64 lines
1.4 KiB
Svelte
64 lines
1.4 KiB
Svelte
<script lang="ts">
|
|
import Router, { location, replace } from 'svelte-spa-router'
|
|
import { wrap } from 'svelte-spa-router/wrap'
|
|
|
|
import Navbar from './lib/Navbar.svelte'
|
|
import Sidebar from './lib/Sidebar.svelte'
|
|
import Home from './lib/Home.svelte'
|
|
import Chat from './lib/Chat.svelte'
|
|
import NewChat from './lib/NewChat.svelte'
|
|
import { chatsStorage, apiKeyStorage } from './lib/Storage.svelte'
|
|
import { Modals, closeModal } from 'svelte-modals'
|
|
|
|
// The definition of the routes with some conditions
|
|
const routes = {
|
|
'/': Home,
|
|
|
|
'/chat/new': wrap({
|
|
component: NewChat,
|
|
conditions: () => {
|
|
return !!$apiKeyStorage
|
|
}
|
|
}),
|
|
|
|
'/chat/:chatId': wrap({
|
|
component: Chat,
|
|
conditions: (detail) => {
|
|
return $chatsStorage.find((chat) => chat.id === parseInt(detail?.params?.chatId as string)) !== undefined
|
|
}
|
|
}),
|
|
|
|
'*': Home
|
|
}
|
|
</script>
|
|
|
|
<Navbar />
|
|
<div class="side-bar-column">
|
|
<Sidebar />
|
|
</div>
|
|
<div class="main-content-column" id="content">
|
|
{#key $location}
|
|
<Router {routes} on:conditionsFailed={() => replace('/')}/>
|
|
{/key}
|
|
</div>
|
|
|
|
<Modals>
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
<div
|
|
slot="backdrop"
|
|
class="backdrop"
|
|
on:click={closeModal}
|
|
/>
|
|
</Modals>
|
|
|
|
<style>
|
|
.backdrop {
|
|
position: fixed;
|
|
top: 0;
|
|
bottom: 0;
|
|
right: 0;
|
|
left: 0;
|
|
background: transparent
|
|
}
|
|
</style>
|