File tree Expand file tree Collapse file tree 5 files changed +29
-19
lines changed Expand file tree Collapse file tree 5 files changed +29
-19
lines changed Original file line number Diff line number Diff line change 1616 import IconBurger from " $lib/components/icons/IconBurger.svelte" ;
1717 import { Spring } from " svelte/motion" ;
1818 import { shareModal } from " $lib/stores/shareModal" ;
19+ import { loading } from " $lib/stores/loading" ;
1920 interface Props {
2021 title: string | undefined ;
2122 children? : import (" svelte" ).Snippet ;
2829
2930 const isHuggingChat = $derived (Boolean (page .data ?.publicConfig ?.isHuggingChat ));
3031 const canShare = $derived (
31- isHuggingChat && Boolean (page .params ?.id ) && page .route .id ?.startsWith (" /conversation/" )
32+ isHuggingChat &&
33+ ! $loading &&
34+ Boolean (page .params ?.id ) &&
35+ page .route .id ?.startsWith (" /conversation/" )
3236 );
3337
3438 // Define the width for the drawer (less than 100% to create the gap)
Original file line number Diff line number Diff line change 1+ import { writable } from "svelte/store" ;
2+
3+ export const loading = writable ( false ) ;
Original file line number Diff line number Diff line change 88
99 import { error } from " $lib/stores/errors" ;
1010 import { createSettingsStore } from " $lib/stores/settings" ;
11+ import { loading } from " $lib/stores/loading" ;
1112
1213 import Toast from " $lib/components/Toast.svelte" ;
1314 import NavMenu from " $lib/components/NavMenu.svelte" ;
244245 {#if canShare }
245246 <button
246247 type =" button"
247- class =" hidden size-8 items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white/90 text-sm font-medium text-gray-700 shadow-sm hover:bg-white/60 hover:text-gray-500 dark:border-gray-700 dark:bg-gray-800/80 dark:text-gray-200 dark:hover:bg-gray-700 md:absolute md:right-6 md:top-5 md:flex"
248+ class =" hidden size-8 items-center justify-center gap-2 rounded-xl border border-gray-200 bg-white/90 text-sm font-medium text-gray-700 shadow-sm hover:bg-white/60 hover:text-gray-500 dark:border-gray-700 dark:bg-gray-800/80 dark:text-gray-200 dark:hover:bg-gray-700 md:absolute md:right-6 md:top-5 md:flex
249+ {$loading ? 'cursor-not-allowed opacity-40' : ''}"
248250 onclick ={() => shareModal .open ()}
249251 aria-label =" Share conversation"
252+ disabled ={$loading }
250253 >
251254 <IconShare />
252255 </button >
Original file line number Diff line number Diff line change 1313 import { findCurrentModel } from " $lib/utils/models" ;
1414 import { sanitizeUrlParam } from " $lib/utils/urlParams" ;
1515 import { onMount , tick } from " svelte" ;
16+ import { loading } from " $lib/stores/loading.js" ;
1617
1718 let { data } = $props ();
1819
1920 let hasModels = $derived (Boolean (data .models ?.length ));
20- let loading = $state (false );
2121 let files: File [] = $state ([]);
2222 let draft = $state (" " );
2323
2424 const settings = useSettingsStore ();
2525
2626 async function createConversation(message : string ) {
2727 try {
28- loading = true ;
28+ $ loading = true ;
2929
3030 // check if $settings.activeModel is a valid model
3131 // else check if it's an assistant, and use that model
7171 error .set ((err as Error ).message || ERROR_MESSAGES .default );
7272 console .error (err );
7373 } finally {
74- loading = false ;
74+ $ loading = false ;
7575 }
7676 }
7777
112112{#if hasModels }
113113 <ChatWindow
114114 onmessage ={(message ) => createConversation (message )}
115- { loading }
115+ loading ={ $ loading }
116116 {currentModel }
117117 models ={data .models }
118118 bind:files
Original file line number Diff line number Diff line change 2626 import " katex/dist/katex.min.css" ;
2727 import { updateDebouncer } from " $lib/utils/updates.js" ;
2828 import SubscribeModal from " $lib/components/SubscribeModal.svelte" ;
29+ import { loading } from " $lib/stores/loading.js" ;
2930
3031 let { data = $bindable () } = $props ();
3132
32- let loading = $state (false );
3333 let pending = $state (false );
3434 let initialRun = true ;
3535 let showSubscribeModal = $state (false );
9696
9797 async function convFromShared() {
9898 try {
99- loading = true ;
99+ $ loading = true ;
100100 const res = await fetch (` ${base }/conversation ` , {
101101 method: " POST" ,
102102 headers: {
135135 }): Promise <void > {
136136 try {
137137 $isAborted = false ;
138- loading = true ;
138+ $ loading = true ;
139139 pending = true ;
140140 const base64Files = await Promise .all (
141141 (files ?? []).map ((file ) =>
335335 }
336336 console .error (err );
337337 } finally {
338- loading = false ;
338+ $ loading = false ;
339339 pending = false ;
340340 await invalidateAll ();
341341 }
348348 if (r .ok ) {
349349 setTimeout (() => {
350350 $isAborted = true ;
351- loading = false ;
351+ $ loading = false ;
352352 }, 500 );
353353 } else {
354354 $isAborted = true ;
355- loading = false ;
355+ $ loading = false ;
356356 }
357357 });
358358 }
375375 const streaming = isConversationStreaming (messages );
376376 if (streaming ) {
377377 addBackgroundGeneration ({ id: page .params .id , startedAt: Date .now () });
378- loading = true ;
378+ $ loading = true ;
379379 }
380380 });
381381
388388 await goto (` ${base }/conversation/${convId } ` , { invalidateAll: true });
389389 })
390390 .then (async () => await writeMessage ({ prompt: content }))
391- .finally (() => (loading = false ));
391+ .finally (() => ($ loading = false ));
392392 }
393393 }
394394
415415 isRetry: true ,
416416 })
417417 )
418- .finally (() => (loading = false ));
418+ .finally (() => ($ loading = false ));
419419 }
420420 }
421421
447447 $effect (() => {
448448 const streaming = isConversationStreaming (messages );
449449 if (streaming ) {
450- loading = true ;
450+ $ loading = true ;
451451 } else if (! pending ) {
452- loading = false ;
452+ $ loading = false ;
453453 }
454454
455455 if (! streaming && browser ) {
478478 }
479479
480480 $isAborted = true ;
481- loading = false ;
481+ $ loading = false ;
482482 });
483483
484484 let title = $derived .by (() => {
494494</svelte:head >
495495
496496<ChatWindow
497- { loading }
497+ loading ={ $ loading }
498498 {pending }
499499 messages ={messagesPath as Message []}
500500 {messagesAlternatives }
You can’t perform that action at this time.
0 commit comments