fix: link "Enter the folder" was causing page reload, and thus losing state (like clipboard)
Massimo Melina committed
Jun 14, 2024 at 23:03 UTC
61978ebca6da4407ec742cc439975b94852f6eb1
2 files changed
+14
-6
frontend/src/upload.ts
+6
-4
@@ -486,10 +486,12 @@ async function createFolder() {
486
h(FlexV, {},
487
h('div', {}, t`Successfully created`),
488
h(Link, {
489
- to: uri + encodeURIComponent(name) + '/',
490
- onClickCapture() { // "capture" because dialogs must be closed (popping from history) before we push a new state in the history
491
- closeDialog()
492
- closeDialog()
489
+ to: '', // wasn't able
490
+ async onClick(ev) {
491
+ ev.preventDefault()
492
+ await closeDialog()?.closed
493
+ await closeDialog()?.closed
494
+ getHFS().navigate(uri + encodeURIComponent(name) + '/')
495
}
496
}, t('enter_folder', "Enter the folder")),
497
)))
shared/dialogs.ts
+8
-2
@@ -21,6 +21,7 @@ export interface DialogOptions {
21
$id?: number
22
$opening?: NodeJS.Timeout
23
ts?: number
24
+ closed?: Promise<void>
25
26
Container?: FunctionComponent<DialogOptions>
27
}
@@ -70,7 +71,12 @@ export function isDescendant(child: Node | null | undefined, parentMatch: Node |
71
let ignorePopState = false
72
function back() {
73
ignorePopState = true
74
+ let was = history.state
75
history.back()
76
+ return new Promise<void>(res => {
77
+ const h = setInterval(() => was !== history.state && res() , 10)
78
+ setTimeout(() => clearTimeout(h), 500)
79
+ })
80
}
81
82
;(async () => {
@@ -190,7 +196,7 @@ export function newDialog(options: DialogOptions) {
196
const i = dialogs.findIndex(x => (x as any).$id === $id)
197
if (i < 0) return
198
if (history.state.$dialog === $id)
193
- back()
199
+ options.closed = back()
200
return closeDialogAt(i, v)
201
}
202
}
@@ -204,7 +210,7 @@ export function closeDialog(v?:any, skipHistory=false) {
210
continue
211
if (!skipHistory) {
212
if (history.state.$dialog !== d.$id) return
207
- back()
213
+ d.closed = back()
214
}
215
closeDialogAt(i, v)
216
return d