Skip to content

Commit

Permalink
show loading spinner on "suggest title" button
Browse files Browse the repository at this point in the history
  • Loading branch information
Shackless committed Apr 5, 2023
1 parent 9d53b15 commit 52a6cb5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/lib/Modals/SuggestTitleModal.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<script lang="ts">
import { modalStore } from '@skeletonlabs/skeleton';
import { modalStore, ProgressRadial } from '@skeletonlabs/skeleton';
import { chatStore, settingsStore } from '$misc/stores';
import { canSuggestTitle, suggestChatTitle } from '$misc/shared';
let slug = $modalStore[0].meta?.slug || '';
let isLoading = false;
$: showAiSuggestOptions = $settingsStore.openAiApiKey && canSuggestTitle($chatStore[slug]);
async function handleSuggestTitle() {
if (!$settingsStore.openAiApiKey) {
return;
}
isLoading = true;
const title = await suggestChatTitle($chatStore[slug], $settingsStore.openAiApiKey);
chatStore.updateChat(slug, { title });
isLoading = false;
}
function handleSave() {
Expand All @@ -35,8 +38,21 @@
{#if showAiSuggestOptions}
<span class="self-center">OR:</span>

<button class="btn variant variant-filled-secondary" on:click={handleSuggestTitle}>
Let ChatGPT suggest a title
<button
class="btn variant variant-filled-secondary"
disabled={isLoading}
on:click={handleSuggestTitle}
>
{#if !isLoading}
Let ChatGPT suggest a new title
{:else}
<ProgressRadial
class="w-6"
stroke={120}
meter="stroke-tertiary-500"
track="stroke-tertiary-500/30"
/>
{/if}
</button>

<span class="text-xs text-slate-400">
Expand Down

0 comments on commit 52a6cb5

Please sign in to comment.