From 54775278da1de094d41c09705193232ab31c8bdb Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Tue, 12 Nov 2024 14:46:05 +0000 Subject: [PATCH] add logic to select category if the user starts with chatting --- app/src/lib/components/ChatContainer.svelte | 7 ++-- .../components/RenderCategorySelection.svelte | 13 +++++++ app/src/lib/components/SelectCategory.svelte | 33 +++++++++++++++++ app/src/routes/+page.svelte | 36 +++++++++++++++---- .../chat/[sessionId=sessionId]/+page.svelte | 4 ++- 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 app/src/lib/components/RenderCategorySelection.svelte create mode 100644 app/src/lib/components/SelectCategory.svelte diff --git a/app/src/lib/components/ChatContainer.svelte b/app/src/lib/components/ChatContainer.svelte index 38dc80c..f5edada 100644 --- a/app/src/lib/components/ChatContainer.svelte +++ b/app/src/lib/components/ChatContainer.svelte @@ -7,9 +7,12 @@ let navLoading = false; -
+
-
+
diff --git a/app/src/lib/components/RenderCategorySelection.svelte b/app/src/lib/components/RenderCategorySelection.svelte new file mode 100644 index 0000000..b76ed28 --- /dev/null +++ b/app/src/lib/components/RenderCategorySelection.svelte @@ -0,0 +1,13 @@ + + +
+ + + + + +
diff --git a/app/src/lib/components/SelectCategory.svelte b/app/src/lib/components/SelectCategory.svelte new file mode 100644 index 0000000..625cdfb --- /dev/null +++ b/app/src/lib/components/SelectCategory.svelte @@ -0,0 +1,33 @@ + + + + +
+
+ {#each categories as category (category)} + + {/each} +
+
diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index c2e7324..0439f3d 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -2,16 +2,31 @@ 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); } @@ -19,6 +34,15 @@ Audiora - - + + + {#if triggerSelectCategory && selectContent} + continueChat(detail.value)} + /> + {:else} + + {/if} + diff --git a/app/src/routes/chat/[sessionId=sessionId]/+page.svelte b/app/src/routes/chat/[sessionId=sessionId]/+page.svelte index 211e4db..1699d6c 100644 --- a/app/src/routes/chat/[sessionId=sessionId]/+page.svelte +++ b/app/src/routes/chat/[sessionId=sessionId]/+page.svelte @@ -109,7 +109,9 @@ {#if finalResponse && $fetchingSource$} -
+
Fetching Audiocast Source...Please wait
{:else if finalResponse}