diff --git a/ts/Manager/App.tsx b/ts/Manager/App.tsx index 514485a..aee0041 100644 --- a/ts/Manager/App.tsx +++ b/ts/Manager/App.tsx @@ -35,7 +35,7 @@ type Props = { } const App: React.FC = () => { - const [areRoomsLoaded, setRoomsLoaded] = useState(false); + const [isLoaded, setLoaded] = useState(false); const [error, setError] = useState(''); const [restriction, setRestriction] = useState(); const [rooms, setRooms] = useState([]); @@ -45,22 +45,35 @@ const App: React.FC = () => { const rows = rooms.sort(sortRooms(orderBy, sortOrder)).map(room => ); useEffect(() => { - api.getRestriction().then(restriction => { + Promise.all([ + loadRestriction(), + loadRooms(), + ]).catch(() => { + setError(t('bbb', 'Server error')); + }).then(() => { + setLoaded(true); + }); + }, []); + + function loadRestriction() { + return api.getRestriction().then(restriction => { setRestriction(restriction); }).catch(err => { console.warn('Could not load restriction', err); - }); - api.getRooms().then(rooms => { + throw err; + }); + } + + function loadRooms() { + return api.getRooms().then(rooms => { setRooms(rooms); }).catch((err) => { console.warn('Could not load rooms', err); - setError(t('bbb', 'Server error')); - }).then(() => { - setRoomsLoaded(true); + throw err; }); - }, []); + } function onOrderBy(key: SortKey) { if (orderBy === key) { @@ -143,7 +156,7 @@ const App: React.FC = () => { {error && <> {error}} - {!areRoomsLoaded && } + {!isLoaded && } {(maxRooms > rows.length || maxRooms < 0) ?