Backend: - New Flask 3 app with service-layer architecture - Pydantic v2 models and unified API response format - psycopg3 connection pool with stored procedure support - 14 services: DB, SSH, K8s, BGD, RMQ (admin + game), realtime, player, economy, guild, world, progression, character, audit, chat - 30+ API endpoints covering players, guilds, economy, world, admin, server, files, director, chat - SSE real-time events for battlegroup, chat, metrics, connection status - SocketIO remote shell (xterm.js compatible) - Settings CRUD, moderation (ban/kick/unban), audit logging - Security: CSRF, rate limiting, CSP, HSTS, read-only SQL enforcement Frontend: - Vite + React 18 + TypeScript + Tailwind CSS - 14 Dune house themes via CSS custom properties - SWR for server state, Axios API client with interceptors - 14 pages: Overview, Player Explorer + Detail, Guild Manager, Vehicles, Buildings, Map Viewer, Accounts, Server Control, Admin Tools (7 tabs), Chat Monitor, Remote Shell, File Browser, Director, Settings - Player Detail with 6 tabs: overview, inventory, vehicles, buildings, progression, actions - Admin Tools: broadcast, economy, world, character, functions, raw query, audit log - Interactive canvas map viewer with zoom/pan/filter - Toast notifications, connection badges, theme switcher Other: - Updated .gitignore for frontend/backend structure - Updated README with new architecture, development guide, and project structure - Legacy app/ templates/ static/ remain untouched
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
import client from '../../api/client'
|
|
import { useApp } from '../../stores/AppContext'
|
|
|
|
export default function Settings() {
|
|
const [settings, setSettings] = useState<Record<string, string>>({})
|
|
const [loading, setLoading] = useState(false)
|
|
const [saving, setSaving] = useState(false)
|
|
const { dispatch } = useApp()
|
|
|
|
const load = async () => {
|
|
setLoading(true)
|
|
try {
|
|
const res = await client.get('/settings')
|
|
if (res.data.success) {
|
|
setSettings(res.data.data)
|
|
}
|
|
} catch (e: any) {
|
|
dispatch({ type: 'ADD_TOAST', payload: { message: e.response?.data?.error || 'Failed to load settings', type: 'error' } })
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
load()
|
|
}, [])
|
|
|
|
const handleSave = async () => {
|
|
setSaving(true)
|
|
try {
|
|
const res = await client.post('/settings', settings)
|
|
if (res.data.success) {
|
|
dispatch({ type: 'ADD_TOAST', payload: { message: 'Settings saved', type: 'success' } })
|
|
}
|
|
} catch (e: any) {
|
|
dispatch({ type: 'ADD_TOAST', payload: { message: e.response?.data?.error || 'Failed to save', type: 'error' } })
|
|
} finally {
|
|
setSaving(false)
|
|
}
|
|
}
|
|
|
|
const handleChange = (key: string, value: string) => {
|
|
setSettings({ ...settings, [key]: value })
|
|
}
|
|
|
|
const addKey = () => {
|
|
const key = prompt('Enter new setting key:')
|
|
if (key) {
|
|
setSettings({ ...settings, [key]: '' })
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<h1 className="font-serif text-3xl text-primary mb-6">Settings</h1>
|
|
|
|
<div className="flex items-center gap-4 mb-6">
|
|
<button
|
|
onClick={load}
|
|
disabled={loading}
|
|
className="px-4 py-2 bg-primary text-white rounded-lg text-sm font-medium hover:bg-primary-dark disabled:opacity-50"
|
|
>
|
|
{loading ? 'Loading...' : 'Reload'}
|
|
</button>
|
|
<button
|
|
onClick={handleSave}
|
|
disabled={saving}
|
|
className="px-4 py-2 bg-success text-white rounded-lg text-sm font-medium hover:bg-success/80 disabled:opacity-50"
|
|
>
|
|
{saving ? 'Saving...' : 'Save Settings'}
|
|
</button>
|
|
<button
|
|
onClick={addKey}
|
|
className="px-4 py-2 bg-card-bg border border-border text-text-primary rounded-lg text-sm font-medium hover:bg-hover"
|
|
>
|
|
Add Key
|
|
</button>
|
|
</div>
|
|
|
|
<div className="bg-card-bg border border-border rounded-lg p-5 space-y-4 max-w-2xl">
|
|
{Object.entries(settings).length === 0 && !loading && (
|
|
<div className="text-text-muted">No settings found.</div>
|
|
)}
|
|
{Object.entries(settings).map(([key, value]) => (
|
|
<div key={key} className="grid grid-cols-[200px_1fr] gap-4 items-center">
|
|
<label className="text-sm text-text-secondary truncate" title={key}>{key}</label>
|
|
<input
|
|
value={value}
|
|
onChange={(e) => handleChange(key, e.target.value)}
|
|
className="bg-card-bg border border-border rounded px-3 py-2 text-sm text-text-primary"
|
|
/>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|