File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { m } from 'malevic' ;
22import { getLocalMessage } from '../../../../utils/locales' ;
33import { withState , useState } from 'malevic/state' ;
4+ import { getContext } from 'malevic/dom' ;
45
56interface LoaderProps {
67 complete : boolean ;
78}
89
910interface LoaderState {
1011 finished : boolean ;
12+ errorOccured : boolean ;
1113}
1214
1315function 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}
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments