Ground-up rebuild of the GMW frontend as an Ambient Field console: - WebGL ambient background (Three.js shader, drifting motes, reduced-motion aware) - Glassmorphism dark cyber theme across all 8 routes - SSR page + client view split with SWR fallback; realtime via WebSocket - Command palette (Cmd+K), chatbot FAB, guild/channel pickers - Chart primitives: donut, radial-gauge, area-activity, sparkline, equalizer Cleanup (review pass): - Remove stray Puppeteer nav-test/nav-debug scripts - Replace non-null assertions with guards (dashboard/moderation) - Drop unused useGuilds fetches in messages/voice views - Type implicit-any `let` declarations across pages - Add a11y roles/labels to SVG charts and audio, tidy imports
91 lines
2.2 KiB
TypeScript
91 lines
2.2 KiB
TypeScript
import useSWR from "swr";
|
|
|
|
import { dashboardApi } from "@/lib/api";
|
|
import type {
|
|
DashboardActivity,
|
|
DashboardChannelDetail,
|
|
DashboardStats,
|
|
DashboardUserDetail,
|
|
TopReactedMessage,
|
|
TopReactor,
|
|
} from "@/lib/types";
|
|
|
|
/**
|
|
* Server-seeded SWR hooks.
|
|
*
|
|
* SSR pages fetch the initial payload on the server and hand it here as
|
|
* `initialData` — the first render is server data, and SWR takes over for
|
|
* revalidation from then on (no blank-spinner-first-load).
|
|
*/
|
|
export function useStats(initialData?: DashboardStats) {
|
|
return useSWR<DashboardStats>(
|
|
["dashboard-stats"],
|
|
() => dashboardApi.getStats(),
|
|
{ fallbackData: initialData },
|
|
);
|
|
}
|
|
|
|
export function useActivity(days = 14, initialData?: DashboardActivity) {
|
|
return useSWR<DashboardActivity>(
|
|
["dashboard-activity", days],
|
|
() => dashboardApi.getActivity(days),
|
|
{ fallbackData: initialData },
|
|
);
|
|
}
|
|
|
|
export function useUsers(search?: string) {
|
|
return useSWR(
|
|
["dashboard-users", search ?? ""],
|
|
async () => {
|
|
const res = await dashboardApi.listUsers(20, undefined, search);
|
|
return res.data;
|
|
},
|
|
{
|
|
keepPreviousData: true,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useChannels(guildId?: string, search?: string) {
|
|
return useSWR(
|
|
["dashboard-channels", guildId ?? "__all__", search ?? ""],
|
|
async () => {
|
|
const res = await dashboardApi.listChannels(
|
|
20,
|
|
search,
|
|
guildId || undefined,
|
|
);
|
|
return res.data;
|
|
},
|
|
{
|
|
keepPreviousData: true,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useUserDetail(userId: string | null) {
|
|
return useSWR<DashboardUserDetail>(
|
|
userId ? (["dashboard-user", userId] as const) : null,
|
|
() => dashboardApi.getUserDetail(userId ?? ""),
|
|
);
|
|
}
|
|
|
|
export function useChannelDetail(channelId: string | null) {
|
|
return useSWR<DashboardChannelDetail>(
|
|
channelId ? (["dashboard-channel", channelId] as const) : null,
|
|
() => dashboardApi.getChannelDetail(channelId ?? ""),
|
|
);
|
|
}
|
|
|
|
export function useTopReactions() {
|
|
return useSWR<TopReactedMessage[]>(["dashboard-reactions"], () =>
|
|
dashboardApi.getTopReactions(20),
|
|
);
|
|
}
|
|
|
|
export function useTopReactors() {
|
|
return useSWR<TopReactor[]>(["dashboard-reactors"], () =>
|
|
dashboardApi.getTopReactors(20),
|
|
);
|
|
}
|