Skip to content

Commit

Permalink
use generate-custom-source endpoint when adding custom source
Browse files Browse the repository at this point in the history
- this allows saving the custom source to firestore
  • Loading branch information
nwaughachukwuma committed Nov 21, 2024
1 parent 39e45ab commit 3cd2a89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/src/lib/components/ManageAudioSourceDrawer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import { getCustomSources, type Sources } from '@/stores/customSources.svelte';
import { env } from '@env';
import RenderAudioSources from './RenderAudioSources.svelte';
import { getSessionContext } from '@/stores/sessionContext.svelte';
export let aiSource: string;
const { sessionId$ } = getSessionContext();
const { addSource } = getCustomSources();
let snapPoints = [0.75, 0.95];
Expand All @@ -18,6 +20,8 @@
let accordionResetKey = {};
$: sessionId = $sessionId$;
function accordionValueChanged(v: string | string[] | undefined) {
if (v === 'item-x') {
activeSnapPoint = snapPoints[snapPoints.length - 1];
Expand All @@ -36,9 +40,9 @@
}
async function fetchURLContent(url: string): Promise<Sources> {
return fetch(`${env.API_BASE_URL}/extract-url-content`, {
return fetch(`${env.API_BASE_URL}/generate-custom-source`, {
method: 'POST',
body: JSON.stringify({ url }),
body: JSON.stringify({ url, sessionId }),
headers: { 'Content-Type': 'application/json' }
})
.then<{
Expand Down
5 changes: 2 additions & 3 deletions app/src/lib/stores/customSources.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Sources = (LinkSources | CopyPasteSources) & {

const CONTEXT_KEY = {};

export const setCustomSources = () => {
export const setCustomSources = (_sessionId: string) => {
const sources$ = writable<Sources[]>([]);

return setContext(CONTEXT_KEY, {
Expand All @@ -31,5 +31,4 @@ export const setCustomSources = () => {
};

export type CustomSourcesType = ReturnType<typeof setCustomSources>;
export const getCustomSources = () =>
getContext<CustomSourcesType>(CONTEXT_KEY) || setCustomSources();
export const getCustomSources = () => getContext<CustomSourcesType>(CONTEXT_KEY);
5 changes: 4 additions & 1 deletion app/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import { page } from '$app/stores';
import Spinner from '@/components/Spinner.svelte';
import { setAppContext } from '@/stores/appContext.svelte';
import { setCustomSources } from '@/stores/customSources.svelte';
export let data;
$: setAppContext();
$: sessionId = $page.params.sessionId || data.sessionId;
$: setAppContext();
$: setSessionContext(sessionId);
$: setCustomSources(sessionId);
</script>

<svelte:head>
Expand Down

0 comments on commit 3cd2a89

Please sign in to comment.