-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomsList.tsx
More file actions
51 lines (47 loc) · 1.44 KB
/
RoomsList.tsx
File metadata and controls
51 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { useMemo } from "react";
import type { RoomWithOptionalGuestBooking } from "@shared";
import { RoomCard } from "@/components/rooms/RoomCard";
type RoomsListProps = {
rooms: Array<RoomWithOptionalGuestBooking>;
onRoomSelect: (room: RoomWithOptionalGuestBooking) => void;
ascending: boolean;
selectedRoomNumber?: number | null;
};
function sortRoomsByRoomNumber(
rooms: Array<RoomWithOptionalGuestBooking>,
ascending: boolean,
): Array<RoomWithOptionalGuestBooking> {
return [...rooms].sort((a, b) => {
const an = a.room_number ?? 0;
const bn = b.room_number ?? 0;
return ascending ? an - bn : bn - an;
});
}
export function RoomsList({
rooms,
onRoomSelect,
ascending,
selectedRoomNumber = null,
}: RoomsListProps) {
const sortedRooms = useMemo(
() => sortRoomsByRoomNumber(rooms, ascending),
[rooms, ascending],
);
return (
<section className="flex-1 min-h-0 flex flex-col overflow-hidden py-4">
<nav className="flex-1 min-h-0">
<ul className="flex flex-col gap-4 h-full overflow-y-auto min-h-0 [&::-webkit-scrollbar]:hidden">
{sortedRooms.map((room) => (
<li key={room.room_number} className="min-w-0">
<RoomCard
room={room}
isSelected={selectedRoomNumber === room.room_number}
onClick={() => onRoomSelect(room)}
/>
</li>
))}
</ul>
</nav>
</section>
);
}