diff --git a/web/src/pages/Calendar.test.tsx b/web/src/pages/Calendar.test.tsx index 770980aa..afb7d05e 100644 --- a/web/src/pages/Calendar.test.tsx +++ b/web/src/pages/Calendar.test.tsx @@ -83,7 +83,7 @@ describe("Calendar page", () => { renderCalendar("/calendar?week=2026-04-06&library=7"); expect(mockUseCalendarWeek).toHaveBeenCalledWith("2026-04-06", { - filter: "all", + filter: "following", libraryId: 7, }); }); diff --git a/web/src/pages/Calendar.tsx b/web/src/pages/Calendar.tsx index f583b3e2..a6bb9936 100644 --- a/web/src/pages/Calendar.tsx +++ b/web/src/pages/Calendar.tsx @@ -17,25 +17,52 @@ import WeekNavigator from "@/components/calendar/WeekNavigator"; import DayGroup from "@/components/calendar/DayGroup"; import { addWeeks, formatDayHeading, getWeekDays, getWeekStart } from "@/lib/calendarWeek"; -type CalendarFilter = "all" | "favorites" | "watchlist"; +type CalendarFilter = "following" | "popular" | "trending" | "everything"; -const FILTER_OPTIONS: { value: CalendarFilter; label: string }[] = [ - { value: "all", label: "All" }, - { value: "favorites", label: "Favorites" }, - { value: "watchlist", label: "Watchlist" }, +const PRESET_OPTIONS: { value: CalendarFilter; label: string }[] = [ + { value: "following", label: "Following" }, + { value: "popular", label: "Popular" }, + { value: "trending", label: "Trending" }, + { value: "everything", label: "All" }, ]; +const DEFAULT_PRESET: CalendarFilter = "following"; +const PRESET_STORAGE_KEY = "calendar:preset"; + +// Accept the four presets plus legacy server values so old shared links keep working. +const KNOWN_FILTERS = new Set([ + "following", + "popular", + "trending", + "everything", + "all", + "favorites", + "watchlist", +]); + /** Skeleton rows mirror a full week; enough slides per row to fill wide viewports. */ const CALENDAR_SKELETON_DAY_ROWS = 7; const CALENDAR_SKELETON_ITEMS_PER_ROW = 18; +function readStoredPreset(): CalendarFilter { + if (typeof window === "undefined") return DEFAULT_PRESET; + const stored = window.localStorage.getItem(PRESET_STORAGE_KEY); + return stored && PRESET_OPTIONS.some((o) => o.value === stored) + ? (stored as CalendarFilter) + : DEFAULT_PRESET; +} + +function writeStoredPreset(value: string) { + if (typeof window === "undefined") return; + window.localStorage.setItem(PRESET_STORAGE_KEY, value); +} + function parseCalendarParams(searchParams: URLSearchParams) { const weekRaw = searchParams.get("week"); const weekStart = weekRaw && /^\d{4}-\d{2}-\d{2}$/.test(weekRaw) ? weekRaw : getWeekStart(new Date()); const rawFilter = searchParams.get("filter"); - const filter: CalendarFilter = - rawFilter === "favorites" || rawFilter === "watchlist" ? rawFilter : "all"; + const filter = rawFilter && KNOWN_FILTERS.has(rawFilter) ? rawFilter : readStoredPreset(); const libraryIdRaw = searchParams.get("library"); const libraryId = libraryIdRaw ? Number(libraryIdRaw) : undefined; return { weekStart, filter, libraryId }; @@ -77,7 +104,10 @@ export default function Calendar() { } const goToWeek = (w: string) => setParams({ week: w }); - const setFilter = (f: string) => setParams({ filter: f === "all" ? undefined : f }); + const setFilter = (f: string) => { + writeStoredPreset(f); + setParams({ filter: f === DEFAULT_PRESET ? undefined : f }); + }; const setLibrary = (id: string) => setParams({ library: id === "all" ? undefined : id }); const onSelectDay = (date: string) => { @@ -101,13 +131,13 @@ export default function Calendar() {

Calendar

- {/* Filter toggle */} + {/* Preset pills (desktop) */}
- {FILTER_OPTIONS.map((opt) => ( + {PRESET_OPTIONS.map((opt) => (