Files
ProxMenux/AppImage/components/settings.tsx

142 lines
5.3 KiB
TypeScript
Raw Normal View History

2025-11-18 13:30:37 +01:00
"use client"
2025-11-04 18:07:13 +01:00
2025-11-18 13:30:37 +01:00
import { useState, useEffect } from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "./ui/card"
2026-02-08 13:19:24 +01:00
import { Wrench, Package, Ruler } from "lucide-react"
2025-11-18 21:27:24 +01:00
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"
2025-11-18 22:05:54 +01:00
import { getNetworkUnit } from "../lib/format-network"
2026-02-08 13:19:24 +01:00
import { fetchApi } from "../lib/api-config"
2025-11-04 18:07:13 +01:00
2025-11-09 20:52:39 +01:00
interface ProxMenuxTool {
2025-11-18 13:30:37 +01:00
key: string
name: string
enabled: boolean
2025-11-09 20:52:39 +01:00
}
2025-11-04 18:07:13 +01:00
export function Settings() {
2025-11-18 13:30:37 +01:00
const [proxmenuxTools, setProxmenuxTools] = useState<ProxMenuxTool[]>([])
const [loadingTools, setLoadingTools] = useState(true)
2025-11-18 22:05:54 +01:00
const [networkUnitSettings, setNetworkUnitSettings] = useState<"Bytes" | "Bits">("Bytes")
2025-11-18 21:27:24 +01:00
const [loadingUnitSettings, setLoadingUnitSettings] = useState(true)
2025-11-18 19:00:51 +01:00
2025-11-04 18:07:13 +01:00
useEffect(() => {
2025-11-18 13:30:37 +01:00
loadProxmenuxTools()
2026-02-07 18:03:46 +01:00
getUnitsSettings()
2025-11-18 13:30:37 +01:00
}, [])
2025-11-18 10:58:06 +01:00
2025-11-09 20:52:39 +01:00
const loadProxmenuxTools = async () => {
try {
2026-02-08 13:19:24 +01:00
const data = await fetchApi("/api/proxmenux/installed-tools")
2025-11-09 20:52:39 +01:00
if (data.success) {
2025-11-18 13:30:37 +01:00
setProxmenuxTools(data.installed_tools || [])
2025-11-09 20:52:39 +01:00
}
} catch (err) {
2025-11-18 13:30:37 +01:00
console.error("Failed to load ProxMenux tools:", err)
2025-11-09 20:52:39 +01:00
} finally {
2025-11-18 13:30:37 +01:00
setLoadingTools(false)
2025-11-09 20:52:39 +01:00
}
2025-11-18 13:30:37 +01:00
}
2025-11-09 20:52:39 +01:00
2025-11-18 21:27:24 +01:00
const changeNetworkUnit = (unit: string) => {
2025-11-18 22:05:54 +01:00
const networkUnit = unit as "Bytes" | "Bits"
localStorage.setItem("proxmenux-network-unit", networkUnit)
setNetworkUnitSettings(networkUnit)
2026-02-08 13:19:24 +01:00
2025-11-18 22:05:54 +01:00
window.dispatchEvent(new CustomEvent("networkUnitChanged", { detail: networkUnit }))
2026-02-08 13:19:24 +01:00
2025-11-18 22:05:54 +01:00
window.dispatchEvent(new StorageEvent("storage", {
key: "proxmenux-network-unit",
newValue: networkUnit,
url: window.location.href
}))
2025-11-18 21:27:24 +01:00
}
const getUnitsSettings = () => {
2025-11-18 22:05:54 +01:00
const networkUnit = getNetworkUnit()
2025-11-18 21:27:24 +01:00
setNetworkUnitSettings(networkUnit)
setLoadingUnitSettings(false)
}
2025-11-04 18:07:13 +01:00
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold">Settings</h1>
2026-02-08 13:19:24 +01:00
<p className="text-muted-foreground mt-2">Manage your dashboard preferences</p>
2025-11-04 18:07:13 +01:00
</div>
2025-11-18 21:27:24 +01:00
{/* Network Units Settings */}
<Card>
<CardHeader>
<div className="flex items-center gap-2">
<Ruler className="h-5 w-5 text-green-500" />
<CardTitle>Network Units</CardTitle>
</div>
<CardDescription>Change how network traffic is displayed</CardDescription>
</CardHeader>
<CardContent>
{loadingUnitSettings ? (
<div className="flex items-center justify-center py-8">
<div className="animate-spin h-8 w-8 border-4 border-green-500 border-t-transparent rounded-full" />
</div>
) : (
<div className="text-foreground flex items-center justify-between">
<div className="flex items-center">Network Unit Display</div>
<Select value={networkUnitSettings} onValueChange={changeNetworkUnit}>
<SelectTrigger className="w-28 h-8 text-xs">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="Bytes">Bytes</SelectItem>
<SelectItem value="Bits">Bits</SelectItem>
</SelectContent>
</Select>
</div>
)}
</CardContent>
</Card>
2025-11-09 20:52:39 +01:00
{/* ProxMenux Optimizations */}
2025-11-04 18:07:13 +01:00
<Card>
<CardHeader>
2025-11-09 20:52:39 +01:00
<div className="flex items-center gap-2">
<Wrench className="h-5 w-5 text-orange-500" />
<CardTitle>ProxMenux Optimizations</CardTitle>
2025-11-04 18:07:13 +01:00
</div>
2025-11-18 13:30:37 +01:00
<CardDescription>System optimizations and utilities installed via ProxMenux</CardDescription>
2025-11-09 20:52:39 +01:00
</CardHeader>
<CardContent>
{loadingTools ? (
<div className="flex items-center justify-center py-8">
<div className="animate-spin h-8 w-8 border-4 border-orange-500 border-t-transparent rounded-full" />
</div>
) : proxmenuxTools.length === 0 ? (
<div className="text-center py-8">
<Package className="h-12 w-12 text-muted-foreground mx-auto mb-3 opacity-50" />
2025-11-18 13:30:37 +01:00
<p className="text-muted-foreground">No ProxMenux optimizations installed yet</p>
<p className="text-sm text-muted-foreground mt-1">Run ProxMenux to configure system optimizations</p>
2025-11-09 20:52:39 +01:00
</div>
) : (
<div className="space-y-2">
<div className="flex items-center justify-between mb-4 pb-2 border-b border-border">
2025-11-18 13:30:37 +01:00
<span className="text-sm font-medium text-muted-foreground">Installed Tools</span>
<span className="text-sm font-semibold text-orange-500">{proxmenuxTools.length} active</span>
2025-11-09 20:52:39 +01:00
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
{proxmenuxTools.map((tool) => (
<div
key={tool.key}
className="flex items-center gap-2 p-3 bg-muted/50 rounded-lg border border-border hover:bg-muted transition-colors"
>
<div className="w-2 h-2 rounded-full bg-green-500 flex-shrink-0" />
<span className="text-sm font-medium">{tool.name}</span>
</div>
))}
</div>
</div>
)}
2025-11-04 18:07:13 +01:00
</CardContent>
</Card>
</div>
2025-11-18 13:30:37 +01:00
)
2025-11-18 19:00:51 +01:00
}