show loading screen

This commit is contained in:
Silas 2023-04-09 18:22:05 -04:00
parent ffd1bfc4a2
commit f3eda31c48
Signed by: silentsilas
GPG Key ID: 4199EFB7DAA34349
1 changed files with 44 additions and 39 deletions

View File

@ -6,9 +6,9 @@
let files: FileList | null;
let url: string = '';
let urlInput: HTMLInputElement;
let fileForm: HTMLFormElement;
let hasFile = true;
let loading = false;
$: if (files && files.length >= 0) {
hasFile = true;
@ -44,6 +44,7 @@
const summarize = async () => {
try {
loading = true;
let result;
if (hasFile) {
if (!files) throw new Error('File missing');
@ -53,6 +54,7 @@
result = await submitUrl(url);
}
summary.set(JSON.stringify(result.response));
loading = false;
return goto('chat');
} catch (error) {
alert((error as App.Error).message);
@ -63,43 +65,46 @@
<div class="container h-full mx-auto flex justify-center items-center px-4">
<div class="text-center">
<h2>Please Sumi</h2>
<p class="my-4">Enter the URL you'd like to have summarized.</p>
<div>
<input
class="input"
type="text"
bind:value={url}
bind:this={urlInput}
disabled={hasFile}
placeholder="https://stupid.article/you-will-never-believe-this-shit"
/>
</div>
<p class="my-6"></p>
<div>
<p>Or you can submit a text file instead:</p>
<form bind:this={fileForm}>
<div class="flex flex-row">
<input class="input my-4" type="file" accept=".txt" name="conversation" bind:files />
{#if hasFile}
<button
type="button"
class="btn btn-icon-sm variant-ghost-error self-center"
style="height: 100%;"
on:click={removeFile}
><Fa icon={faTrashCan} />
</button>
{/if}
</div>
</form>
</div>
<div class="flex justify-center space-x-2 my-12">
<button
type="button"
class="btn variant-ringed-tertiary"
disabled={!hasFile && url.length <= 0}
on:click={summarize}>Summarize</button
>
</div>
{#if loading}
<p>Please wait while Sumi tries to make sense of this garbage.</p>
{:else}
<h2>Please Sumi</h2>
<p class="my-4">Enter the URL you'd like to have summarized.</p>
<div>
<input
class="input"
type="text"
bind:value={url}
disabled={hasFile}
placeholder="https://stupid.article/you-will-never-believe-this-shit"
/>
</div>
<p class="my-6"></p>
<div>
<p>Or you can submit a text file instead:</p>
<form bind:this={fileForm}>
<div class="flex flex-row">
<input class="input my-4" type="file" accept=".txt" name="conversation" bind:files />
{#if hasFile}
<button
type="button"
class="btn btn-icon-sm variant-ghost-error self-center"
style="height: 100%;"
on:click={removeFile}
><Fa icon={faTrashCan} />
</button>
{/if}
</div>
</form>
</div>
<div class="flex justify-center space-x-2 my-12">
<button
type="button"
class="btn variant-ringed-tertiary"
disabled={!hasFile && url.length <= 0}
on:click={summarize}>Summarize</button
>
</div>
{/if}
</div>
</div>