refactor: simplify conditional check for class response before fetching rooms
This commit is contained in:
parent
e6d8a9ae9e
commit
c45579221b
@ -48,17 +48,17 @@ const HomePage = () => {
|
||||
useEffect(() => {
|
||||
axiosInstance.get<{ id: string, name: string, createdAt: string }[]>("/@me/class")
|
||||
.then((classResponse) => {
|
||||
classResponse.data.length > 0 &&
|
||||
axiosInstance.get<Room[]>(`/@me/class/${classResponse.data[0].id}/rooms`)
|
||||
.then(classes => {
|
||||
// Filter rooms by date, get future, actual and past rooms
|
||||
const future = classes.data.filter(room => moment(room.date).isAfter(moment(), "day"));
|
||||
const actual = classes.data.filter(room => moment(room.date).isSame(moment(), "day"));
|
||||
const past = classes.data.filter(room => moment(room.date).isBefore(moment()));
|
||||
if (classResponse.data.length)
|
||||
axiosInstance.get<Room[]>(`/@me/class/${classResponse.data[0].id}/rooms`)
|
||||
.then(classes => {
|
||||
// Filter rooms by date, get future, actual and past rooms
|
||||
const future = classes.data.filter(room => moment(room.date).isAfter(moment(), "day"));
|
||||
const actual = classes.data.filter(room => moment(room.date).isSame(moment(), "day"));
|
||||
const past = classes.data.filter(room => moment(room.date).isBefore(moment()));
|
||||
|
||||
setRooms({ future, actual, past });
|
||||
setRoomsLoading(false);
|
||||
});
|
||||
setRooms({ future, actual, past });
|
||||
setRoomsLoading(false);
|
||||
});
|
||||
})
|
||||
|
||||
}, []);
|
||||
|
Loading…
Reference in New Issue
Block a user