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";
|
2026-08-14 10:49:44 +07:00
|
|
|
import { Spine } from "@/components/layout/spine";
|
|
|
|
|
import { StatusBar } from "@/components/layout/status-bar";
|
2026-07-28 08:53:54 +07:00
|
|
|
import { MiniPlayer } from "@/components/media/mini-player";
|
2026-08-14 10:49:44 +07:00
|
|
|
import { RouteTransition } from "@/components/motion/route-transition";
|
2026-08-07 17:33:12 +07:00
|
|
|
import { GuildSelector } from "@/components/shared/guild-selector";
|
2026-07-28 08:53:54 +07:00
|
|
|
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-08-03 06:04:25 +07:00
|
|
|
function ChatbotGuildSync({ guildId }: { guildId: string }) {
|
|
|
|
|
const { setGuildId } = useChatbot();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setGuildId(guildId);
|
|
|
|
|
}, [guildId, setGuildId]);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-08-14 10:49:44 +07:00
|
|
|
const unsub2 = ws.on("voice_active_user", () => setExpression("listening"));
|
2026-07-28 12:11:01 +07:00
|
|
|
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>
|
2026-08-03 06:04:25 +07:00
|
|
|
<ChatbotGuildSync guildId={guildId} />
|
2026-07-28 15:00:29 +07:00
|
|
|
<ChatbotExpressionSync />
|
2026-08-14 10:49:44 +07:00
|
|
|
<div className="min-h-svh bg-[var(--color-canvas)] md:pl-[68px]">
|
|
|
|
|
<Spine />
|
|
|
|
|
<div className="flex min-h-svh flex-col">
|
|
|
|
|
<StatusBar
|
|
|
|
|
guildId={guildId}
|
|
|
|
|
onGuildChange={(g) => setGuildId(g)}
|
|
|
|
|
/>
|
|
|
|
|
<main className="flex flex-1 flex-col gap-4 p-4 pb-24 md:p-6 lg:pb-8">
|
|
|
|
|
<div className="mx-auto w-full max-w-[1440px]">
|
|
|
|
|
<Suspense
|
|
|
|
|
fallback={
|
|
|
|
|
<div className="flex h-[60vh] items-center justify-center">
|
|
|
|
|
<div className="size-8 animate-spin rounded-full border-2 border-[var(--color-signal)] border-t-transparent" />
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<RouteTransition>{children}</RouteTransition>
|
|
|
|
|
</Suspense>
|
|
|
|
|
</div>
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
2026-07-28 08:53:54 +07:00
|
|
|
<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
|
|
|
);
|
|
|
|
|
}
|