Skip to content

Commit fc2c114

Browse files
gary149nsarrazin
andauthored
UX: Dropzone (#1350)
* nav: more compact * drop window trigger * fix z-index * border width --------- Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent 8461fd6 commit fc2c114

File tree

5 files changed

+23
-72
lines changed

5 files changed

+23
-72
lines changed

src/lib/components/NavConversationItem.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
confirmDelete = false;
2626
}}
2727
href="{base}/conversation/{conv.id}"
28-
class="group flex h-10 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700 {conv.id ===
28+
class="group flex h-10 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-600 hover:bg-gray-100 sm:h-[2.35rem] dark:text-gray-300 dark:hover:bg-gray-700 {conv.id ===
2929
$page.params.id
3030
? 'bg-gray-100 dark:bg-gray-700'
3131
: ''}"

src/lib/components/NavMenu.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
<a
5858
href={`${base}/`}
5959
on:click={handleNewChatClick}
60-
class="flex rounded-lg border bg-white px-2 py-0.5 text-center shadow-sm hover:shadow-none dark:border-gray-600 dark:bg-gray-700"
60+
class="flex rounded-lg border bg-white px-2 py-0.5 text-center shadow-sm hover:shadow-none sm:text-smd dark:border-gray-600 dark:bg-gray-700"
6161
>
6262
New Chat
6363
</a>
6464
</div>
6565
<div
66-
class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl from-gray-50 px-3 pb-3 pt-2 max-sm:bg-gradient-to-t md:bg-gradient-to-l dark:from-gray-800/30"
66+
class="scrollbar-custom flex flex-col gap-1 overflow-y-auto rounded-r-xl from-gray-50 px-3 pb-3 pt-2 text-[.9rem] max-sm:bg-gradient-to-t md:bg-gradient-to-l dark:from-gray-800/30"
6767
>
6868
{#each Object.entries(groupedConversations) as [group, convs]}
6969
{#if convs.length}

src/lib/components/chat/ChatWindow.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@
8282
onDrag = false;
8383
}
8484
};
85-
const onDragOver = (e: DragEvent) => {
86-
e.preventDefault();
87-
};
8885
8986
const onPaste = (e: ClipboardEvent) => {
9087
if (!e.clipboardData) {
@@ -167,6 +164,13 @@
167164
$: isFileUploadEnabled = activeMimeTypes.length > 0;
168165
</script>
169166

167+
<svelte:window
168+
on:dragenter={onDragEnter}
169+
on:dragleave={onDragLeave}
170+
on:dragover|preventDefault
171+
on:drop|preventDefault={() => (onDrag = false)}
172+
/>
173+
170174
<div class="relative min-h-0 min-w-0">
171175
{#if loginModalOpen}
172176
<LoginModal
@@ -332,9 +336,6 @@
332336
{/if}
333337
</div>
334338
<form
335-
on:dragover={onDragOver}
336-
on:dragenter={onDragEnter}
337-
on:dragleave={onDragLeave}
338339
tabindex="-1"
339340
aria-label={isFileUploadEnabled ? "file dropzone" : undefined}
340341
on:submit|preventDefault={handleSubmit}
Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<script lang="ts">
2-
import { onDestroy } from "svelte";
32
import CarbonImage from "~icons/carbon/image";
43
// import EosIconsLoading from "~icons/eos-icons/loading";
54
65
export let files: File[];
76
export let mimeTypes: string[] = [];
87
9-
let file_error_message = "";
10-
let errorTimeout: ReturnType<typeof setTimeout>;
11-
128
export let onDrag = false;
9+
export let onDragInner = false;
1310
1411
async function dropHandle(event: DragEvent) {
1512
event.preventDefault();
@@ -51,69 +48,22 @@
5148
}
5249
5350
function setErrorMsg(errorMsg: string) {
54-
if (errorTimeout) {
55-
clearTimeout(errorTimeout);
56-
}
57-
file_error_message = errorMsg;
58-
errorTimeout = setTimeout(() => {
59-
file_error_message = "";
60-
onDrag = false;
61-
}, 2000);
51+
onDrag = false;
52+
alert(errorMsg);
6253
}
63-
64-
onDestroy(() => {
65-
if (errorTimeout) {
66-
clearTimeout(errorTimeout);
67-
}
68-
});
6954
</script>
7055

7156
<div
7257
id="dropzone"
7358
role="form"
7459
on:drop={dropHandle}
75-
class="relative flex w-full max-w-4xl flex-col items-center rounded-xl border border-dashed bg-gray-100 focus-within:border-gray-300 dark:border-gray-500 dark:bg-gray-700 dark:focus-within:border-gray-500"
60+
on:dragenter={() => (onDragInner = true)}
61+
on:dragleave={() => (onDragInner = false)}
62+
on:dragover|preventDefault
63+
class="relative flex h-28 w-full max-w-4xl flex-col items-center justify-center gap-1 rounded-xl border-2 border-dotted {onDragInner
64+
? 'border-blue-200 !bg-blue-500/10 text-blue-600 *:pointer-events-none dark:border-blue-600 dark:bg-blue-500/20 dark:text-blue-500'
65+
: 'bg-gray-100 text-gray-500 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-400'}"
7666
>
77-
<div class="object-center">
78-
{#if file_error_message}
79-
<div
80-
class="absolute bottom-0 left-0 right-0 top-0 flex flex-col items-center justify-center gap-2 rounded-xl bg-gray-100 bg-opacity-50 dark:bg-gray-700 dark:bg-opacity-50"
81-
>
82-
<p class="text-red-500 dark:text-red-400">{file_error_message}</p>
83-
<div class="h-2.5 w-1/2 rounded-full bg-gray-200 dark:bg-gray-700">
84-
<div
85-
class="animate-progress-bar h-2.5
86-
rounded-full bg-red-500
87-
dark:text-red-400
88-
"
89-
/>
90-
</div>
91-
</div>
92-
{/if}
93-
<div class="mt-3 flex justify-center" class:opacity-0={file_error_message}>
94-
<CarbonImage class="text-xl text-gray-500 dark:text-gray-400" />
95-
</div>
96-
<p
97-
class="mb-3 mt-1.5 text-sm text-gray-500 dark:text-gray-400"
98-
class:opacity-0={file_error_message}
99-
>
100-
Drag and drop <span class="font-semibold">one file</span> here
101-
</p>
102-
</div>
67+
<CarbonImage class="text-xl" />
68+
<p>Drop File to add to chat</p>
10369
</div>
104-
105-
<style>
106-
@keyframes slideInFromLeft {
107-
0% {
108-
width: 0;
109-
}
110-
100% {
111-
width: 100%;
112-
}
113-
}
114-
115-
.animate-progress-bar {
116-
/* This section calls the slideInFromLeft animation we defined above */
117-
animation: 2s linear 0s 1 slideInFromLeft;
118-
}
119-
</style>

src/routes/assistant/[assistantId]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
</svelte:head>
4141

4242
<div
43-
class="fixed inset-0 flex items-center justify-center bg-black/80 backdrop-blur-sm dark:bg-black/50"
43+
class="fixed inset-0 z-20 flex items-center justify-center bg-black/80 backdrop-blur-sm dark:bg-black/50"
4444
>
4545
<dialog
4646
open
4747
use:clickOutside={() => {
4848
goto(previousPage);
4949
}}
50-
class="z-10 flex flex-col content-center items-center gap-x-10 gap-y-3 overflow-hidden rounded-2xl bg-white p-4 pt-6 text-center shadow-2xl outline-none max-sm:w-[85dvw] max-sm:px-6 md:w-96 md:grid-cols-3 md:grid-rows-[auto,1fr] md:p-8"
50+
class="flex flex-col content-center items-center gap-x-10 gap-y-3 overflow-hidden rounded-2xl bg-white p-4 pt-6 text-center shadow-2xl outline-none max-sm:w-[85dvw] max-sm:px-6 md:w-96 md:grid-cols-3 md:grid-rows-[auto,1fr] md:p-8"
5151
>
5252
<div class="absolute right-0 top-0 m-6">
5353
<form

0 commit comments

Comments
 (0)