fixed loading error handling

This commit is contained in:
Integral Team 2019-09-11 15:16:44 +07:00
parent dd2861fe5c
commit 0bfb1dee90
4 changed files with 79 additions and 26 deletions

View file

@ -1,4 +1,5 @@
import { history } from '$redux/store';
import {API_RETRY_INTERVAL} from "$constants/api";
interface IUrlData {
path: string,
@ -34,12 +35,24 @@ export const parseQuery = (queryString: string) => {
return params;
};
export const pushLoaderState = state => {
export const pushLoaderState = (state: number) => {
document.getElementById('loader-bar').style.width = `${state}%`;
};
export const countDownToRefresh = (left: number = API_RETRY_INTERVAL): void => {
console.log('countdown');
if (left <= 0) return document.location.reload();
document.getElementById('loader-bar').style.width = `${(left / API_RETRY_INTERVAL) * 100}%`;
setTimeout(() => countDownToRefresh(left - 0.25), 1000);
};
export const pushNetworkInitError = () => {
document.getElementById('loader-bar').classList.add('is_failed');
document.getElementById('loader-bar').style.width = '100%';
document.getElementById('loader-error').style.opacity = String(1);
countDownToRefresh();
};
export const copyToClipboard = str => {
@ -52,4 +65,4 @@ export const copyToClipboard = str => {
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
};