Skip to content

Commit

Permalink
add logic to select category if the user starts with chatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 12, 2024
1 parent 673c3f1 commit 5477527
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
7 changes: 5 additions & 2 deletions app/src/lib/components/ChatContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
let navLoading = false;
</script>

<div class="mx-auto flex h-full w-full flex-col overflow-auto items-center gap-1 px-4">
<div
id="chatContainer1"
class="mx-auto flex h-full w-full flex-col overflow-auto items-center gap-1 px-4"
>
<div class="sm:max-w-xl lg:max-w-3xl max-w-full w-full">
<div id="chatContainer1" class="scrollbar-y-1 w-full h-[calc(100%-4rem)] block">
<div class="scrollbar-y-1 w-full h-[calc(100%-4rem)] block">
<slot name="content"></slot>
<div class="h-48"></div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions app/src/lib/components/RenderCategorySelection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import ChatListItem from './ChatListItem.svelte';
import SelectCategory from './SelectCategory.svelte';
export let content: string;
</script>

<div class="flex flex-col gap-y-3 h-full">
<ChatListItem type="user" {content} />

<ChatListItem type="assistant" content="Please select your audiocast category" />

<SelectCategory on:selectCategory />
</div>
33 changes: 33 additions & 0 deletions app/src/lib/components/SelectCategory.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts" context="module">
import type { ContentCategory } from '@/utils/types';
export const categories: ContentCategory[] = [
'podcast',
'sermon',
'audiodrama',
'lecture',
'commentary',
'voicenote',
'interview',
'soundbite'
];
</script>

<script lang="ts">
import { createEventDispatcher } from 'svelte';
import Button from './ui/button/button.svelte';
const dispatch = createEventDispatcher<{ selectCategory: { value: ContentCategory } }>();
</script>

<div class="w-full h-full block animate-fade-in">
<div class="flex flex-wrap gap-3">
{#each categories as category (category)}
<Button
class="bg-sky-900/40 hover:bg-sky-900/60 text-sky-200 px-4 py-2 rounded-full"
on:click={() => dispatch('selectCategory', { value: category })}
>
{category}
</Button>
{/each}
</div>
</div>
36 changes: 30 additions & 6 deletions app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,47 @@
import RenderExamples from '@/components/RenderExamples.svelte';
import ChatContainer from '@/components/ChatContainer.svelte';
import { getSessionContext } from '@/stores/sessionContext.svelte.js';
import { uuid } from '@/utils/uuid';
import { goto } from '$app/navigation';
import type { ContentCategory } from '@/utils/types';
import RenderCategorySelection from '@/components/RenderCategorySelection.svelte';
const { sessionId$ } = getSessionContext();
const { sessionId$, addChatItem, startSession } = getSessionContext();
let searchTerm = '';
let triggerSelectCategory = false;
let selectContent = '';
$: sessionId = $sessionId$;
function handleSearch() {
if (searchTerm) {
console.log(searchTerm);
}
selectContent = searchTerm;
triggerSelectCategory = true;
searchTerm = '';
}
function continueChat(category: ContentCategory) {
startSession(category);
addChatItem({ id: uuid(), content: selectContent, role: 'user', loading: false });
const href = `/chat/${sessionId}?category=${category}`;
goto(href);
}
</script>

<svelte:head>
<title>Audiora</title>
</svelte:head>

<ChatContainer on:click={handleSearch} on:keypress={handleSearch}>
<RenderExamples slot="content" {sessionId} />
<ChatContainer bind:searchTerm on:click={handleSearch} on:keypress={handleSearch}>
<svelte:fragment slot="content">
{#if triggerSelectCategory && selectContent}
<RenderCategorySelection
content={selectContent}
on:selectCategory={({ detail }) => continueChat(detail.value)}
/>
{:else}
<RenderExamples {sessionId} />
{/if}
</svelte:fragment>
</ChatContainer>
4 changes: 3 additions & 1 deletion app/src/routes/chat/[sessionId=sessionId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
<ChatListItem type={item.role} content={item.content} loading={item.loading} />

{#if finalResponse && $fetchingSource$}
<div class="block w-full animate-pulse text-center p-2 text-gray-300">
<div
class="py-1 px-3 mx-auto w-fit bg-sky-600/20 animate-pulse text-sky-300 rounded-sm"
>
Fetching Audiocast Source...Please wait
</div>
{:else if finalResponse}
Expand Down

0 comments on commit 5477527

Please sign in to comment.