From 65cd92dd5812f9d647fb4cefda37416daee0052d Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Tue, 26 Nov 2024 10:35:48 +0000 Subject: [PATCH] enhance getSession$ to accept an initial value; simplify session model assignment in audiocast page --- app/src/lib/db/db.session.ts | 8 ++--- .../[sessionId=sessionId]/+page.svelte | 36 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/app/src/lib/db/db.session.ts b/app/src/lib/db/db.session.ts index bfc0946..86a1c49 100644 --- a/app/src/lib/db/db.session.ts +++ b/app/src/lib/db/db.session.ts @@ -5,13 +5,13 @@ import { dbRefs } from '@/services/firebase'; import { docData } from './db.utils'; import type { SessionModel } from '@/utils/types'; -export const getSession$ = (sessionId: string) => { +export const getSession$ = (sessionId: string, startValue: SessionModel | null = null) => { const ref = dbRefs.docRef('audiora_sessions', sessionId) as DocumentReference; - return docData(ref).pipe( + const obs = docData(ref).pipe( switchMap((v) => of(v)), distinctUntilChanged((a, b) => equals(a, b)), shareReplay(1), - catchError(() => of(null)), - // startWith(null) + catchError(() => of(null)) ); + return startValue ? obs.pipe(startWith(startValue)) : obs; }; diff --git a/app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte b/app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte index 396eaeb..6243f80 100644 --- a/app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte +++ b/app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte @@ -25,7 +25,6 @@ import AudiocastPageSkeletonLoader from '@/components/AudiocastPageSkeletonLoader.svelte'; import RenderAudioSources from '@/components/RenderAudioSources.svelte'; import AudiocastPageHeader from '@/components/AudiocastPageHeader.svelte'; - import { startWith, tap, switchMap, of } from 'rxjs'; export let data; @@ -36,12 +35,7 @@ $: sessionId = $page.params.sessionId; $: $customSources$; - $: sessionModel = data.sessionModel; - $: sessionModel$.pipe( - switchMap((v) => of(v)), - tap((v) => v && (sessionModel = v)), - startWith(data.sessionModel) - ); + $: sessionModel = $sessionModel$ || data.sessionModel; $: sessionTitle = sessionModel.metadata?.title || 'Untitled'; async function generateAudiocast(sessionId: string, category: ContentCategory, summary: string) { @@ -105,20 +99,6 @@ - - Show Waveform - - - - - - - {#if sessionModel.metadata?.transcript} Audio Transcript @@ -137,6 +117,20 @@ {#if sessionModel.metadata?.source} {/if} + + + Show Waveform + + + + + +