Skip to content

Commit

Permalink
swap chat input box with navigation button when audiocast completes f…
Browse files Browse the repository at this point in the history
…or a given session
  • Loading branch information
nwaughachukwuma committed Nov 11, 2024
1 parent 43a8cfd commit 80bc3ac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/src/lib/components/ChatBoxContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
export let loading = false;
export let searchTerm: string;
export let showIcon = false;
export let disabled = false;
</script>

<div
class="fixed bg-background bottom-0 block w-full max-w-full max-sm:px-2 py-4 sm:max-w-xl lg:max-w-3xl"
>
<div class="block w-full items-center">
<ChatBox {showIcon} disabled={loading} bind:searchTerm on:keypress>
<ChatBox {showIcon} disabled={loading || disabled} bind:searchTerm on:keypress>
<svelte:fragment slot="icon-right" let:disabled>
<ChatBoxIcon iconType="send" {loading} {disabled} {searchTerm} on:click />
</svelte:fragment>
Expand Down
14 changes: 13 additions & 1 deletion app/src/lib/components/ChatContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script>
import { getSessionContext } from '@/stores/sessionContext.svelte';
import ChatBoxContainer from './ChatBoxContainer.svelte';
export let searchTerm = '';
const { sessionCompleted$ } = getSessionContext();
let navLoading = false;
</script>

Expand All @@ -12,5 +15,14 @@
<div class="h-32"></div>
</div>

<ChatBoxContainer bind:searchTerm loading={navLoading} showIcon on:keypress on:click />
{#if !$sessionCompleted$}
<ChatBoxContainer
bind:searchTerm
loading={navLoading}
showIcon
disabled={$sessionCompleted$}
on:keypress
on:click
/>
{/if}
</div>
52 changes: 33 additions & 19 deletions app/src/lib/components/CheckFinalResponse.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
<script lang="ts">
import { createEventDispatcher, onMount } from 'svelte';
import { Button } from './ui/button';
import { getSessionContext } from '@/stores/sessionContext.svelte';
export let content: string;
const { sessionId$, sessionCompleted$ } = getSessionContext();
const dispatch = createEventDispatcher<{
finalResponse: void;
reviewSource: void;
Expand All @@ -33,23 +36,34 @@
</script>

{#if finalResponse}
<div class="animate-fade-in grid sm:grid-cols-3 gap-3">
<Button class="bg-emerald-600 text-emerald-100 hover:bg-emerald-700" on:click={ongenerate}
>Generate Audiocast</Button
>

<Button
variant="ghost"
class="bg-gray-800 hover:bg-gray-700 text-emerald-600 hover:text-emerald-600"
on:click={() => dispatch('reviewSource')}
>
Review Source
</Button>

<Button
variant="ghost"
class="text-emerald-600 hover:text-emerald-600 hover:bg-gray-800/40"
on:click={() => dispatch('startNew')}>Start New Session</Button
>
</div>
{#if $sessionCompleted$}
<div class="mt-3 w-full items-center justify-center flex">
<a
href="/audiocast/{$sessionId$}"
data-sveltekit-preload-data="hover"
class="py-3 rounded-md px-16 no-underline hover:no-underline bg-emerald-600 text-emerald-100 hover:bg-emerald-700"
>View Audiocast</a
>
</div>
{:else}
<div class="animate-fade-in grid sm:grid-cols-3 gap-3">
<Button class="bg-emerald-600 text-emerald-100 hover:bg-emerald-700" on:click={ongenerate}
>Generate Audiocast</Button
>

<Button
variant="ghost"
class="bg-gray-800 hover:bg-gray-700 text-emerald-600 hover:text-emerald-600"
on:click={() => dispatch('reviewSource')}
>
Review Source
</Button>

<Button
variant="ghost"
class="text-emerald-600 hover:text-emerald-600 hover:bg-gray-800/40"
on:click={() => dispatch('startNew')}>Start New Session</Button
>
</div>
{/if}
{/if}
4 changes: 3 additions & 1 deletion app/src/lib/stores/sessionContext.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ContentCategory } from '@/utils/types';
import { setContext, getContext } from 'svelte';
import { persisted } from 'svelte-persisted-store';
import { writable } from 'svelte/store';
import { derived, writable } from 'svelte/store';

const CONTEXT_KEY = {};
export const SESSION_KEY = 'AUDIOCAST_SESSION';
Expand All @@ -26,10 +26,12 @@ export type Session = {
export function setSessionContext(sessionId: string) {
const session$ = persisted<Session | null>(`${SESSION_KEY}_${sessionId}`, null);
const sessionId$ = writable(sessionId);
const sessionCompleted$ = derived(session$, ($session) => !!$session?.completed);

return setContext(CONTEXT_KEY, {
session$,
sessionId$,
sessionCompleted$,
startSession: (category: ContentCategory) => {
session$.set({
id: sessionId,
Expand Down

0 comments on commit 80bc3ac

Please sign in to comment.