victor HF Staff nsarrazin HF Staff commited on
Commit
5ddf84d
·
unverified ·
1 Parent(s): 1c84463

UX: Dropzone (#1350)

Browse files

* nav: more compact

* drop window trigger

* fix z-index

* border width

---------

Co-authored-by: Nathan Sarrazin <[email protected]>

src/lib/components/NavConversationItem.svelte CHANGED
@@ -25,7 +25,7 @@
25
  confirmDelete = false;
26
  }}
27
  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 ===
29
  $page.params.id
30
  ? 'bg-gray-100 dark:bg-gray-700'
31
  : ''}"
 
25
  confirmDelete = false;
26
  }}
27
  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 sm:h-[2.35rem] dark:text-gray-300 dark:hover:bg-gray-700 {conv.id ===
29
  $page.params.id
30
  ? 'bg-gray-100 dark:bg-gray-700'
31
  : ''}"
src/lib/components/NavMenu.svelte CHANGED
@@ -57,13 +57,13 @@
57
  <a
58
  href={`${base}/`}
59
  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"
61
  >
62
  New Chat
63
  </a>
64
  </div>
65
  <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"
67
  >
68
  {#each Object.entries(groupedConversations) as [group, convs]}
69
  {#if convs.length}
 
57
  <a
58
  href={`${base}/`}
59
  on:click={handleNewChatClick}
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"
61
  >
62
  New Chat
63
  </a>
64
  </div>
65
  <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 text-[.9rem] max-sm:bg-gradient-to-t md:bg-gradient-to-l dark:from-gray-800/30"
67
  >
68
  {#each Object.entries(groupedConversations) as [group, convs]}
69
  {#if convs.length}
src/lib/components/chat/ChatWindow.svelte CHANGED
@@ -82,9 +82,6 @@
82
  onDrag = false;
83
  }
84
  };
85
- const onDragOver = (e: DragEvent) => {
86
- e.preventDefault();
87
- };
88
 
89
  const onPaste = (e: ClipboardEvent) => {
90
  if (!e.clipboardData) {
@@ -167,6 +164,13 @@
167
  $: isFileUploadEnabled = activeMimeTypes.length > 0;
168
  </script>
169
 
 
 
 
 
 
 
 
170
  <div class="relative min-h-0 min-w-0">
171
  {#if loginModalOpen}
172
  <LoginModal
@@ -332,9 +336,6 @@
332
  {/if}
333
  </div>
334
  <form
335
- on:dragover={onDragOver}
336
- on:dragenter={onDragEnter}
337
- on:dragleave={onDragLeave}
338
  tabindex="-1"
339
  aria-label={isFileUploadEnabled ? "file dropzone" : undefined}
340
  on:submit|preventDefault={handleSubmit}
 
82
  onDrag = false;
83
  }
84
  };
 
 
 
85
 
86
  const onPaste = (e: ClipboardEvent) => {
87
  if (!e.clipboardData) {
 
164
  $: isFileUploadEnabled = activeMimeTypes.length > 0;
165
  </script>
166
 
167
+ <svelte:window
168
+ on:dragenter={onDragEnter}
169
+ on:dragleave={onDragLeave}
170
+ on:dragover|preventDefault
171
+ on:drop|preventDefault={() => (onDrag = false)}
172
+ />
173
+
174
  <div class="relative min-h-0 min-w-0">
175
  {#if loginModalOpen}
176
  <LoginModal
 
336
  {/if}
337
  </div>
338
  <form
 
 
 
339
  tabindex="-1"
340
  aria-label={isFileUploadEnabled ? "file dropzone" : undefined}
341
  on:submit|preventDefault={handleSubmit}
src/lib/components/chat/FileDropzone.svelte CHANGED
@@ -1,15 +1,12 @@
1
  <script lang="ts">
2
- import { onDestroy } from "svelte";
3
  import CarbonImage from "~icons/carbon/image";
4
  // import EosIconsLoading from "~icons/eos-icons/loading";
5
 
6
  export let files: File[];
7
  export let mimeTypes: string[] = [];
8
 
9
- let file_error_message = "";
10
- let errorTimeout: ReturnType<typeof setTimeout>;
11
-
12
  export let onDrag = false;
 
13
 
14
  async function dropHandle(event: DragEvent) {
15
  event.preventDefault();
@@ -51,69 +48,22 @@
51
  }
52
 
53
  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);
62
  }
63
-
64
- onDestroy(() => {
65
- if (errorTimeout) {
66
- clearTimeout(errorTimeout);
67
- }
68
- });
69
  </script>
70
 
71
  <div
72
  id="dropzone"
73
  role="form"
74
  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"
 
 
 
 
 
76
  >
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>
103
  </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>
 
1
  <script lang="ts">
 
2
  import CarbonImage from "~icons/carbon/image";
3
  // import EosIconsLoading from "~icons/eos-icons/loading";
4
 
5
  export let files: File[];
6
  export let mimeTypes: string[] = [];
7
 
 
 
 
8
  export let onDrag = false;
9
+ export let onDragInner = false;
10
 
11
  async function dropHandle(event: DragEvent) {
12
  event.preventDefault();
 
48
  }
49
 
50
  function setErrorMsg(errorMsg: string) {
51
+ onDrag = false;
52
+ alert(errorMsg);
 
 
 
 
 
 
53
  }
 
 
 
 
 
 
54
  </script>
55
 
56
  <div
57
  id="dropzone"
58
  role="form"
59
  on:drop={dropHandle}
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'}"
66
  >
67
+ <CarbonImage class="text-xl" />
68
+ <p>Drop File to add to chat</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/routes/assistant/[assistantId]/+page.svelte CHANGED
@@ -40,14 +40,14 @@
40
  </svelte:head>
41
 
42
  <div
43
- class="fixed inset-0 flex items-center justify-center bg-black/80 backdrop-blur-sm dark:bg-black/50"
44
  >
45
  <dialog
46
  open
47
  use:clickOutside={() => {
48
  goto(previousPage);
49
  }}
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"
51
  >
52
  <div class="absolute right-0 top-0 m-6">
53
  <form
 
40
  </svelte:head>
41
 
42
  <div
43
+ class="fixed inset-0 z-20 flex items-center justify-center bg-black/80 backdrop-blur-sm dark:bg-black/50"
44
  >
45
  <dialog
46
  open
47
  use:clickOutside={() => {
48
  goto(previousPage);
49
  }}
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"
51
  >
52
  <div class="absolute right-0 top-0 m-6">
53
  <form