flamenco/web/app/src/stores/api-query-count.js
Sybren A. Stüvel aa9837b5f0 First incarnation of the first-time wizard
This adds a `-wizard` CLI option to the Manager, which opens a webbrowser
and shows the First-Time Wizard to aid in configuration of Flamenco.

This is work in progress. The wizard is just one page, and doesn't save
anything yet to the configuration.
2022-07-14 11:17:03 +02:00

47 lines
1.2 KiB
JavaScript

import { defineStore } from "pinia";
import { ApiClient } from "@/manager-api";
import * as urls from '@/urls'
/**
* 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--;
});
}
}
export const apiClient = new CountingApiClient(urls.api());;