mirror of https://github.com/sualko/cloud_bbb
fix: unify error handling for room and restriction
parent
4d9a7b8a79
commit
b5f03b5981
|
@ -35,7 +35,7 @@ type Props = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const App: React.FC<Props> = () => {
|
const App: React.FC<Props> = () => {
|
||||||
const [areRoomsLoaded, setRoomsLoaded] = useState(false);
|
const [isLoaded, setLoaded] = useState(false);
|
||||||
const [error, setError] = useState<string>('');
|
const [error, setError] = useState<string>('');
|
||||||
const [restriction, setRestriction] = useState<Restriction>();
|
const [restriction, setRestriction] = useState<Restriction>();
|
||||||
const [rooms, setRooms] = useState<Room[]>([]);
|
const [rooms, setRooms] = useState<Room[]>([]);
|
||||||
|
@ -45,22 +45,35 @@ const App: React.FC<Props> = () => {
|
||||||
const rows = rooms.sort(sortRooms(orderBy, sortOrder)).map(room => <RoomRow room={room} restriction={restriction} key={room.id} updateRoom={updateRoom} deleteRoom={deleteRoom} />);
|
const rows = rooms.sort(sortRooms(orderBy, sortOrder)).map(room => <RoomRow room={room} restriction={restriction} key={room.id} updateRoom={updateRoom} deleteRoom={deleteRoom} />);
|
||||||
|
|
||||||
useEffect(() => {
|
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);
|
setRestriction(restriction);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.warn('Could not load restriction', err);
|
console.warn('Could not load restriction', err);
|
||||||
});
|
|
||||||
|
|
||||||
api.getRooms().then(rooms => {
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadRooms() {
|
||||||
|
return api.getRooms().then(rooms => {
|
||||||
setRooms(rooms);
|
setRooms(rooms);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.warn('Could not load rooms', err);
|
console.warn('Could not load rooms', err);
|
||||||
|
|
||||||
setError(t('bbb', 'Server error'));
|
throw err;
|
||||||
}).then(() => {
|
|
||||||
setRoomsLoaded(true);
|
|
||||||
});
|
});
|
||||||
}, []);
|
}
|
||||||
|
|
||||||
function onOrderBy(key: SortKey) {
|
function onOrderBy(key: SortKey) {
|
||||||
if (orderBy === key) {
|
if (orderBy === key) {
|
||||||
|
@ -143,7 +156,7 @@ const App: React.FC<Props> = () => {
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={3}>
|
<td colSpan={3}>
|
||||||
{error && <><span className="icon icon-error icon-visible"></span> {error}</>}
|
{error && <><span className="icon icon-error icon-visible"></span> {error}</>}
|
||||||
{!areRoomsLoaded && <span className="icon icon-loading-small icon-visible"></span>}
|
{!isLoaded && <span className="icon icon-loading-small icon-visible"></span>}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{(maxRooms > rows.length || maxRooms < 0) ?
|
{(maxRooms > rows.length || maxRooms < 0) ?
|
||||||
|
|
Loading…
Reference in New Issue