toast for rename, instead of dialog

Massimo Melina committed Sep 21, 2024 at 12:41 UTC 0db55a9fc1cb35d00b7dd8b3dda217301266a144
1 file changed +14 -16
frontend/src/fileMenu.ts
+14 -16
@@ -147,22 +147,20 @@ async function rename(entry: DirEntry) {
147 if (!dest) return
148 const { n, uri } = entry
149 await apiCall('rename', { uri, dest }, { modal: working })
150 - const renamingCurrentFolder = uri === location.pathname
151 - if (!renamingCurrentFolder) {
152 - // update state instead of re-getting the list
153 - const newN = n.replace(/(.*?)[^/]+(\/?)$/, (_,before,after) => before + dest + after)
154 - const newEntry = new DirEntry(newN, { key: n, ...entry }) // by keeping old key, we avoid unmounting the element, that's causing focus lost
155 - const i = _.findIndex(state.list, { n })
156 - state.list[i] = newEntry
157 - // update filteredList too
158 - const j = _.findIndex(state.filteredList, { n })
159 - if (j >= 0)
160 - state.filteredList![j] = newEntry
161 - }
162 - alertDialog(t`Operation successful`).then(() => {
163 - if (renamingCurrentFolder)
164 - getHFS().navigate(uri + '../' + pathEncode(dest) + '/')
165 - })
150 + const MSG = t`Operation successful`
151 + if (uri === location.pathname) //current folder
152 + return alertDialog(MSG).then(() =>
153 + getHFS().navigate(uri + '../' + pathEncode(dest) + '/') )
154 + // update state instead of re-getting the list
155 + const newN = n.replace(/(.*?)[^/]+(\/?)$/, (_,before,after) => before + dest + after)
156 + const newEntry = new DirEntry(newN, { key: n, ...entry }) // by keeping old key, we avoid unmounting the element, that's causing focus lost
157 + const i = _.findIndex(state.list, { n })
158 + state.list[i] = newEntry
159 + // update filteredList too
160 + const j = _.findIndex(state.filteredList, { n })
161 + if (j >= 0)
162 + state.filteredList![j] = newEntry
163 + toast(MSG, 'success')
164 }
165
166 async function editComment(entry: DirEntry) {