feat: go back to last chat on back to chat button (#47)

This commit is contained in:
Aidan Bleser 2025-08-11 05:51:27 -05:00 committed by GitHub
parent a77493c9ef
commit f8f6748bec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 3 deletions

View file

@ -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"

View 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();
}

View file

@ -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

View file

@ -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>