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
75 changes: 45 additions & 30 deletions apps/next/src/app/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import Button from "@mui/material/Button";
import type { SelectChangeEvent } from "@mui/material/Select";
import type { Event } from "@peterplate/validators";
import { addMonths, subMonths } from "date-fns";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import CalendarView from "@/components/ui/calendar-view";
import EventCard from "@/components/ui/card/event-card";
import EventsOnboarding from "@/components/ui/events-onboarding";
import MobileEventsView from "@/components/ui/mobile-events-view";
import EventCardSkeleton from "@/components/ui/skeleton/event-card-skeleton";
import { useTourStore } from "@/context/useTourStore";
import { useMediaQuery } from "@/hooks/useMediaQuery";
import {
classifyEvent,
Expand Down Expand Up @@ -100,6 +102,13 @@ const Events = () => {

const isDesktop = useMediaQuery("(min-width: 768px)");

useEffect(() => {
return () => {
const { activeTour, stop } = useTourStore.getState();
if (activeTour === "events") stop();
};
}, []);

const handleLocationChange = (
event: SelectChangeEvent<"both" | "anteatery" | "brandywine">,
) => {
Expand Down Expand Up @@ -166,35 +175,37 @@ const Events = () => {
View:
</span>

{/* Grid View Button */}
<Button
onClick={() => setViewMode("grid")}
variant="outlined"
size="small"
className={`!px-4 !py-1 flex items-center justify-center !normal-case ${
viewMode === "grid"
? "!bg-sky-700 !text-white !border-sky-700 hover:!bg-sky-800 dark:!bg-blue-300 dark:!text-gray-900 dark:!border-blue-300 dark:hover:!bg-blue-400"
: "!bg-white !border-sky-700 !text-slate-900 hover:!bg-sky-50 dark:!bg-transparent dark:!border-blue-300 dark:!text-white dark:hover:!bg-zinc-700"
}`}
>
<GridOnIcon className="mr-1" sx={{ fontSize: 18 }} />
Grid View
</Button>
<div id="tour-events-view-toggle" className="flex gap-2">
{/* Grid View Button */}
<Button
onClick={() => setViewMode("grid")}
variant="outlined"
size="small"
className={`!px-4 !py-1 flex items-center justify-center !normal-case ${
viewMode === "grid"
? "!bg-sky-700 !text-white !border-sky-700 hover:!bg-sky-800 dark:!bg-blue-300 dark:!text-gray-900 dark:!border-blue-300 dark:hover:!bg-blue-400"
: "!bg-white !border-sky-700 !text-slate-900 hover:!bg-sky-50 dark:!bg-transparent dark:!border-blue-300 dark:!text-white dark:hover:!bg-zinc-700"
}`}
>
<GridOnIcon className="mr-1" sx={{ fontSize: 18 }} />
Grid View
</Button>

{/* Calendar View Button */}
<Button
onClick={() => setViewMode("calendar")}
variant="outlined"
size="small"
className={`!px-4 !py-1 flex items-center justify-center !normal-case ${
viewMode === "calendar"
? "!bg-sky-700 !text-white !border-sky-700 hover:!bg-sky-800 dark:!bg-blue-300 dark:!text-gray-900 dark:!border-blue-300 dark:hover:!bg-blue-400"
: "!bg-white !border-sky-700 !text-slate-900 hover:!bg-sky-50 dark:!bg-transparent dark:!border-blue-300 dark:!text-white dark:hover:!bg-zinc-700"
}`}
>
<CalendarTodayIcon className="mr-1" sx={{ fontSize: 18 }} />
Calendar View
</Button>
{/* Calendar View Button */}
<Button
onClick={() => setViewMode("calendar")}
variant="outlined"
size="small"
className={`!px-4 !py-1 flex items-center justify-center !normal-case ${
viewMode === "calendar"
? "!bg-sky-700 !text-white !border-sky-700 hover:!bg-sky-800 dark:!bg-blue-300 dark:!text-gray-900 dark:!border-blue-300 dark:hover:!bg-blue-400"
: "!bg-white !border-sky-700 !text-slate-900 hover:!bg-sky-50 dark:!bg-transparent dark:!border-blue-300 dark:!text-white dark:hover:!bg-zinc-700"
}`}
>
<CalendarTodayIcon className="mr-1" sx={{ fontSize: 18 }} />
Calendar View
</Button>
</div>

{viewMode === "calendar" && (
<div className="ml-auto flex items-center gap-4 text-sm text-slate-900 dark:text-white">
Expand All @@ -211,7 +222,10 @@ const Events = () => {
</div>

{/* Filter Bar */}
<div className="flex flex-wrap gap-8 w-full bg-[var(--calendar-today-bg)] dark:bg-[var(--surface-tinted)] border dark:border-zinc-700 rounded-lg p-5 pb-8 mt-4">
<div
id="tour-events-filters"
className="flex flex-wrap gap-8 w-full bg-[var(--calendar-today-bg)] dark:bg-[var(--surface-tinted)] border dark:border-zinc-700 rounded-lg p-5 pb-8 mt-4"
>
<div className="flex flex-col gap-3">
<span className="text-sm font-medium text-slate-900 dark:text-white">
Event Type
Expand Down Expand Up @@ -357,6 +371,7 @@ const Events = () => {
)}
</div>
</div>
<EventsOnboarding viewMode={viewMode} />
</div>
);
};
Expand Down
8 changes: 8 additions & 0 deletions apps/next/src/components/ui/calendar-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ const CalendarView = ({
}: CalendarViewProps) => {
if (isLoading || error || viewMode !== "calendar") return null;

// Tracks the days that have events so that the events tour can point to one
const eventDays = new Set(
calendarEvents.map((event) => event.start.toDateString()),
);
const dayPropGetter = (date: Date) =>
eventDays.has(date.toDateString()) ? { className: "tour-event-day" } : {};

// Only page between the first and last months that have events
const monthStart = startOfMonth(currentDate);
const firstMonth = availableMonths[0];
Expand Down Expand Up @@ -112,6 +119,7 @@ const CalendarView = ({
toolbar={false}
selectable
onSelectEvent={onSelectEvent}
dayPropGetter={dayPropGetter}
/>
</div>

Expand Down
133 changes: 133 additions & 0 deletions apps/next/src/components/ui/events-onboarding.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"use client";

import { type EventData, Joyride, STATUS, type Step } from "react-joyride";
import { useTourStore } from "@/context/useTourStore";
import { useMediaQuery } from "@/hooks/useMediaQuery";
import { CustomTooltip } from "./tracker-onboarding";

const gridSteps: Step[] = [
{
target: "#tour-events-view-toggle",
content:
"Toggle between grid and calendar view to see events in your preferred layout.",
title: "Switch Views",
skipBeacon: true,
placement: "right",
},
{
target: "#tour-events-filters",
content:
"Use event type and location filters to find exactly what you're looking for!",
title: "Filter Events",
skipBeacon: true,
placement: "bottom",
},
];

const calendarSteps: Step[] = [
{
// Open it for the first visible day with an event
target: ".tour-event-day",
content:
"Click on any day with events to see more information with event details.",
title: "Click for Details",
skipBeacon: true,
placement: "right",
},
];

// Override the Joyride scroll, which puts the target at the top of the page
// It was causing a visual bug, so instead I'm scrolling the element into view
// manually before showing the tooltip
const withDesktopScroll = (steps: Step[]): Step[] =>
steps.map((step) => ({
...step,
skipScroll: true,
before: async () => {
document
.querySelector(step.target as string)
?.scrollIntoView({ block: "center" });
},
}));

const desktopGridSteps = withDesktopScroll(gridSteps);
const desktopCalendarSteps = withDesktopScroll(calendarSteps);

// Keeps targets below the fixed mobile toolbar when Joyride scrolls to them
const MOBILE_SCROLL_OFFSET = 80;

// Mobile has a list view in place of the grid, so it gets the grid tour
const mobileListSteps: Step[] = [
{
...gridSteps[1],
target: "#tour-events-location-mobile",
content: "Use the location filter to find exactly what you're looking for!",
title: "Filter Events by Location",
scrollOffset: MOBILE_SCROLL_OFFSET,
},
{
...gridSteps[0],
target: "#tour-events-view-toggle-mobile",
content:
"Toggle between calendar and list view to see events in your preferred layout.",
scrollOffset: MOBILE_SCROLL_OFFSET,
placement: "bottom",
},
];

const mobileCalendarSteps: Step[] = [
...mobileListSteps,
{
...calendarSteps[0],
scrollOffset: MOBILE_SCROLL_OFFSET,
placement: "bottom",
},
];

interface EventsOnboardingProps {
viewMode: "grid" | "calendar" | "list";
}

export default function EventsOnboarding({ viewMode }: EventsOnboardingProps) {
const running = useTourStore((state) => state.activeTour === "events");
const launchId = useTourStore((state) => state.launchId);
const stop = useTourStore((state) => state.stop);
const isDesktop = useMediaQuery("(min-width: 768px)");

const handleEvent = ({ status, action }: EventData) => {
if (
status === STATUS.FINISHED ||
status === STATUS.SKIPPED ||
action === "close"
)
stop();
};

if (!running) return null;
return (
<Joyride
// Switching views mid-tour swaps the step list and so it restarts from step 1
key={`${launchId}-${viewMode}`}
steps={
viewMode === "calendar"
? isDesktop
? desktopCalendarSteps
: mobileCalendarSteps
: isDesktop
? desktopGridSteps
: mobileListSteps
}
run
continuous
scrollToFirstStep
onEvent={handleEvent}
tooltipComponent={CustomTooltip}
options={{
skipBeacon: true,
overlayClickAction: false,
blockTargetInteraction: true,
zIndex: 1500,
}}
/>
);
}
2 changes: 2 additions & 0 deletions apps/next/src/components/ui/mobile-calendar-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ const MobileCalendarView = ({
}
}}
className={`flex flex-col items-center relative aspect-square justify-center text-sm ${
hasEvents && isCurrentMonth ? "tour-event-day" : ""
} ${
isCurrentMonth
? "text-slate-900 dark:text-zinc-100"
: "text-slate-300 dark:text-zinc-600"
Expand Down
23 changes: 20 additions & 3 deletions apps/next/src/components/ui/mobile-events-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
Select,
type SelectChangeEvent,
} from "@mui/material";
import { useState } from "react";
import { useEffect, useState } from "react";
import type { EventWithType } from "@/app/events/page";
import { useTourStore } from "@/context/useTourStore";
import EventDetailsDrawer from "./event-details-drawer";
import EventsOnboarding from "./events-onboarding";
import MobileCalendarView from "./mobile-calendar-view";
import MobileListView from "./mobile-list-view";
import MonthPickerDrawer from "./month-picker-drawer";
Expand Down Expand Up @@ -51,6 +53,13 @@ const MobileEventsView = ({
const [selectedDayEvents, setSelectedDayEvents] = useState<EventWithType[]>(
[],
);
const tourRunning = useTourStore((state) => state.activeTour === "events");
const tourLaunchId = useTourStore((state) => state.launchId);

// biome-ignore lint/correctness/useExhaustiveDependencies: re-run on every tour restart and view switch
useEffect(() => {
if (tourRunning) window.scrollTo({ top: 0 });
}, [tourRunning, tourLaunchId, mobileView]);

const locationFormControlClasses =
"w-36 [&_.MuiOutlinedInput-root]:h-[38px] [&_.MuiOutlinedInput-root]:rounded-lg [&_.MuiOutlinedInput-root]:bg-white [&_.MuiOutlinedInput-root]:text-[0.9rem] [&_.MuiOutlinedInput-root]:text-slate-900 [&_.MuiOutlinedInput-notchedOutline]:border-sky-700 [&_.MuiOutlinedInput-root:hover_.MuiOutlinedInput-notchedOutline]:border-sky-800 [&_.MuiOutlinedInput-root.Mui-focused_.MuiOutlinedInput-notchedOutline]:border-2 [&_.MuiOutlinedInput-root.Mui-focused_.MuiOutlinedInput-notchedOutline]:border-sky-700 dark:[&_.MuiOutlinedInput-root]:bg-transparent dark:[&_.MuiOutlinedInput-root]:text-zinc-100 dark:[&_.MuiOutlinedInput-notchedOutline]:!border-blue-300";
Expand All @@ -69,7 +78,10 @@ const MobileEventsView = ({
Events
</h1>
<div className="flex items-center gap-3">
<FormControl className={locationFormControlClasses}>
<FormControl
id="tour-events-location-mobile"
className={locationFormControlClasses}
>
<Select
id="mobile-location-select"
className={locationSelectClasses}
Expand All @@ -82,7 +94,10 @@ const MobileEventsView = ({
</Select>
</FormControl>

<div className="flex bg-white dark:bg-transparent border border-sky-700 dark:border-blue-300 rounded-lg overflow-hidden h-[38px]">
<div
id="tour-events-view-toggle-mobile"
className="flex bg-white dark:bg-transparent border border-sky-700 dark:border-blue-300 rounded-lg overflow-hidden h-[38px]"
>
<button
type="button"
onClick={() => setMobileView("calendar")}
Expand Down Expand Up @@ -157,6 +172,8 @@ const MobileEventsView = ({
}}
/>

<EventsOnboarding viewMode={mobileView} />

<EventDetailsDrawer
selectedEventData={selectedEventData}
selectedDayEvents={selectedDayEvents}
Expand Down
Loading
Loading