Frontend: - Replace Tailwind CSS with ChakraUI v3 (react, recharts, fontsource) - 24 themes (12 Dune factions x day/night variants) - Collapsible sidebar navigation with 6 groups - Recharts AreaChart/PieChart for CPU/RAM/metrics - New Experimental page (ports legacy admin_experimental.html) - Common components: DataTable, Modal, Badge, Toaster Backend: - Fix services to use direct SQL (dune.* schema) instead of stored procedures - PlayerService, EconomyService, GuildService, WorldService rewritten - Auto-login for SPA development in factory.py - Fix settings.yaml path resolution Launcher: - Add option [7] Start New Dashboard in launcher.ps1 and start.sh - Auto-installs pip + npm dependencies - Sets up SSH tunnels + kubectl port-forwards - Starts backend API + frontend Vite dev server Security: - Sanitize hardcoded RMQ password in config.py - Add frontend/dist/ to .gitignore
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import { createContext, useContext, useReducer, useEffect } from 'react'
|
|
import type { FactionKey } from '../themes/palettes'
|
|
import { toaster } from '../toaster'
|
|
|
|
interface AppState {
|
|
user: string | null
|
|
faction: FactionKey
|
|
colorMode: 'day' | 'night'
|
|
connectionStatus: {
|
|
database: boolean
|
|
ssh: boolean
|
|
bgd: boolean
|
|
rmq: boolean
|
|
}
|
|
}
|
|
|
|
type Action =
|
|
| { type: 'SET_USER'; payload: string | null }
|
|
| { type: 'SET_FACTION'; payload: FactionKey }
|
|
| { type: 'SET_COLOR_MODE'; payload: 'day' | 'night' }
|
|
| { type: 'SET_CONNECTION'; payload: Partial<AppState['connectionStatus']> }
|
|
| { type: 'ADD_TOAST'; payload: { message: string; type: 'success' | 'error' | 'warning' | 'info' } }
|
|
|
|
function loadStoredFaction(): FactionKey {
|
|
try {
|
|
const stored = localStorage.getItem('dune-faction')
|
|
if (stored) return stored as FactionKey
|
|
} catch {}
|
|
return 'fremen'
|
|
}
|
|
|
|
function loadStoredColorMode(): 'day' | 'night' {
|
|
try {
|
|
const stored = localStorage.getItem('dune-color-mode')
|
|
if (stored === 'day' || stored === 'night') return stored
|
|
} catch {}
|
|
return 'night'
|
|
}
|
|
|
|
const initialState: AppState = {
|
|
user: null,
|
|
faction: loadStoredFaction(),
|
|
colorMode: loadStoredColorMode(),
|
|
connectionStatus: {
|
|
database: true,
|
|
ssh: true,
|
|
bgd: true,
|
|
rmq: true,
|
|
},
|
|
}
|
|
|
|
function reducer(state: AppState, action: Action): AppState {
|
|
switch (action.type) {
|
|
case 'SET_USER':
|
|
return { ...state, user: action.payload }
|
|
case 'SET_FACTION':
|
|
return { ...state, faction: action.payload }
|
|
case 'SET_COLOR_MODE':
|
|
return { ...state, colorMode: action.payload }
|
|
case 'SET_CONNECTION':
|
|
return { ...state, connectionStatus: { ...state.connectionStatus, ...action.payload } }
|
|
case 'ADD_TOAST':
|
|
toaster[action.payload.type]({
|
|
title: action.payload.message,
|
|
duration: 4000,
|
|
})
|
|
return state
|
|
default:
|
|
return state
|
|
}
|
|
}
|
|
|
|
const AppContext = createContext<{
|
|
state: AppState
|
|
dispatch: React.Dispatch<Action>
|
|
} | null>(null)
|
|
|
|
export function AppProvider({ children }: { children: React.ReactNode }) {
|
|
const [state, dispatch] = useReducer(reducer, initialState)
|
|
|
|
useEffect(() => {
|
|
localStorage.setItem('dune-faction', state.faction)
|
|
}, [state.faction])
|
|
|
|
useEffect(() => {
|
|
localStorage.setItem('dune-color-mode', state.colorMode)
|
|
}, [state.colorMode])
|
|
|
|
return (
|
|
<AppContext.Provider value={{ state, dispatch }}>
|
|
{children}
|
|
</AppContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useApp() {
|
|
const ctx = useContext(AppContext)
|
|
if (!ctx) throw new Error('useApp must be used within AppProvider')
|
|
return ctx
|
|
}
|