1010 </template >
1111 <template #end >
1212 <RouterLink :to =" { name: ' DropboxListSent' , params: $route .params , query: $route .query } " >
13- <BaseButton type="black" icon="arrow-left" :label =" t (' Back' )" />
13+ <BaseButton
14+ type="black"
15+ icon="arrow-left"
16+ :label =" t (' Back' )"
17+ />
1418 </RouterLink >
1519 </template >
1620 </BaseToolbar >
1721
18- <div class =" grid mt-5 gap-6" style =" grid-template-columns : 1.6fr 1fr " >
22+ <div
23+ class =" grid mt-5 gap-6"
24+ style =" grid-template-columns : 1.6fr 1fr "
25+ >
1926 <!-- LEFT: files -->
2027 <div >
2128 <div class =" rounded-lg border border-gray-50 bg-white shadow-sm" >
3744 />
3845 </div >
3946
40- <div v-if =" pickedFiles.length" class =" mt-3" >
47+ <div
48+ v-if =" pickedFiles.length"
49+ class =" mt-3"
50+ >
4151 <div class =" text-sm text-gray-600 mb-1" >{{ t("Selected files") }}</div >
4252 <ul class =" text-sm space-y-1" >
4353 <li
6070 </ul >
6171 </div >
6272
63- <div v-else class =" mt-3 text-sm text-gray-500" >
73+ <div
74+ v-else
75+ class =" mt-3 text-sm text-gray-500"
76+ >
6477 {{ t("No file selected.") }}
6578 </div >
6679 </div >
7891 />
7992
8093 <label class =" inline-flex items-center gap-3 mt-3" >
81- <input id =" overwrite" type =" checkbox" v-model =" overwrite" />
94+ <input
95+ id =" overwrite"
96+ type =" checkbox"
97+ v-model =" overwrite"
98+ />
8299 <span class =" text-sm" >{{ t("Overwrite previous versions of same document?") }}</span >
83100 </label >
84101 </div >
90107 <div class =" rounded-lg border border-gray-50 bg-white shadow-sm" >
91108 <div class =" px-4 py-3 border-b text-sm font-medium" >{{ t("Sharing") }}</div >
92109 <div class =" p-4" >
93- <label class =" block text-sm mb-1" >
94- {{ t("Recipients") }} <span class =" text-red-600" >*</span >
95- </label >
110+ <label class =" block text-sm mb-1" > {{ t("Recipients") }} <span class =" text-red-600" >*</span > </label >
96111 <BaseSelect
97112 v-model =" recipients "
98113 :options =" recipientOptions "
105120 :class =" { ' ring-1 ring-red-500 rounded-md' : submitted && ! hasSelectedRecipient } "
106121 />
107122 <small class =" text-gray-500 block mt-1" >
108- {{ t(' Tip: choose “— Just upload —” to store without sending to anyone.' ) }}
123+ {{ t(" Tip: choose “— Just upload —” to store without sending to anyone." ) }}
109124 </small >
110- <div v-if =" submitted && !hasSelectedRecipient" class =" text-sm text-red-600 mt-1" >
111- {{ t('Please select at least one recipient (“— Just upload —” or any user)') }}
125+ <div
126+ v-if =" submitted && !hasSelectedRecipient"
127+ class =" text-sm text-red-600 mt-1"
128+ >
129+ {{ t("Please select at least one recipient (“— Just upload —” or any user)") }}
112130 </div >
113131
114132 <div class =" flex justify-end gap-2 mt-6" >
115133 <RouterLink :to =" { name: ' DropboxListSent' , params: $route .params , query: $route .query } " >
116- <BaseButton type="black" icon="xmark" :label =" t (' Cancel' )" />
134+ <BaseButton
135+ type="black"
136+ icon="xmark"
137+ :label =" t (' Cancel' )"
138+ />
117139 </RouterLink >
118140 <BaseButton
119141 type="primary"
126148 </div >
127149 </div >
128150
129- <div v-if =" isUploading" class =" text-xs text-gray-500 mt-2 text-right" >
151+ <div
152+ v-if =" isUploading"
153+ class =" text-xs text-gray-500 mt-2 text-right"
154+ >
130155 {{ t("Uploading... please keep this tab open.") }}
131156 </div >
132157 </div >
135160</template >
136161
137162<script setup>
138- import { computed , onBeforeUnmount , onMounted , ref } from " vue"
163+ import { computed , markRaw , onBeforeUnmount , onMounted , ref , shallowRef } from " vue"
139164import { useRoute , useRouter } from " vue-router"
140165import { useI18n } from " vue-i18n"
141166import Uppy from " @uppy/core"
@@ -153,8 +178,8 @@ import service from "../../services/dropbox"
153178const { t } = useI18n ()
154179const route = useRoute ()
155180const router = useRouter ()
181+ const uppy = shallowRef (null )
156182
157- const uppy = ref (null )
158183const pickedFiles = ref ([])
159184const description = ref (" " )
160185const overwrite = ref (false )
@@ -164,41 +189,61 @@ const isUploading = ref(false)
164189// recipients
165190const recipients = ref ([])
166191const recipientOptions = ref ([])
192+ let syncPicked = null
167193
168194onMounted (() => {
169- uppy .value = new Uppy ({
170- autoProceed: false ,
171- allowMultipleUploads: true ,
172- restrictions: { maxNumberOfFiles: null },
173- })
195+ uppy .value = markRaw (
196+ new Uppy ({
197+ autoProceed: false ,
198+ allowMultipleUploads: true ,
199+ restrictions: { maxNumberOfFiles: null },
200+ }),
201+ )
174202
175- // sync picked files when user adds/removes in dashboard
176- const syncPicked = () => {
177- pickedFiles .value = Object . values ( uppy . value ? . getFiles ? .() ?? {}) .map ((f ) => f .data )
203+ syncPicked = () => {
204+ const files = uppy . value ? . getFiles ? . () ?? []
205+ pickedFiles .value = files .map ((f ) => f .data )
178206 }
179207 uppy .value ? .on ? .(" file-added" , syncPicked)
180208 uppy .value ? .on ? .(" file-removed" , syncPicked)
181209})
182210
183211onBeforeUnmount (() => {
184- if (uppy .value ) {
185- try { uppy .value .cancelAll () } catch {}
186- try { uppy .value .reset () } catch {}
187- uppy .value = null
188- }
212+ if (! uppy .value ) return
213+
214+ try {
215+ if (syncPicked) {
216+ uppy .value ? .off ? .(" file-added" , syncPicked)
217+ uppy .value ? .off ? .(" file-removed" , syncPicked)
218+ }
219+ } catch {}
220+
221+ try {
222+ uppy .value .cancelAll ()
223+ } catch {}
224+ try {
225+ uppy .value .reset ()
226+ } catch {}
227+
228+ try {
229+ uppy .value .close ? .()
230+ } catch {}
231+
232+ uppy .value = null
189233})
190234
191235function removePicked (file ) {
192236 // remove by id match in uppy store
193- const record = (uppy .value ? .getFiles ? .() || []).find ((r ) => r .data === file)
237+ const list = uppy .value ? .getFiles ? .() ?? []
238+ const record = list .find ((r ) => r .data === file)
194239 if (record) uppy .value ? .removeFile ? .(record .id )
195240 else pickedFiles .value = pickedFiles .value .filter ((f ) => f !== file)
196241}
197242
198243// utils
199244function humanSize (bytes ) {
200- const units = [" B" ," KB" ," MB" ," GB" ," TB" ]
201- const i = bytes > 0 ? Math .floor (Math .log (bytes)/ Math .log (1024 )) : 0
245+ const units = [" B" , " KB" , " MB" , " GB" , " TB" ]
246+ const i = bytes > 0 ? Math .floor (Math .log (bytes) / Math .log (1024 )) : 0
202247 return ` ${ (bytes / Math .pow (1024 , i)).toFixed (1 )} ${ units[i]} `
203248}
204249
@@ -253,7 +298,9 @@ async function submit() {
253298 description .value = " "
254299 overwrite .value = false
255300 recipients .value = []
256- try { uppy .value ? .reset () } catch {}
301+ try {
302+ uppy .value ? .reset ? .()
303+ } catch {}
257304 pickedFiles .value = []
258305
259306 // Navigate back to list (sent)
0 commit comments