2026-07-26 15:34:08 +07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-07-28 12:11:01 +07:00
|
|
|
import { Suspense, useEffect, useState } from "react";
|
2026-08-01 09:19:39 +07:00
|
|
|
import { SWRConfig } from "swr";
|
2026-07-28 15:00:29 +07:00
|
|
|
import { ChatbotContainer } from "@/components/chatbot/chatbot-container";
|
2026-08-01 09:19:39 +07:00
|
|
|
import {
|
|
|
|
|
ChatbotProvider,
|
|
|
|
|
useChatbot,
|
|
|
|
|
} from "@/components/chatbot/chatbot-context";
|
|
|
|
|
import { HiddenSidebar } from "@/components/layout/hidden-sidebar";
|
|
|
|
|
import { MobileNav } from "@/components/layout/mobile-nav";
|
|
|
|
|
import { TopNav } from "@/components/layout/top-nav";
|
2026-07-28 08:53:54 +07:00
|
|
|
import { MiniPlayer } from "@/components/media/mini-player";
|
|
|
|
|
import { MediaPlayerProvider } from "@/lib/hooks/use-media-player";
|
2026-08-01 09:19:39 +07:00
|
|
|
import { useWebSocket, WsProvider } from "@/lib/ws/context";
|
2026-07-26 16:55:20 +07:00
|
|
|
|
2026-07-28 15:00:29 +07:00
|
|
|
function ChatbotExpressionSync() {
|
2026-07-28 12:11:01 +07:00
|
|
|
const ws = useWebSocket();
|
2026-07-28 15:00:29 +07:00
|
|
|
const { setExpression } = useChatbot();
|
2026-07-28 12:11:01 +07:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const unsub1 = ws.on("message_created", (data: any) => {
|
|
|
|
|
if (data.ai_status === "flagged" || data.ai_status === "warn") {
|
|
|
|
|
setExpression("surprise");
|
|
|
|
|
setTimeout(() => setExpression("idle"), 2000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const unsub2 = ws.on("voice_active_user", () => {
|
|
|
|
|
setExpression("listening");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unsub1();
|
|
|
|
|
unsub2();
|
|
|
|
|
};
|
|
|
|
|
}, [ws, setExpression]);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 15:34:08 +07:00
|
|
|
export default function DashboardLayout({
|
|
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
}) {
|
2026-07-28 08:53:54 +07:00
|
|
|
const [guildId, setGuildId] = useState("");
|
|
|
|
|
|
2026-07-26 15:34:08 +07:00
|
|
|
return (
|
2026-08-01 09:19:39 +07:00
|
|
|
<SWRConfig
|
|
|
|
|
value={{
|
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
|
dedupingInterval: 10_000,
|
|
|
|
|
shouldRetryOnError: (err) =>
|
|
|
|
|
(err as { statusCode?: number })?.statusCode !== 404,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-07-26 16:55:20 +07:00
|
|
|
<WsProvider>
|
2026-07-28 08:53:54 +07:00
|
|
|
<MediaPlayerProvider>
|
2026-07-28 15:00:29 +07:00
|
|
|
<ChatbotProvider>
|
|
|
|
|
<ChatbotExpressionSync />
|
2026-07-28 08:53:54 +07:00
|
|
|
<div className="min-h-screen bg-canvas">
|
|
|
|
|
<TopNav />
|
2026-08-01 09:19:39 +07:00
|
|
|
<HiddenSidebar
|
|
|
|
|
guildId={guildId}
|
|
|
|
|
onGuildChange={(g) => setGuildId(g ?? "")}
|
|
|
|
|
/>
|
2026-07-28 08:53:54 +07:00
|
|
|
|
|
|
|
|
{/* Sub-nav space — filled per-page */}
|
|
|
|
|
<div className="pt-11">
|
|
|
|
|
<main className="p-4 md:p-6 pb-24 md:pb-6 max-w-[1600px] mx-auto">
|
|
|
|
|
<Suspense
|
|
|
|
|
fallback={
|
|
|
|
|
<div className="flex h-[60vh] items-center justify-center">
|
|
|
|
|
<div className="size-8 rounded-full border-2 border-primary border-t-transparent animate-spin" />
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Suspense>
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<MobileNav />
|
|
|
|
|
<MiniPlayer />
|
2026-07-28 15:00:29 +07:00
|
|
|
<ChatbotContainer />
|
2026-07-28 08:53:54 +07:00
|
|
|
</div>
|
2026-07-28 15:00:29 +07:00
|
|
|
</ChatbotProvider>
|
2026-07-28 08:53:54 +07:00
|
|
|
</MediaPlayerProvider>
|
2026-07-26 16:55:20 +07:00
|
|
|
</WsProvider>
|
2026-08-01 09:19:39 +07:00
|
|
|
</SWRConfig>
|
2026-07-26 15:34:08 +07:00
|
|
|
);
|
|
|
|
|
}
|