no "modal" while loading list

Massimo Melina committed Dec 30, 2021 at 12:26 UTC 62425c56bfb2caa7a3b9c67c400e261058e3d828
2 files changed +6 -5
frontend/src/api.ts
+5 -4
@@ -3,21 +3,22 @@ import { Falsy, working } from './misc'
3
4 const PREFIX = '/~/api/'
5
6 -export function apiCall(cmd: string, params?: object) : Promise<any> {
7 - const stop = working()
6 +interface ApiCallOptions { noModal?:true }
7 +export function apiCall(cmd: string, params?: object, options: ApiCallOptions={}) : Promise<any> {
8 + const stop = options.noModal ? undefined : working()
9 return fetch(PREFIX+cmd, {
10 method: 'POST',
11 headers: { 'content-type': 'application/json' },
12 body: params && JSON.stringify(params),
13 }).then(res => {
13 - stop()
14 + stop?.()
15 if (res.ok)
16 return res.json()
17 const msg = 'Failed API ' + cmd
18 console.warn(msg + (params ? ' ' + JSON.stringify(params) : ''))
19 throw new ApiError(res.status, msg)
20 }, err => {
20 - stop()
21 + stop?.()
22 throw err
23 })
24 }
frontend/src/useFetchList.ts
+1 -1
@@ -69,7 +69,7 @@ export default function useFetchList() {
69 let offset = 0
70 while (1) {
71 const limit = list.length ? 1000 : 100
72 - const res = await apiCall(API, { ...baseParams, offset, limit }).catch(e => e)
72 + const res = await apiCall(API, { ...baseParams, offset, limit }, { noModal:true }).catch(e => e)
73 || Error()
74 if (res instanceof Error)
75 return setError(res)