import { content } from "@deadhead/content"; import { useState } from "react"; import { useNavigate } from "react-router"; import { useClock } from "../clock/clock"; import { formatCredits, locationName, toLocation } from "../format"; import { formatLocalTime } from "../screens/DispatchSheet"; import { useGameAction, useLoadedPlayer } from "../state/actions"; import { Button, Icon, Sheet } from "../ui"; /** "While you were away": deliveries resolved since the player last looked (Step 9.2). */ export function AwaySummary() { const state = useLoadedPlayer(); const acknowledge = useGameAction("acknowledgeSummaries"); // Hide as soon as the player dismisses; the refetch clears the list for real. const [dismissed, setDismissed] = useState>(new Set()); const navigate = useNavigate(); const now = useClock((s) => s.now); const summaries = state.summaries.filter((s) => !dismissed.has(s.dispatchId)); // Upgrades finished and not yet seen: "out of the shop" (CR-009). const outOfShop = state.ships.filter( (s) => s.shop !== null && s.shop.until <= now && !dismissed.has(`ship:${s.id}`), ); // Goals waiting to be claimed (Step 10A.17). const readyGoals = state.goals .filter((g) => g.status === "ready") .map((g) => content.onboardingGoal(g.id)) .filter((g) => g !== undefined); if (summaries.length === 0 && outOfShop.length === 0) return null; const shipName = (shipId: string, tutorial: boolean) => tutorial ? "Company loaner" : (state.ships.find((s) => s.id === shipId)?.name ?? "A ship"); const dismiss = () => { const ids = summaries.map((s) => s.dispatchId); const shipIds = outOfShop.map((s) => s.id); setDismissed(new Set([...dismissed, ...ids, ...shipIds.map((id) => `ship:${id}`)])); acknowledge.mutate({ dispatchIds: ids, ...(shipIds.length > 0 ? { shipIds } : {}) }); }; return ( {readyGoals.length > 0 && (

Goals ready to claim

    {readyGoals.map((goal) => (
  • {goal.title}{" "} +{formatCredits(goal.reward)}
  • ))}
)}
); }