Skip to content

Commit

Permalink
fix bug with sidebar title streaming update
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 29, 2024
1 parent 1be9af3 commit f2f5127
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
12 changes: 3 additions & 9 deletions app/src/lib/components/ChatListActionItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
export let summary: string;
export let title: string;
const { session$, audioSource$, fetchingSource$, sessionId$, sessionCompleted$ } =
const { session$, audioSource$, fetchingSource$, sessionId$, sessionCompleted$, updateSessionTitle } =
getSessionContext();
async function ongenerate(summary: string) {
Expand Down Expand Up @@ -79,15 +79,9 @@
async function handleStreamingResponse(res: Response) {
if (!res.ok) return;
for await (const chunk of streamingResponse(res)) {
session$.update((session) => {
if (session) {
if (session.title.toLowerCase() === 'untitled') session.title = '';
session.title += chunk;
}
return session;
});
updateSessionTitle(chunk);
}
}
Expand Down
13 changes: 8 additions & 5 deletions app/src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<script lang="ts" context="module">
import { browser } from '$app/environment';
import { SESSION_KEY } from '@/stores/sessionContext.svelte';
const ONE_DAY_MS = 24 * 60 * 60 * 1000;
const last24Hrs = Date.now() - ONE_DAY_MS;
const last7Days = Date.now() - 4 * ONE_DAY_MS;
export function getSessionItems() {
if (!browser) return [];
return Object.entries(localStorage)
.filter(([key]) => key.startsWith(SESSION_KEY))
.map(
Expand Down Expand Up @@ -39,17 +42,17 @@
import { page } from '$app/stores';
import NewAudiocastButton from './NewAudiocastButton.svelte';
import { goto } from '$app/navigation';
import { browser } from '$app/environment';
import { env } from '@env';
const dispatch = createEventDispatcher<{ clickItem: void }>();
const { openSettingsDrawer$ } = getAppContext();
const { session$, refreshSidebar$ } = getSessionContext();
$: sessionItems = browser || $session$ ? getSessionItems() : [];
$: sidebarItems = getSidebarItems(sessionItems);
$: if ($refreshSidebar$) sidebarItems = getSidebarItems(getSessionItems());
$: sidebarItems = getSidebarItems(getSessionItems());
$: if ($refreshSidebar$ || $session$?.title) {
sidebarItems = getSidebarItems(getSessionItems());
}
$: inLast24Hrs = sidebarItems.filter((i) => i.nonce > last24Hrs);
$: inLast7Days = sidebarItems.filter((i) => i.nonce < last24Hrs && i.nonce > last7Days);
Expand Down
10 changes: 10 additions & 0 deletions app/src/lib/stores/sessionContext.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export function setSessionContext(sessionId: string) {
session.chats = chats;
return session;
});
},
updateSessionTitle: (chunk: string) => {
session$.update((session) => {
if (session) {
if (session.title.toLowerCase() === 'untitled') session.title = '';
session.title += chunk;
}
return session;
});
return session$;
}
});
}
Expand Down

0 comments on commit f2f5127

Please sign in to comment.