feat: go back to last chat on back to chat button (#47)
This commit is contained in:
parent
a77493c9ef
commit
f8f6748bec
4 changed files with 39 additions and 3 deletions
|
|
@ -272,7 +272,7 @@
|
|||
|
||||
<Popover.Content
|
||||
portalProps={{
|
||||
disabled: isFirefox
|
||||
disabled: isFirefox,
|
||||
}}
|
||||
align="start"
|
||||
sideOffset={5}
|
||||
|
|
@ -524,7 +524,7 @@
|
|||
</div>
|
||||
|
||||
<div
|
||||
class="bg-popover absolute top-1 right-1 scale-75 rounded-md p-1 md:opacity-0 transition-all group-hover/item:scale-100 group-hover/item:opacity-100"
|
||||
class="bg-popover absolute top-1 right-1 scale-75 rounded-md p-1 transition-all group-hover/item:scale-100 group-hover/item:opacity-100 md:opacity-0"
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
|
|
|||
23
src/lib/state/last-chat.svelte.ts
Normal file
23
src/lib/state/last-chat.svelte.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { Context } from 'runed';
|
||||
|
||||
class LastChatState {
|
||||
constructor(readonly opts: { lastChat: string | null }) {}
|
||||
|
||||
get current() {
|
||||
return this.opts.lastChat;
|
||||
}
|
||||
|
||||
set current(chat: string | null) {
|
||||
this.opts.lastChat = chat;
|
||||
}
|
||||
}
|
||||
|
||||
const ctx = new Context<LastChatState>('last-chat');
|
||||
|
||||
export function setupLastChat() {
|
||||
return ctx.set(new LastChatState({ lastChat: null }));
|
||||
}
|
||||
|
||||
export function useLastChat() {
|
||||
return ctx.get();
|
||||
}
|
||||
|
|
@ -10,11 +10,19 @@
|
|||
import { browser } from '$app/environment';
|
||||
import { MetaTags } from 'svelte-meta-tags';
|
||||
import { page } from '$app/state';
|
||||
import { setupLastChat } from '$lib/state/last-chat.svelte';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
setupConvex(PUBLIC_CONVEX_URL);
|
||||
const lastChat = setupLastChat();
|
||||
models.init();
|
||||
|
||||
$effect(() => {
|
||||
if (page.url.pathname.startsWith('/chat')) {
|
||||
lastChat.current = page.params?.id ?? null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<MetaTags
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
import { session } from '$lib/state/session.svelte.js';
|
||||
import { api } from '$lib/backend/convex/_generated/api.js';
|
||||
import { cn } from '$lib/utils/utils.js';
|
||||
import { useLastChat } from '$lib/state/last-chat.svelte.js';
|
||||
|
||||
let { data, children } = $props();
|
||||
|
||||
|
|
@ -71,11 +72,15 @@
|
|||
|
||||
await goto('/login');
|
||||
}
|
||||
|
||||
const lastChat = useLastChat();
|
||||
|
||||
const backToChat = $derived(lastChat.current ? `/chat/${lastChat.current}` : '/chat');
|
||||
</script>
|
||||
|
||||
<div class="container mx-auto max-w-[1200px] space-y-8 pt-6 pb-24">
|
||||
<header class="flex place-items-center justify-between px-4">
|
||||
<Button href="/chat" variant="ghost" class="flex place-items-center gap-2 text-sm">
|
||||
<Button href={backToChat} variant="ghost" class="flex place-items-center gap-2 text-sm">
|
||||
<ArrowLeftIcon class="size-4" />
|
||||
Back to Chat
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue