plugins: apiCall is no longer displaying modal screen by default

Massimo Melina committed Sep 27, 2023 at 12:49 UTC 54f046ff26abe23a367722b1fe62f72e091d301d
6 files changed +12 -12
frontend/src/UserPanel.ts
+3 -3
@@ -7,7 +7,7 @@ import { createVerifierAndSalt, SRPParameters, SRPRoutines } from 'tssrp6a'
7 import { apiCall } from '@hfs/shared/api'
8 import { logout } from './login'
9 import { MenuButton } from './menu'
10 -import { hIcon } from './misc'
10 +import { hIcon, working } from './misc'
11 import { t } from './i18n'
12
13 export default function showUserPanel() {
@@ -34,10 +34,10 @@ export default function showUserPanel() {
34 const srp6aNimbusRoutines = new SRPRoutines(new SRPParameters())
35 const res = await createVerifierAndSalt(srp6aNimbusRoutines, snap.username, pwd)
36 try {
37 - await apiCall('change_srp', { salt: String(res.s), verifier: String(res.v) }).catch(e => {
37 + await apiCall('change_srp', { salt: String(res.s), verifier: String(res.v) }, { modal: working }).catch(e => {
38 if (e.code !== 406) // 406 = server was configured to support clear text authentication
39 throw e
40 - return apiCall('change_password', { newPassword: pwd }) // unencrypted version
40 + return apiCall('change_password', { newPassword: pwd }, { modal: working }) // unencrypted version
41 })
42 return alertDialog(t('password_changed', "Password changed"))
43 }
frontend/src/fileMenu.ts
+3 -3
@@ -1,5 +1,5 @@
1 import { t, useI18N } from './i18n'
2 -import { dontBotherWithKeys, formatBytes, hfsEvent, hIcon, newDialog, prefix, with_ } from './misc'
2 +import { dontBotherWithKeys, formatBytes, hfsEvent, hIcon, newDialog, prefix, with_, working } from './misc'
3 import { createElement as h, Fragment, isValidElement, MouseEvent, ReactNode } from 'react'
4 import _ from 'lodash'
5 import { getEntryIcon, MISSING_PERM } from './BrowseFiles'
@@ -113,7 +113,7 @@ async function rename(entry: DirEntry) {
113 if (!dest) return
114 try {
115 const { n, uri } = entry
116 - await apiCall('rename', { uri, dest })
116 + await apiCall('rename', { uri, dest }, { modal: working })
117 const isCurrentFolder = uri === location.pathname
118 if (!isCurrentFolder) {
119 // update state instead of re-getting the list
@@ -138,7 +138,7 @@ async function rename(entry: DirEntry) {
138 async function editComment(entry: DirEntry) {
139 const res = await inputComment(entry.name, entry.comment)
140 if (res === null) return
141 - await apiCall('comment', { uri: entry.uri, comment: res })
141 + await apiCall('comment', { uri: entry.uri, comment: res }, { modal: working })
142 updateEntry(entry, e => e.comment = res)
143 alertDialog(t`Operation successful`)
144 }
frontend/src/login.ts
+1 -1
@@ -31,7 +31,7 @@ const sessionRefresher = makeSessionRefresher(state)
31 sessionRefresher(getHFS().session)
32
33 export function logout(){
34 - return apiCall('logout').catch(res => {
34 + return apiCall('logout', {}, { modal: working }).catch(res => {
35 if (res.code !== 401) // we expect 401
36 throw res
37 state.username = ''
frontend/src/menu.ts
+3 -1
@@ -3,7 +3,7 @@
3 import { state, useSnapState } from './state'
4 import { ComponentPropsWithoutRef, createElement as h, Fragment, useEffect, useMemo, useState } from 'react'
5 import { alertDialog, confirmDialog, ConfirmOptions, promptDialog } from './dialog'
6 -import { err2msg, ErrorMsg, hIcon, onlyTruthy, prefix, useStateMounted } from './misc'
6 +import { err2msg, ErrorMsg, hIcon, onlyTruthy, prefix, useStateMounted, working } from './misc'
7 import { loginDialog } from './login'
8 import { showOptions } from './options'
9 import showUserPanel from './UserPanel'
@@ -207,9 +207,11 @@ export async function deleteFiles(uris: string[]) {
207 }
208 if (!await confirmDialog(t('delete_confirm', {n}, "Delete {n,plural, one{# item} other{# items}}?")))
209 return false
210 + const stop = working()
211 const errors = onlyTruthy(await Promise.all(uris.map(uri =>
212 apiCall('delete', { uri }).then(() => null, err => ({ uri, err }))
213 )))
214 + stop()
215 reloadList()
216 const e = errors.length
217 alertDialog(h(Fragment, {},
frontend/src/misc.ts
-2
@@ -84,5 +84,3 @@ Object.assign(getHFS(), {
84 }
85 }
86 })
87 -
88 -setDefaultApiCallOptions({ modal: working })
frontend/src/upload.ts
+2 -2
@@ -2,7 +2,7 @@
2
3 import { createElement as h, DragEvent, Fragment, useMemo, CSSProperties } from 'react'
4 import { Checkbox, Flex, FlexV, iconBtn } from './components'
5 -import { basename, closeDialog, formatBytes, formatPerc, hIcon, isMobile, newDialog, prefix, selectFiles } from './misc'
5 +import { basename, closeDialog, formatBytes, formatPerc, hIcon, isMobile, newDialog, prefix, selectFiles, working } from './misc'
6 import _ from 'lodash'
7 import { proxy, ref, subscribe, useSnapshot } from 'valtio'
8 import { alertDialog, confirmDialog, promptDialog } from './dialog'
@@ -411,7 +411,7 @@ async function createFolder() {
411 if (!name) return
412 const uri = location.pathname
413 try {
414 - await apiCall('create_folder', { uri, name })
414 + await apiCall('create_folder', { uri, name }, { modal: working })
415 reloadList()
416 return alertDialog(h(() =>
417 h(FlexV, {},