diff --git a/src/app/components/Header/index.tsx b/src/app/components/Header/index.tsx index 5b5561c..0c925a2 100644 --- a/src/app/components/Header/index.tsx +++ b/src/app/components/Header/index.tsx @@ -1,4 +1,5 @@ "use client"; +import { useClassStore } from "@/app/stores/classStore"; import { User } from "@/app/types/next-auth"; import { Autocomplete, @@ -15,9 +16,8 @@ import { NavbarItem, } from "@nextui-org/react"; import { useRouter } from "next/navigation"; +import { useEffect } from "react"; import { ThemeSwitcher } from "../ThemeSwitcher/ThemeSwitcher"; -import { useClassStore } from "@/app/stores/classStore"; -import { useEffect, useRef } from "react"; const getInitials = (name: string) => { if (!name) return ""; @@ -37,16 +37,14 @@ export const Header = ({ user }: { user?: User }) => { const router = useRouter(); const { classes, selectedClass, setSelectedClass, fetchClass } = useClassStore(); - const listClassesRef = useRef(null); const initials = user?.name ? getInitials(user.name) : ""; useEffect(() => { - fetchClass().then(() => { - if (selectedClass) setSelectedClass(classes[0]); + fetchClass().then((classesFetched) => { + setSelectedClass(classesFetched[0]); }); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [fetchClass, setSelectedClass]); return ( @@ -56,10 +54,10 @@ export const Header = ({ user }: { user?: User }) => { { console.log(selectedId); const inputSelectedClass = classes.find( diff --git a/src/app/components/Room/List.tsx b/src/app/components/Room/List.tsx index 475d32b..e00564f 100644 --- a/src/app/components/Room/List.tsx +++ b/src/app/components/Room/List.tsx @@ -4,7 +4,7 @@ import { RoomCard } from "./Card"; import { Room } from "./Room"; import { SkeletonRoomCard } from "./SkeletonRoomCard"; -export const RoomList = ({ rooms }: { rooms: Room[] }) => { +export const RoomList = ({ rooms }: { rooms: Room[] | null }) => { const scrollContainerRef = useRef(null); const handleWheel = (event: WheelEvent) => { @@ -47,12 +47,18 @@ export const RoomList = ({ rooms }: { rooms: Room[] }) => { }; }, []); + if (rooms?.length == 0) return ( +
+

No rooms found

+
+ ) + return (
    - {rooms.length > 0 ? ( + {rooms ? ( rooms.map((room) => (
  • void; - fetchClass: () => Promise; + fetchClass: () => Promise; setSelectedClass: (selectedClass: Class | undefined | null) => void; }; @@ -36,5 +36,6 @@ export const useClassStore = create()((set) => ({ fetchClass: async () => { const classResponse = await axiosInstance.get("/@me/class"); useClassStore.getState()._setClass(classResponse.data); + return classResponse.data; }, })); diff --git a/src/app/stores/roomStore.tsx b/src/app/stores/roomStore.tsx index a6e781a..6bc8a2c 100644 --- a/src/app/stores/roomStore.tsx +++ b/src/app/stores/roomStore.tsx @@ -5,9 +5,9 @@ import { axiosInstance } from "../lib/axios"; import { useClassStore } from "./classStore"; type RoomStoreState = { - future: Room[]; - actual: Room[]; - past: Room[]; + future: Room[] | null; + actual: Room[] | null; + past: Room[] | null; }; type RoomStoreActions = { @@ -18,9 +18,9 @@ type RoomStoreActions = { type RoomStore = RoomStoreState & RoomStoreActions; const defaultState: RoomStoreState = { - future: [], - actual: [], - past: [], + future: null, + actual: null, + past: null, }; export const useRoomStore = create()((set) => ({