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

@ -12,3 +12,5 @@ export const API: { [x: string]: string } = {
MODIFY_ROUTE: `${CLIENT.API_ADDR}/route/modify`,
SET_STARRED: `${CLIENT.API_ADDR}/route/star`,
};
export const API_RETRY_INTERVAL = 10;

View file

@ -4,7 +4,7 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=0.95">
<meta name="theme-color" content="#5A3D6D">
<link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700&amp;subset=cyrillic" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500,700&amp;subset=cyrillic" rel="stylesheet" />
<title>Редактор маршрутов</title>
<link rel="shortcut icon" href="/favicon.png" type="image/png">
@ -13,7 +13,7 @@
<style>
#loader {
position: fixed;
background: #ecf0ff;
background: #333333;
left: 0;
top: 0;
width: 100%;
@ -23,7 +23,7 @@
display: flex;
align-items: center;
justify-content: center;
color: #666666;
color: #ffffff;
font-family: sans-serif;
font-size: 16px;
flex-direction: column;
@ -38,31 +38,58 @@
#loader-current {
text-transform: uppercase;
font-size: 14px;
font-size: 20px;
text-align: center;
font-weight: 600;
display: none;
}
#loader-container {
width: 240px;
max-width: 320px;
height: 100px;
width: 100%;
position: relative;
}
#loader-progress {
margin-top: 10px;
width: 100%;
height: 8px;
background: rgba(0, 0, 0, 0.05);
height: 24px;
background: rgba(0, 0, 0, 0.2);
box-shadow: inset rgba(0,0,0,0.1) 0 0 0 1px;
border-radius: 4px;
border-radius: 12px;
box-sizing: border-box;
padding: 4px;
display: flex;
align-items: center;
justify-content: center;
}
#loader-bar {
// background: linear-gradient(90deg, #845b9e, #54faff);
background: #7c5f9e;
/*background: linear-gradient(90deg, #845b9e, #54faff);*/
background: linear-gradient(130deg,#46bff3, #7833ff);
/* background: #7c5f9e; */
width: 10%;
height: 100%;
border-radius: 4px;
border-radius: 8px;
transition: width 500ms;
animation: blink 0.3s infinite alternate;
animation: blink 0.3s infinite alternate linear;
min-width: 16px;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
}
#loader-bar.is_failed {
background: linear-gradient(130deg, #f3572b, #a51519);
}
#loader-bar.is_failed::after {
content: 'перезагрузка';
font-size: 12px;
position: relative;
top: 1px;
opacity: 0.5;
}
body {
@ -79,16 +106,25 @@
#loader-error {
color: white;
background: #ff3344;
border-radius: 3px;
padding: 5px 10px 10px 10px;
/* background-color: white; */
border-radius: 12px;
padding: 10px;
margin-top: 20px;
opacity: 0;
font-size: 14px;
font-size: 13px;
text-align: center;
box-shadow: inset white 0 0 0 1px;
text-transform: uppercase;
position: absolute;
bottom: 100%;
left: 0;
width: 100%;
box-sizing: border-box;
transform: translate(0, -16px);
}
#loader-error h4 {
margin: 5px 0;
margin: 0 0 5px 0;
}
</style>
</head>
@ -98,13 +134,15 @@
<section id="loader">
<div id="loader-container">
<div id="loader-current">ЗАГРУЗКА</div>
<div id="loader-error">
<h4>Хранилище недоступно</h4>
<div>Мы работаем над решением проблемы</div>
</div>
<div id="loader-progress">
<div id="loader-bar"></div>
</div>
<div id="loader-error">
<h4>Хранилище недоступно.</h4>
Повторите попытку позже.
</div>
</div>
</section>
<section id="index"></section>

View file

@ -218,7 +218,7 @@ function* authCheckSaga() {
if (user) {
yield put(setUser(user));
pushLoaderState(' ...готово');
pushLoaderState(99);
return yield call(mapInitSaga);
}
@ -231,7 +231,7 @@ function* authCheckSaga() {
if (user) {
yield put(setUser(user));
pushLoaderState(' ...готово');
pushLoaderState(99);
return yield call(mapInitSaga);
} else if (!ready) {

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);
}
};