-
Notifications
You must be signed in to change notification settings - Fork 0
feat: rooms list sort by button #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e9e752f
b508b36
99716f8
bddd50c
1ab5401
591a321
f3c0aac
2855aa5
b6b919a
4c95952
19a69b1
6bf77c3
5b2e08c
e3db6f6
253db20
21edf0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { X } from "lucide-react"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| type FilterTagProps = { | ||
| label: string; | ||
| onRemove: () => void; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export function FilterTag({ label, onRemove, className }: FilterTagProps) { | ||
| return ( | ||
| <div | ||
| className={cn( | ||
| className, | ||
| "inline-flex items-center gap-1 rounded-md border border-stroke-default pl-4 pr-3 py-1.5 text-sm text-text-default transition-colors", | ||
| )} | ||
| > | ||
| {label} | ||
| <button | ||
| type="button" | ||
| onClick={onRemove} | ||
| className="text-text-subtle hover:text-text-default" | ||
| > | ||
| <X className="h-4 w-4" /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { ChevronDown } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| type OrderByDropdownProps = { | ||
| ascending: boolean; | ||
| setAscending: (ascending: boolean) => void; | ||
| }; | ||
|
|
||
| export function OrderByDropdown({ | ||
| ascending, | ||
| setAscending, | ||
| }: OrderByDropdownProps) { | ||
| const [open, setOpen] = useState(false); | ||
| const label = ascending ? "Ascending" : "Descending"; | ||
|
|
||
| return ( | ||
| <div | ||
| className="relative min-w-0 w-full max-w-31.5" | ||
| onBlur={(e) => { | ||
| if (!e.currentTarget.contains(e.relatedTarget)) setOpen(false); | ||
| }} | ||
| > | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| "flex w-full items-center justify-between gap-2 py-1 pl-2 pr-1 border border-stroke-subtle bg-bg-primary text-left", | ||
| open ? "rounded-t-md" : "rounded-md", | ||
| )} | ||
| onClick={() => setOpen((o) => !o)} | ||
| aria-expanded={open} | ||
| > | ||
| <span className="min-w-0 truncate text-md text-text-default"> | ||
| {label} | ||
| </span> | ||
| <ChevronDown | ||
| className={cn( | ||
| "h-4 w-4 shrink-0 transition-transform", | ||
| open && "rotate-180", | ||
| )} | ||
| /> | ||
| </button> | ||
|
|
||
| {open && ( | ||
| <div className="absolute left-0 top-full z-10 w-full rounded-b-md border border-t-0 border-stroke-subtle bg-bg-primary shadow-md"> | ||
| <button | ||
| type="button" | ||
| className="block w-full pl-2 pr-1 py-1 text-left text-md text-text-default hover:bg-bg-selected" | ||
| onClick={() => { | ||
| setAscending(!ascending); | ||
| setOpen(false); | ||
| }} | ||
| > | ||
| {ascending ? "Descending" : "Ascending"} | ||
| </button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,41 @@ | ||
| 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>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ILoRoomWithOptionalGuestBooking
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a fundies reference? 😭 |
||
| 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; | ||
| }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we wanna do this sorting on the backend at the query level, we can merge this in for now but let's add that as a field to our request body as an optional sorting in a different pr |
||
|
|
||
| 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"> | ||
| {rooms.map((room) => ( | ||
| {sortedRooms.map((room) => ( | ||
| <li key={room.room_number} className="min-w-0"> | ||
| <RoomCard | ||
| room={room} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { OrderByDropdown } from "./OrderByDropdown"; | ||
|
|
||
| type SortByContainerProps = { | ||
| ascending: boolean; | ||
| setAscending: (ascending: boolean) => void; | ||
| }; | ||
|
|
||
| export function SortByContainer({ | ||
| ascending, | ||
| setAscending, | ||
| }: SortByContainerProps) { | ||
| return ( | ||
| <span className="text-sm text-text-subtle flex items-center gap-1 pt-6"> | ||
| Sort by:{" "} | ||
| <OrderByDropdown ascending={ascending} setAscending={setAscending} /> | ||
| </span> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good but def shadcn for future cases, you're the goat for cooking up from scratch though