import nprogress from 'nprogress';
nprogress.configure({
trickleSpeed: 100,
template: '
',
});
// Only the last caller should be able to call nprogress.done()
let lastCalledBy: symbol;
export async function withLoadProgress(loadTarget: Promise): Promise {
const callIdentifier = Symbol();
lastCalledBy = callIdentifier;
// Cancel any existing progress and restart
nprogress.done();
nprogress.start();
return loadTarget.finally(() => {
if (lastCalledBy === callIdentifier) {
nprogress.done();
nprogress.remove();
}
});
}