From f54a8ccc0a57b332c4ae4af6e7d37af938c8581f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Sat, 4 Jan 2025 16:11:05 +0100 Subject: [PATCH] feat: refactor RoomCard and RoomList components, add SkeletonRoomCard for loading state --- src/app/components/Room/Card.tsx | 90 +++++++++++-------- src/app/components/Room/List.tsx | 42 ++++++--- src/app/components/Room/SkeletonRoomCard.tsx | 30 +++++++ src/app/globals.css | 16 ---- src/app/page.tsx | 95 +++----------------- 5 files changed, 122 insertions(+), 151 deletions(-) create mode 100644 src/app/components/Room/SkeletonRoomCard.tsx diff --git a/src/app/components/Room/Card.tsx b/src/app/components/Room/Card.tsx index 1863f78..ca41a1f 100644 --- a/src/app/components/Room/Card.tsx +++ b/src/app/components/Room/Card.tsx @@ -1,6 +1,6 @@ -"use client"; +'use client'; -import { parseDate, Time } from "@internationalized/date"; +import { parseDate, Time } from '@internationalized/date'; import { Button, @@ -9,66 +9,80 @@ import { CardHeader, DateInput, Divider, - TimeInput, -} from "@nextui-org/react"; -import { Room } from "./Room"; -import moment from "moment"; -import { useRouter } from "next/navigation"; + TimeInput +} from '@nextui-org/react'; +import { Room } from './Room'; +import moment from 'moment'; +import { useRouter } from 'next/navigation'; -export const RoomCard = ({ - id, - name, - date, - Times, - Presentator -}: Room) => { +export const RoomCard = ({ id, name, date, Times, Presentator }: Room) => { const router = useRouter(); return ( - + -
-

{name}

-

{Presentator.username}

+
+

{name}

+

+ {Presentator.username} +

- {Times.map((time) => ( -
- -
+ {Times.map(time => ( +
+ +
-
))} -
- -
+ {moment(date).dayOfYear() === moment().dayOfYear() && ( +
+ +
+ )} ); }; diff --git a/src/app/components/Room/List.tsx b/src/app/components/Room/List.tsx index 80e98e4..3154c3a 100644 --- a/src/app/components/Room/List.tsx +++ b/src/app/components/Room/List.tsx @@ -2,6 +2,7 @@ import { useEffect, useRef } from 'react'; import { RoomCard } from './Card'; import { Room } from './Room'; +import { SkeletonRoomCard } from './SkeletonRoomCard'; export const RoomList = ({ rooms }: { rooms: Room[] }) => { const scrollContainerRef = useRef(null); @@ -9,14 +10,17 @@ export const RoomList = ({ rooms }: { rooms: Room[] }) => { const handleWheel = (event: WheelEvent) => { if (event.deltaY === 0) return; if (event.ctrlKey || event.shiftKey || event.altKey) return; - + const scrollContainer = scrollContainerRef.current; if (!scrollContainer) return; const goLeft = event.deltaY < 0; - const isEnd = goLeft ? scrollContainer.scrollLeft === 0 : scrollContainer.scrollLeft + scrollContainer.clientWidth >= scrollContainer.scrollWidth; + const isEnd = goLeft + ? scrollContainer.scrollLeft === 0 + : scrollContainer.scrollLeft + scrollContainer.clientWidth >= + scrollContainer.scrollWidth; if (isEnd) return; - + event.preventDefault(); const scrollAmount = 10; @@ -49,17 +53,27 @@ export const RoomList = ({ rooms }: { rooms: Room[] }) => { className='overflow-x-auto scrollbar-hide rounded-xl bg-default-100' >
    - {rooms.map(room => ( -
  • - -
  • - ))} + {rooms?.length > 0 ? ( + rooms.map(room => ( +
  • + +
  • + )) + ) : ( + <> + {Array.from({ length: 5 }).map((_, i) => ( +
  • + +
  • + ))} + + )}
); diff --git a/src/app/components/Room/SkeletonRoomCard.tsx b/src/app/components/Room/SkeletonRoomCard.tsx new file mode 100644 index 0000000..6a815a1 --- /dev/null +++ b/src/app/components/Room/SkeletonRoomCard.tsx @@ -0,0 +1,30 @@ +"use client" +import { Card, Skeleton, Divider } from "@nextui-org/react" + +export const SkeletonRoomCard = () => { + return ( + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + - + +
+ +
+ + ) +} \ No newline at end of file diff --git a/src/app/globals.css b/src/app/globals.css index 145073e..b5c61c9 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -1,19 +1,3 @@ @tailwind base; @tailwind components; @tailwind utilities; - -@layer utilities { - .scrollbar::-webkit-scrollbar { - height: 10px; - } - - .scrollbar::-webkit-scrollbar-track { - border-radius: 100vh; - background: #5a5a5a54; - } - - .scrollbar::-webkit-scrollbar-thumb { - background: #414141; - border-radius: 100vh; - } -} diff --git a/src/app/page.tsx b/src/app/page.tsx index 28b7df9..96faa32 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -7,34 +7,6 @@ import { RoomList } from './components/Room/List'; import { Header } from './components/Header'; import { axiosInstance } from './lib/axios'; -const SkeletonCard = () => { - return ( - -
- -
- - -
- -
- - -
- -
- -
- - - - -
- -
- - ); -}; - const HomePage = () => { const [roomsLoading, setRoomsLoading] = useState(true); const [rooms, setRooms] = useState<{ @@ -80,61 +52,18 @@ const HomePage = () => { <>
- {roomsLoading ? ( - <> -
-

- Cours a venir -

-
- - - -
-
-
-

- Cours actuels -

-
- - - -
-
-
-

- Cours passés -

-
- - - -
-
- - ) : ( - <> -
-

- Cours a venir -

- -
-
-

- Cours actuels -

- -
-
-

- Cours passés -

- -
- - )} +
+

Upcoming

+ +
+
+

Current

+ +
+
+

Past

+ +
);