From c45579221b7b378188f6c134ed89838a7ecf2465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Thu, 2 Jan 2025 19:30:50 +0100 Subject: [PATCH] refactor: simplify conditional check for class response before fetching rooms --- src/app/page.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index fe48a3f..2ee7112 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -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(`/@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(`/@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); + }); }) }, []);