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
9 changes: 4 additions & 5 deletions apps/next/src/components/ui/restaurant/dishes-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMemo } from "react";
import DishesInfo from "@/components/ui/dishes-info";
import { useRestaurantUIStore } from "@/context/useRestaurantUIStore";
import { useUserStore } from "@/context/useUserStore";
import { useShowSuitableDishesOnly } from "@/hooks/useShowSuitableDishesOnly";
import { getDietaryConflicts } from "@/utils/dietary";
import { toTitleCase } from "@/utils/funcs";
import { trpc } from "@/utils/trpc";
Expand All @@ -25,9 +26,7 @@ export function DishesView({
hallData,
}: DishesViewProps) {
const isCompactView = useRestaurantUIStore((s) => s.isCompactView);
const showPreferencesOnly = useRestaurantUIStore(
(s) => s.showPreferencesOnly,
);
const { showSuitableDishesOnly } = useShowSuitableDishesOnly();

const errorMessage =
error?.message ??
Expand All @@ -47,7 +46,7 @@ export function DishesView({
return new Map(
stations.map((station) => [
station.name,
showPreferencesOnly && allergies && preferences
showSuitableDishesOnly && allergies && preferences
? station.dishes.filter(
(dish) =>
getDietaryConflicts(
Expand All @@ -59,7 +58,7 @@ export function DishesView({
: station.dishes,
]),
);
}, [stations, showPreferencesOnly, preferences, allergies]);
}, [stations, showSuitableDishesOnly, preferences, allergies]);

return (
<div className="w-full">
Expand Down
28 changes: 1 addition & 27 deletions apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Station } from "@api/index";
import { GridView, Menu as MenuIcon } from "@mui/icons-material";
import { Button, Tab, Tabs } from "@mui/material";
import { Tab, Tabs } from "@mui/material";
import { useRestaurantUIStore } from "@/context/useRestaurantUIStore";
import { scrollToStation, toTitleCase } from "@/utils/funcs";

Expand All @@ -19,8 +18,6 @@ export function DesktopTabs({
}: DesktopTabsProps) {
const selectedStation = useRestaurantUIStore((s) => s.selectedStation);
const setSelectedStation = useRestaurantUIStore((s) => s.setSelectedStation);
const isCompactView = useRestaurantUIStore((s) => s.isCompactView);
const setIsCompactView = useRestaurantUIStore((s) => s.setIsCompactView);

if (!isDesktop) return null;

Expand Down Expand Up @@ -48,29 +45,6 @@ export function DesktopTabs({
))}
</Tabs>
)}
{/* Card / compact view toggles */}
<div className="flex justify-end mt-2">
<div id="tour-view-toggle-desktop" className="flex gap-2">
<Button
variant="outlined"
size="small"
type="button"
onClick={() => setIsCompactView(false)}
className={`!min-w-0 !w-10 !h-10 !p-0 !border-sky-700 dark:!border-blue-300 !normal-case ${!isCompactView ? "!bg-sky-700 !text-white hover:!bg-sky-700 dark:!bg-blue-300 dark:!text-gray-900" : "!bg-white !text-sky-700 hover:!bg-sky-50 dark:!bg-transparent dark:!text-white"}`}
>
<MenuIcon className="h-5 w-5" />
</Button>
<Button
variant="outlined"
size="small"
type="button"
onClick={() => setIsCompactView(true)}
className={`!min-w-0 !w-10 !h-10 !p-0 !border-sky-700 dark:!border-blue-300 !normal-case ${isCompactView ? "!bg-sky-700 !text-white hover:!bg-sky-700 dark:!bg-blue-300 dark:!text-gray-900" : "!bg-white !text-sky-700 hover:!bg-sky-50 dark:!bg-transparent dark:!text-white"}`}
>
<GridView className="h-5 w-5" />
</Button>
</div>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"use client";

import { ArrowDropDownRounded } from "@mui/icons-material";
import {
ArrowDropDownRounded,
GridView,
Menu as MenuIcon,
} from "@mui/icons-material";
import {
Button,
FormControl,
InputLabel,
MenuItem,
Select,
Tooltip,
Typography,
} from "@mui/material";
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns";
Expand All @@ -15,9 +19,7 @@ import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { useTheme } from "next-themes";
import type { CalendarRange } from "@/components/ui/toolbar";
import { useRestaurantUIStore } from "@/context/useRestaurantUIStore";
import { useUserStore } from "@/context/useUserStore";
import { formatOpenCloseTime, toTitleCase } from "@/utils/funcs";
import { cn } from "@/utils/tw";

interface RestaurantFiltersProps {
isDesktop: boolean;
Expand All @@ -38,40 +40,15 @@ export function RestaurantFilters({
calendarRange,
}: RestaurantFiltersProps) {
const { resolvedTheme } = useTheme();
const { userId } = useUserStore();

const selectedPeriod = useRestaurantUIStore((s) => s.selectedPeriod);
const setSelectedPeriod = useRestaurantUIStore((s) => s.setSelectedPeriod);
const isDatePickerOpen = useRestaurantUIStore((s) => s.isDatePickerOpen);
const setIsDatePickerOpen = useRestaurantUIStore(
(s) => s.setIsDatePickerOpen,
);
const showPreferencesOnly = useRestaurantUIStore(
(s) => s.showPreferencesOnly,
);
const setShowPreferencesOnly = useRestaurantUIStore(
(s) => s.setShowPreferencesOnly,
);

const ShowPrefsButton = (
<button
type="button"
onClick={() => setShowPreferencesOnly(!showPreferencesOnly)}
disabled={userId === null}
className={cn(
"h-[40px] rounded-md border text-sm font-medium transition-all duration-200 w-full",
userId === null &&
"text-black/50 border-sky-700/50 dark:text-white/40 dark:border-blue-300/40",
showPreferencesOnly &&
"bg-sky-700 text-white border-sky-700 shadow-md dark:bg-blue-300 dark:text-gray-900 dark:border-blue-300",
!showPreferencesOnly &&
userId &&
"bg-white text-sky-700 border-sky-700 hover:bg-sky-50 dark:bg-surface-scroll dark:text-blue-300 dark:border-blue-300 dark:hover:bg-zinc-700",
)}
>
Show Preferences Only
</button>
);
const isCompactView = useRestaurantUIStore((s) => s.isCompactView);
const setIsCompactView = useRestaurantUIStore((s) => s.setIsCompactView);

return (
// On desktop, items keep their natural widths on one line, and wrap and
Expand Down Expand Up @@ -174,6 +151,7 @@ export function RestaurantFilters({
<DatePicker
label="Select date"
value={selectedDate || null}
format={isDesktop ? "MM/dd/yyyy (EEE)" : undefined}
onChange={(newValue) => handleDateSelect(newValue || undefined)}
minDate={calendarRange.earliest}
maxDate={calendarRange.latest}
Expand Down Expand Up @@ -234,14 +212,29 @@ export function RestaurantFilters({
</div>
)}

<div className={isDesktop ? "w-[240px] grow" : "col-span-2"}>
{!userId && (
<Tooltip title="Log in to filter by preferences!" placement="top">
{ShowPrefsButton}
</Tooltip>
)}
{userId && ShowPrefsButton}
</div>
{/* Card / compact view toggles (desktop only; mobile has its own) */}
{isDesktop && (
<div id="tour-view-toggle-desktop" className="flex shrink-0 gap-2">
<Button
variant="outlined"
size="small"
type="button"
onClick={() => setIsCompactView(false)}
className={`!min-w-0 !w-10 !h-10 !p-0 !border-sky-700 dark:!border-blue-300 !normal-case ${!isCompactView ? "!bg-sky-700 !text-white hover:!bg-sky-700 dark:!bg-blue-300 dark:!text-gray-900" : "!bg-white !text-sky-700 hover:!bg-sky-50 dark:!bg-transparent dark:!text-white"}`}
>
<MenuIcon className="h-5 w-5" />
</Button>
<Button
variant="outlined"
size="small"
type="button"
onClick={() => setIsCompactView(true)}
className={`!min-w-0 !w-10 !h-10 !p-0 !border-sky-700 dark:!border-blue-300 !normal-case ${isCompactView ? "!bg-sky-700 !text-white hover:!bg-sky-700 dark:!bg-blue-300 dark:!text-gray-900" : "!bg-white !text-sky-700 hover:!bg-sky-50 dark:!bg-transparent dark:!text-white"}`}
>
<GridView className="h-5 w-5" />
</Button>
</div>
)}
</div>
);
}
18 changes: 16 additions & 2 deletions apps/next/src/components/ui/restaurant/restaurant-controls.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Station } from "@api/index";
import { MoreHoriz } from "@mui/icons-material";
import { IconButton, Typography } from "@mui/material";
import { Chip, IconButton, Typography } from "@mui/material";
import type { DishWithRating, Event } from "@peterplate/validators";
import { DiningHallStatus } from "@/components/ui/status";
import type { CalendarRange } from "@/components/ui/toolbar";
import { useRestaurantUIStore } from "@/context/useRestaurantUIStore";
import { useShowSuitableDishesOnly } from "@/hooks/useShowSuitableDishesOnly";
import { toTitleCase } from "@/utils/funcs";
import type { HallEnum, HallStatusEnum } from "@/utils/types";
import { DesktopTabs } from "./header/desktop-tabs";
Expand Down Expand Up @@ -51,6 +52,8 @@ export function RestaurantControls({
);
const selectedPeriod = useRestaurantUIStore((s) => s.selectedPeriod);
const showFilters = isDesktop || isFiltersExpanded;
const { showSuitableDishesOnly, setShowSuitableDishesOnly } =
useShowSuitableDishesOnly();

return (
// Sticky while scrolling
Expand Down Expand Up @@ -99,6 +102,17 @@ export function RestaurantControls({
id="tour-filters-mobile"
className="flex flex-col gap-3 w-full md:w-auto md:grow md:flex-row md:items-center md:justify-end"
>
{/* Shown even with mobile filters collapsed, since the setting persists */}
{showSuitableDishesOnly && (
<Chip
label="Suitable dishes only"
color="primary"
variant="outlined"
onDelete={() => setShowSuitableDishesOnly(false)}
className="self-start ml-3 md:self-auto md:ml-0"
/>
)}

{/* Meal & date selectors */}
{showFilters && (
<RestaurantFilters
Expand All @@ -125,7 +139,7 @@ export function RestaurantControls({
</div>
</div>

{/* Station tabs & card/compact view toggles (desktop only) */}
{/* Station tabs (desktop only) */}
<DesktopTabs
isDesktop={isDesktop}
isLoading={isLoading}
Expand Down
4 changes: 4 additions & 0 deletions apps/next/src/components/ui/restaurant/restaurant-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RestaurantControls } from "./restaurant-controls";
import RestaurantOnboarding from "./restaurant-onboarding";
import { Sidebar } from "./sidebar";
import RestaurantSpinner from "./spinner";
import { TodayEvents } from "./today-events";

interface RestaurantPageProps {
hall: HallEnum;
Expand Down Expand Up @@ -145,6 +146,9 @@ export function RestaurantPage({
hallEvents={hallEvents}
/>

{/* On desktop this sits in the sidebar instead */}
{!isDesktop && <TodayEvents events={hallEvents} />}

<div className="w-full">
<DishesView
stations={stations}
Expand Down
3 changes: 3 additions & 0 deletions apps/next/src/components/ui/restaurant/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
BRANDYWINE_MAP_LINK_URL,
HallEnum,
} from "@/utils/types";
import { TodayEvents } from "./today-events";

interface SidebarProps {
displayDate: Date;
Expand Down Expand Up @@ -64,6 +65,8 @@ export function Sidebar({
}: SidebarProps) {
return (
<div className="w-full md:basis-[325px] md:max-w-[325px] md:min-h-[740px]">
<TodayEvents events={hallEvents} />

{/* Hours of operation card */}
<SidebarSection title={"Hours of Operation"}>
<Typography variant="body2" fontWeight={600} className="mb-3 pb-2">
Expand Down
65 changes: 65 additions & 0 deletions apps/next/src/components/ui/restaurant/today-events.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Typography } from "@mui/material";
import type { Event } from "@peterplate/validators";
import { endOfDay, startOfDay } from "date-fns";

const formatTime = (date: Date) =>
date.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" });

/** Cards for this hall's events happening today, shown above the hours. */
export function TodayEvents({ events }: { events: Event[] }) {
const now = new Date();
const todayEvents = events
.map((event) => {
const start = new Date(event.start);
const end = new Date(event.end);
// Some events have no end time (it arrives as the Unix epoch)
return { event, start, end: end > start ? end : null };
})
.filter(
({ start, end }) =>
start <= endOfDay(now) && (end ?? start) >= startOfDay(now),
);

if (todayEvents.length === 0) return null;

return (
<div className="mb-4 space-y-2">
{todayEvents.map(({ event, start, end }) => (
<div
key={`${event.title}-${String(event.start)}`}
// Stays light in dark mode too, per the Figma
className="flex items-center gap-2 rounded-lg bg-pink-100 py-2.5 pl-1.5 pr-3 dark:bg-pink-200"
>
<span
aria-hidden="true"
className="w-1 self-stretch rounded-full bg-pink-600"
/>
<Typography
variant="body2"
component="span"
className="shrink-0 rounded-lg bg-pink-300 px-2.5 py-1.5 !text-gray-900"
>
Today
</Typography>
<Typography
variant="body2"
fontWeight={600}
className="grow !text-gray-900"
>
{event.title}
</Typography>
<div className="shrink-0 text-right">
<Typography variant="body2" className="!text-gray-900">
{formatTime(start)}
</Typography>
{end && (
<Typography variant="body2" className="!text-gray-900">
{formatTime(end)}
</Typography>
)}
</div>
</div>
))}
</div>
);
}
Loading
Loading