import { useId, useState } from 'react' import { useRegulars } from '../dinners/api.ts' import { useQuestLog, type QuestLogDinner } from '../discover/api.ts' import { details } from '../discover/QuestLogSheet.tsx' import { ErrorBanner } from '../ui/ErrorBanner.tsx' import { ListRow } from '../ui/ListRow.tsx' import { Photo } from '../ui/Photo.tsx' import { Segmented } from '../ui/Segmented.tsx' import { Sheet } from '../ui/Sheet.tsx' import { Skeleton } from '../ui/Skeleton.tsx' import { Tag } from '../ui/Tag.tsx' import type { PlanDay, Swap } from './api.ts' import { weekdayName } from './week.ts' import styles from './SwapSheet.module.css' // Source is a list a dinner is swapped in from. export type Source = 'quest_log' | 'regulars' export const sourceNames: Record = { quest_log: 'Quest log', regulars: 'Regulars' } export const emptyLists: Record = { quest_log: 'Your Quest log is empty — swipe right on a Side quest to add one.', regulars: 'You have no Regulars yet.', } export type SwapSheetProps = { // The day being swapped. day: PlanDay // The ids of the dinners already on the week's plan. planned: ReadonlySet onSwap: (swap: Swap) => void onClose: () => void } // SwapSheet is the mobile swap sheet: the Quest log and the Regulars, as // desktop's plan panel lists them, segmented "Quest log · N | Regulars · N", // each dinner with its 48 px photo, name, difficulty and minutes. Choosing a // dinner swaps it into the day; a dinner already this week can't be chosen. export function SwapSheet({ day, planned, onSwap, onClose }: SwapSheetProps) { const titleId = useId() const questLog = useQuestLog() const regulars = useRegulars() const [source, setSource] = useState('quest_log') const lists = { quest_log: questLog, regulars } const list = lists[source] const label = (s: Source) => { const dinners = lists[s].data return dinners === undefined ? sourceNames[s] : `${sourceNames[s]} · ${dinners.length}` } let body if (list.isError) { body = ( void list.refetch()}> Couldn't load your {sourceNames[source]}. {list.error.message} ) } else if (list.isPending) { body = (
{Array.from({ length: 3 }, (_, i) => ( ))}
) } else if (list.data.length === 0) { body =

{emptyLists[source]}

} else { body = (
    {list.data.map((dinner: QuestLogDinner) => { const already = planned.has(dinner.id) return (
  • ) })}
) } return (

Swap {weekdayName(day.date)}

Replaces {day.dinner.name}

{body}
) }