Skip to content

Commit

Permalink
render loading state and file_icon
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Dec 6, 2024
1 parent b9c690e commit bbb41e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
8 changes: 3 additions & 5 deletions app/src/lib/components/ChatBoxAttachment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
continue;
}
$uploadedItems$.push({
id: slug(file.name),
file: file,
loading: true,
errored: false
uploadedItems$.update((files) => {
files.push({ id: slug(file.name), file: file, loading: true, errored: false });
return files;
});
}
Expand Down
32 changes: 21 additions & 11 deletions app/src/lib/components/ChatBoxAttachmentPreview.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script lang="ts">
import { XIcon } from 'lucide-svelte';
import { FileIcon, XIcon } from 'lucide-svelte';
import { Button } from './ui/button';
import { createEventDispatcher } from 'svelte';
import { getAttachmentsContext } from '@/stores/attachmentsContext.svelte';
import Spinner from './Spinner.svelte';
export let selectedFiles: File[] = [];
const { uploadedItems$ } = getAttachmentsContext();
const dispatch = createEventDispatcher<{ updateAttach: { files: File[] } }>();
function removeFile(index: number) {
selectedFiles = selectedFiles.filter((_, i) => i !== index);
dispatch('updateAttach', { files: selectedFiles });
function removeFile(id: string) {
uploadedItems$.update((files) => {
return files.filter((f) => f.id !== id);
});
}
function formatFileSize(bytes: number): string {
Expand All @@ -33,11 +33,20 @@
return fileType;
}
}
$: validItems = $uploadedItems$.filter((item) => !item.errored);
</script>

<div class="p-2 flex flex-wrap gap-2 bg-zinc-800/30">
{#each selectedFiles as file, index}
<div class="flex items-center w-56 justify-between bg-zinc-700/30 rounded p-2">
{#each validItems as { file, id, loading } (id)}
<div class="flex items-center w-56 gap-2 justify-between bg-zinc-700/30 rounded p-2">
<div class="p-1">
{#if loading}
<Spinner />
{:else}
<FileIcon class="w-6 h-6 text-emerald-800" />
{/if}
</div>
<div class="flex-1 min-w-0">
<p class="text-sm text-white truncate">{file.name}</p>
<p class="text-xs text-zinc-400">
Expand All @@ -48,7 +57,8 @@
variant="ghost"
size="icon"
class="text-zinc-400 hover:text-white hover:bg-zinc-700/70"
on:click={() => removeFile(index)}
disabled={loading}
on:click={() => removeFile(id)}
>
<XIcon class="h-4 w-4" />
</Button>
Expand Down

0 comments on commit bbb41e9

Please sign in to comment.