Skip to content

Commit

Permalink
enhance getSession$ to accept an initial value; simplify session mode…
Browse files Browse the repository at this point in the history
…l assignment in audiocast page
  • Loading branch information
nwaughachukwuma committed Nov 26, 2024
1 parent dc55a0c commit 65cd92d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
8 changes: 4 additions & 4 deletions app/src/lib/db/db.session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionModel>;
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;
};
36 changes: 15 additions & 21 deletions app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -105,20 +99,6 @@
</RenderMedia>

<Accordion.Root>
<Accordion.Item value="item-0" class="border-gray-800">
<Accordion.Trigger>Show Waveform</Accordion.Trigger>
<Accordion.Content>
<RenderMedia filename="{sessionId}.mp4" let:uri>
<video controls class="w-full h-64 animate-fade-in block">
<source src={uri} type="video/mp4" />
Your browser does not support the video element.

<track kind="captions" />
</video>
</RenderMedia>
</Accordion.Content>
</Accordion.Item>

{#if sessionModel.metadata?.transcript}
<Accordion.Item value="item-1" class="border-gray-800">
<Accordion.Trigger>Audio Transcript</Accordion.Trigger>
Expand All @@ -137,6 +117,20 @@
{#if sessionModel.metadata?.source}
<RenderAudioSources aiSource={sessionModel.metadata.source} />
{/if}

<Accordion.Item value="item-0" class="border-gray-800">
<Accordion.Trigger>Show Waveform</Accordion.Trigger>
<Accordion.Content>
<RenderMedia filename="{sessionId}.mp4" let:uri>
<video controls class="w-full h-64 animate-fade-in block">
<source src={uri} type="video/mp4" />
Your browser does not support the video element.

<track kind="captions" />
</video>
</RenderMedia>
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

<AudiocastPageAction {sessionId} {sessionTitle} on:showChats>
Expand Down

0 comments on commit 65cd92d

Please sign in to comment.