Skip to content

Commit

Permalink
improve chat_box attachment and attachment preview components
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Dec 6, 2024
1 parent 5441345 commit 8e6b0aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/src/lib/components/ChatBoxAttachment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
const files = Array.from(fileList);
if (selectedFiles.length + files.length > MAX_FILES) {
alert(`You can only upload up to ${MAX_FILES} files`);
return;
return toast.info(`You can only upload up to ${MAX_FILES} files`);
}
selectedFiles = [...selectedFiles, ...files];
Expand All @@ -47,7 +46,7 @@

<input
type="file"
accept=".pdf,.txt"
accept=".pdf,.txt,.docx"
multiple
class="hidden"
bind:this={fileInput}
Expand Down
22 changes: 18 additions & 4 deletions app/src/lib/components/ChatBoxAttachmentPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function parseFileType(file: File) {
const fileType = file.type.split('/')[1];
switch (fileType) {
case 'pdf':
return 'pdf';
case 'vnd.openxmlformats-officedocument.wordprocessingml.document':
return 'docx';
case 'plain':
return 'txt';
default:
return fileType;
}
}
</script>

<div class="p-2 space-y-2 bg-zinc-800/30">
<div class="p-2 flex flex-wrap gap-2 bg-zinc-800/30">
{#each selectedFiles as file, index}
<div class="flex items-center justify-between bg-zinc-700/30 rounded p-2">
<div class="flex items-center w-56 justify-between bg-zinc-700/30 rounded p-2">
<div class="flex-1 min-w-0">
<p class="text-sm text-white truncate">{file.name}</p>
<p class="text-xs text-zinc-400">
{formatFileSize(file.size)} • {file.type || 'text/plain'}
{formatFileSize(file.size)} • {parseFileType(file)}
</p>
</div>
<Button
variant="ghost"
size="icon"
class="text-zinc-400 hover:text-white"
class="text-zinc-400 hover:text-white hover:bg-zinc-700/70"
on:click={() => removeFile(index)}
>
<XIcon class="h-4 w-4" />
Expand Down

0 comments on commit 8e6b0aa

Please sign in to comment.