Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ export function DesktopTabs({
scrollToStation(val);
setSelectedStation(val);
}}
className="flex w-full overflow-x-auto no-scrollbar !bg-primary-accent/20 dark:!bg-[var(--desktop-tabs-bg)] !rounded-lg !p-2 [&_.MuiTabs-flexContainer]:justify-between [&_.MuiTabs-flexContainer]:gap-2 [&_.MuiTabs-indicator]:hidden"
variant="scrollable"
scrollButtons={false}
scrollButtons="auto"
slotProps={{
startScrollButtonIcon: { fontSize: "medium" },
endScrollButtonIcon: { fontSize: "medium" },
}}
className="h-[52px] w-full rounded-lg bg-primary-accent/20 px-2 dark:bg-[var(--desktop-tabs-bg)] [&_.MuiTabs-flexContainer]:h-full [&_.MuiTabs-flexContainer]:justify-between [&_.MuiTabs-flexContainer]:gap-10 [&_.MuiTabs-indicator]:!bg-sky-700 dark:[&_.MuiTabs-indicator]:!bg-blue-300 [&_.MuiTabScrollButton-root]:!text-slate-600 dark:[&_.MuiTabScrollButton-root]:!text-slate-300 [&_.MuiTabScrollButton-root.Mui-disabled]:!opacity-30"
>
{stations.map((station) => (
<Tab
key={station.name}
value={station.name.toLowerCase()}
label={toTitleCase(station.name)}
className="!rounded !border !border-transparent !bg-transparent !px-4 !py-1.5 !text-sm !font-medium !text-black dark:!text-white !normal-case !min-h-0 aria-selected:!bg-white dark:aria-selected:!bg-white aria-selected:!text-slate-900 dark:aria-selected:!text-gray-900 aria-selected:!border-slate-200 dark:aria-selected:!border-slate-200 aria-selected:!shadow-sm"
className="!whitespace-nowrap !max-w-none !px-4!text-base !font-medium !text-black dark:!text-white !normal-case !min-h-0 aria-selected:!text-sky-700 dark:aria-selected:!text-blue-300"
/>
))}
</Tabs>
Expand Down
40 changes: 39 additions & 1 deletion apps/next/src/hooks/useRestaurantPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ import { trpc } from "@/utils/trpc";
import type { HallStatusEnum } from "@/utils/types";
import { HallEnum } from "@/utils/types";

const normalizeStationName = (name: string) =>
name.toLowerCase().replace(/[^a-z0-9]/g, "");

/**
* Stations shown first, in this order. A station matches the first keyword its
* normalized name contains (CampusDish names like "Ember/Grill" or "The Farm
* Stand/ Deli" are matched by substring). Unlisted stations follow, in API order.
*/
const STATION_PRIORITY: Record<"anteatery" | "brandywine", string[]> = {
brandywine: [
"Grubb",
"Crossroads",
"Twisted Root",
"Ember",
"Hearth",
"Farm Stand",
].map(normalizeStationName),
anteatery: [
"Fire And Ice",
"Noodle Bar",
"Twisted Root",
"Grill",
"Oven",
].map(normalizeStationName),
};

function stationRank(name: string, priority: string[]): number {
const n = normalizeStationName(name);
const i = priority.findIndex((key) => n.includes(key));
return i === -1 ? priority.length : i;
}

/**
* Returns the current meal period key for a given date by checking which period
* window the date falls within. Falls back to the first period if none match.
Expand Down Expand Up @@ -182,7 +214,13 @@ export function useRestaurantPage(hall: HallEnum): UseRestaurantPageResult {
[hallData, selectedPeriod],
);

const stations: Station[] = currentMenu?.stations ?? [];
// Order stations by the per-restaurant priority list (stable sort).
const stations: Station[] = useMemo(() => {
const priority = STATION_PRIORITY[restaurantId];
return [...(currentMenu?.stations ?? [])].sort(
(x, y) => stationRank(x.name, priority) - stationRank(y.name, priority),
);
}, [currentMenu, restaurantId]);

// --- Auto-select station ---
useEffect(() => {
Expand Down
Loading