@samitouri / QOSami-HFS / commits / 67cfd361

fix: (regression 0.52.1) folder-menu: faulty "open"

Massimo Melina committed Jul 2, 2024 at 11:33 UTC 67cfd361cd0357eb445154bf47f02083529290f1
2 files changed +20 -14
frontend/src/fileMenu.ts
+18 -5
@@ -1,14 +1,14 @@
1 import { t, useI18N } from './i18n'
2 import {
3 dontBotherWithKeys, formatBytes, getHFS, hfsEvent, hIcon, newDialog, prefix, with_, working,
4 - pathEncode, closeDialog
4 + pathEncode, closeDialog, anyDialogOpen
5 } from './misc'
6 import { createElement as h, Fragment, isValidElement, MouseEvent, ReactNode } from 'react'
7 import _ from 'lodash'
8 import { getEntryIcon, MISSING_PERM } from './BrowseFiles'
9 import { DirEntry, state } from './state'
10 import { deleteFiles } from './menu'
11 -import { Link } from 'react-router-dom'
11 +import { Link, LinkProps } from 'react-router-dom'
12 import { fileShow, getShowType } from './show'
13 import { alertDialog, promptDialog } from './dialog'
14 import { apiCall, useApi } from '@hfs/shared/api'
@@ -36,9 +36,9 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
36 state.props?.can_comment && { id: 'comment', label: t`Comment`, icon: 'comment', onClick: () => editComment(entry) },
37 ...addToMenu.map(x => {
38 if (x === 'open') {
39 - if (entry.cantOpen) return
39 + if (entry.cantOpen === DirEntry.FORBIDDEN) return
40 const open = { id: 'open', icon: 'play', label: t('file_open', "Open"), href: uri, target: isFolder || entry.web ? undefined : '_blank' }
41 - return !isFolder ? open : h(Link, { to: uri, onClick: () => close() }, hIcon(open.icon), open.label)
41 + return !isFolder ? open : h(LinkClosingDialog, { to: uri, reloadDocument: entry.web }, hIcon(open.icon), open.label)
42 }
43 if (x === 'delete')
44 return (state.props?.can_delete || entry.p?.includes('d')) && {
@@ -58,7 +58,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
58 }),
59 state.props?.can_delete && { id: 'rename', label: t`Rename`, icon: 'edit', onClick: () => rename(entry) },
60 state.props?.can_delete && { id: 'cut', label: t`Cut`, icon: 'cut', onClick: () => close(cut([entry])) },
61 - isFolder && !entry.web && { id: 'list', label: t`Get list`, href: uri + '?get=list&folders=*', icon: 'list' },
61 + isFolder && !entry.web && !entry.cantOpen && { id: 'list', label: t`Get list`, href: uri + '?get=list&folders=*', icon: 'list' },
62 ]
63 const folder = entry.n.slice(0, -entry.name.length - (entry.isFolder ? 2 : 1))
64 const props = [
@@ -165,4 +165,17 @@ async function editComment(entry: DirEntry) {
165
166 function updateEntry(entry: DirEntry, cb: (e: DirEntry) => unknown) {
167 cb(_.find(state.list, { n: entry.n })!)
168 +}
169 +
170 +export function LinkClosingDialog(props: LinkProps) {
171 + return h(Link, props.reloadDocument ? props : {
172 + ...props,
173 + to: '', // workaround to get dialogs and browser-history work correctly
174 + async onClick(ev) {
175 + ev.preventDefault()
176 + while (anyDialogOpen())
177 + await closeDialog()?.closed
178 + getHFS().navigate(props.to)
179 + }
180 + })
181 }
\ No newline at end of file
frontend/src/upload.ts
+2 -9
@@ -16,6 +16,7 @@ import { state, useSnapState } from './state'
16 import { Link } from 'react-router-dom'
17 import { t } from './i18n'
18 import { subscribeKey } from 'valtio/utils'
19 +import { LinkClosingDialog } from './fileMenu'
20
21 const renameEnabled = getHFS().dontOverwriteUploading
22
@@ -485,15 +486,7 @@ async function createFolder() {
486 await alertDialog(h(() =>
487 h(FlexV, {},
488 h('div', {}, t`Successfully created`),
488 - h(Link, {
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")),
489 + h(LinkClosingDialog, { to: uri + encodeURIComponent(name) + '/' }, t('enter_folder', "Enter the folder")),
490 )))
491 }
492 catch(e: any) {