Skip to content

Commit

Permalink
refactor(frontend): extract loading animation logic into a separate f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
logonoff committed Nov 7, 2024
1 parent a4feac1 commit ba882a7
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions frontend/src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,29 @@ instance.interceptors.request.use((config) => {
return config;
});

const loadingAnimation = () => {
setTimeout(() => {
if (loading === 0) {
const loadingBackdrop = document.getElementById('axios-loading-backdrop');
if (loadingBackdrop) {
loadingBackdrop.style.display = 'none';
}
}
}, 500);
};

instance.interceptors.response.use(
(response) => {
if ('skipLoadingWheel' in response.config && response.config.skipLoadingWheel === true) {
return response;
}
loading -= 1;
setTimeout(() => {
if (loading === 0) {
const loadingBackdrop = document.getElementById('axios-loading-backdrop');
if (loadingBackdrop) {
loadingBackdrop.style.display = 'none';
}
}
}, 500);
loadingAnimation();
return response;
},
(error) => {
loading -= 1;
setTimeout(() => {
if (loading === 0) {
const loadingBackdrop = document.getElementById('axios-loading-backdrop');
if (loadingBackdrop) {
loadingBackdrop.style.display = 'none';
}
}
}, 500);
loadingAnimation();
return Promise.reject(error);
},
);
Expand Down

0 comments on commit ba882a7

Please sign in to comment.