flamenco/web/app/src/stores/api-query-count.js
Sybren A. Stüvel 819767ea1a Webapp: tweak the .editorconfig and .prettierrc files + re-format
Try to get the `.editorconfig` and `.prettierrc` files as close as possible
to the formatting that was used in Flamenco. Because these files weren't
here during most of Flamenco's development so far, having them caused quite
a few changes in the webapp files.

No functional changes intended.
2023-09-11 17:22:18 +02:00

68 lines
1.2 KiB
JavaScript

import { defineStore } from 'pinia';
import { ApiClient } from '@/manager-api';
/**
* Keep track of running API queries.
*/
export const useAPIQueryCount = defineStore('apiQueryCount', {
state: () => ({
/**
* Number of running queries.
*/
num: 0,
}),
actions: {
/**
* Track this promise, counting it as a query for the spinner.
* @param {Promise} promise
*/
async track(promise) {
this.num++;
try {
return await promise;
} finally {
this.num--;
}
},
},
});
export class CountingApiClient extends ApiClient {
callApi(
path,
httpMethod,
pathParams,
queryParams,
headerParams,
formParams,
bodyParam,
authNames,
contentTypes,
accepts,
returnType,
apiBasePath
) {
const apiQueryCount = useAPIQueryCount();
apiQueryCount.num++;
return super
.callApi(
path,
httpMethod,
pathParams,
queryParams,
headerParams,
formParams,
bodyParam,
authNames,
contentTypes,
accepts,
returnType,
apiBasePath
)
.finally(() => {
apiQueryCount.num--;
});
}
}