Skip to content

Commit f428b29

Browse files
author
Gusted
authored
Show UI error after 3 seconds (darkreader#7845)
- When for some reason the UI couldn't be loaded, give users a error instead of given them false hope of infinite loading.
1 parent 11e17d4 commit f428b29

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/ui/popup/components/loader/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
import {m} from 'malevic';
22
import {getLocalMessage} from '../../../../utils/locales';
33
import {withState, useState} from 'malevic/state';
4+
import {getContext} from 'malevic/dom';
45

56
interface LoaderProps {
67
complete: boolean;
78
}
89

910
interface LoaderState {
1011
finished: boolean;
12+
errorOccured: boolean;
1113
}
1214

1315
function Loader({complete = false}: LoaderProps) {
14-
const {state, setState} = useState<LoaderState>({finished: false});
16+
const context = getContext();
17+
const {state, setState} = useState<LoaderState>({finished: false, errorOccured: false});
18+
19+
// Add a setTimeout for 3 seconds(in which the UI should be loaded already)
20+
// after the 3 seconds show a generic error message that the UI couldn't be loaded.
21+
if (!state.errorOccured) {
22+
setTimeout(() => {
23+
if (!complete) {
24+
setState({errorOccured: true});
25+
context.refresh();
26+
}
27+
}, 3000);
28+
}
29+
30+
const labelMessage = state.errorOccured ? "A unknown error has occured, the UI couldn't be loaded" : getLocalMessage('loading_please_wait');
31+
1532
return (
1633
<div
1734
class={{
@@ -21,7 +38,10 @@ function Loader({complete = false}: LoaderProps) {
2138
}}
2239
ontransitionend={() => setState({finished: true})}
2340
>
24-
<label class="loader__message">{getLocalMessage('loading_please_wait')}</label>
41+
<label class={{
42+
'loader__message': true,
43+
'loader__error': state.errorOccured,
44+
}}>{labelMessage}</label>
2545
</div>
2646
);
2747
}

src/ui/popup/components/loader/style.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
bottom: @popup-content-height + @popup-content-padding - @size-control-inner - @indent-small;
5252
}
5353

54+
&__error {
55+
font-size: @size-text-normal;
56+
}
57+
5458
&--complete &__message {
5559
color: fade(@color-heading, 0%);
5660
transition: color @loading-fade-duration ease-out;

0 commit comments

Comments
 (0)