fix: a failed 'set comment' was not displaying any error
Massimo Melina committed
Aug 17, 2024 at 12:41 UTC
b48099e2f3b5cdedfbc21ac5afc9d5fbba04939d
1 file changed
+24
-24
frontend/src/fileMenu.ts
+24
-24
@@ -120,8 +120,13 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
120
async onClick(ev: MouseEvent) {
121
if (!entry.href)
122
ev.preventDefault()
123
- if (false !== await entry.onClick?.(ev))
124
- close()
123
+ try {
124
+ if (false !== await entry.onClick?.(ev))
125
+ close()
126
+ }
127
+ catch(e: any) {
128
+ alertDialog(e)
129
+ }
130
}
131
},
132
hIcon(entry.icon || 'file'),
@@ -139,29 +144,24 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (FileMe
144
async function rename(entry: DirEntry) {
145
const dest = await promptDialog(t`Name`, { value: entry.name, title: t`Rename` })
146
if (!dest) return
142
- try {
143
- const { n, uri } = entry
144
- await apiCall('rename', { uri, dest }, { modal: working })
145
- const renamingCurrentFolder = uri === location.pathname
146
- if (!renamingCurrentFolder) {
147
- // update state instead of re-getting the list
148
- const newN = n.replace(/(.*?)[^/]+(\/?)$/, (_,before,after) => before + dest + after)
149
- const newEntry = new DirEntry(newN, { key: n, ...entry }) // by keeping old key, we avoid unmounting the element, that's causing focus lost
150
- const i = _.findIndex(state.list, { n })
151
- state.list[i] = newEntry
152
- // update filteredList too
153
- const j = _.findIndex(state.filteredList, { n })
154
- if (j >= 0)
155
- state.filteredList![j] = newEntry
156
- }
157
- alertDialog(t`Operation successful`).then(() => {
158
- if (renamingCurrentFolder)
159
- getHFS().navigate(uri + '../' + pathEncode(dest) + '/')
160
- })
161
- }
162
- catch(e: any) {
163
- await alertDialog(e)
147
+ const { n, uri } = entry
148
+ await apiCall('rename', { uri, dest }, { modal: working })
149
+ const renamingCurrentFolder = uri === location.pathname
150
+ if (!renamingCurrentFolder) {
151
+ // update state instead of re-getting the list
152
+ const newN = n.replace(/(.*?)[^/]+(\/?)$/, (_,before,after) => before + dest + after)
153
+ const newEntry = new DirEntry(newN, { key: n, ...entry }) // by keeping old key, we avoid unmounting the element, that's causing focus lost
154
+ const i = _.findIndex(state.list, { n })
155
+ state.list[i] = newEntry
156
+ // update filteredList too
157
+ const j = _.findIndex(state.filteredList, { n })
158
+ if (j >= 0)
159
+ state.filteredList![j] = newEntry
160
}
161
+ alertDialog(t`Operation successful`).then(() => {
162
+ if (renamingCurrentFolder)
163
+ getHFS().navigate(uri + '../' + pathEncode(dest) + '/')
164
+ })
165
}
166
167
async function editComment(entry: DirEntry) {