e3bf065574
- Keep Playground component mounted when navigating away, preserving streaming/generating state - Add animated gradient effect on Playground nav link when activity is in progress
59 lines
1.7 KiB
Svelte
59 lines
1.7 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from "svelte";
|
|
import Router from "svelte-spa-router";
|
|
import Header from "./components/Header.svelte";
|
|
import LogViewer from "./routes/LogViewer.svelte";
|
|
import Models from "./routes/Models.svelte";
|
|
import Activity from "./routes/Activity.svelte";
|
|
import Playground from "./routes/Playground.svelte";
|
|
import PlaygroundStub from "./routes/PlaygroundStub.svelte";
|
|
import { enableAPIEvents } from "./stores/api";
|
|
import { initScreenWidth, isDarkMode, appTitle, connectionState } from "./stores/theme";
|
|
import { currentRoute } from "./stores/route";
|
|
|
|
const routes = {
|
|
"/": PlaygroundStub,
|
|
"/models": Models,
|
|
"/logs": LogViewer,
|
|
"/activity": Activity,
|
|
"*": PlaygroundStub,
|
|
};
|
|
|
|
function handleRouteLoaded(event: { detail: { route: string | RegExp } }) {
|
|
const route = event.detail.route;
|
|
currentRoute.set(typeof route === "string" ? route : "/");
|
|
}
|
|
|
|
$effect(() => {
|
|
document.documentElement.setAttribute("data-theme", $isDarkMode ? "dark" : "light");
|
|
});
|
|
|
|
$effect(() => {
|
|
const icon = $connectionState === "connecting" ? "\u{1F7E1}" : $connectionState === "connected" ? "\u{1F7E2}" : "\u{1F534}";
|
|
document.title = `${icon} ${$appTitle}`;
|
|
});
|
|
|
|
onMount(() => {
|
|
const cleanupScreenWidth = initScreenWidth();
|
|
enableAPIEvents(true);
|
|
|
|
return () => {
|
|
cleanupScreenWidth();
|
|
enableAPIEvents(false);
|
|
};
|
|
});
|
|
</script>
|
|
|
|
<div class="flex flex-col h-screen">
|
|
<Header />
|
|
|
|
<main class="flex-1 overflow-auto p-4">
|
|
<div class="h-full" class:hidden={$currentRoute !== "/"}>
|
|
<Playground />
|
|
</div>
|
|
<div class="h-full" class:hidden={$currentRoute === "/"}>
|
|
<Router {routes} on:routeLoaded={handleRouteLoaded} />
|
|
</div>
|
|
</main>
|
|
</div>
|