import { q } from "@thorium/context/AppContext"; import useEventListener, { ShipMapDeckSelectEvent, ShipMapRoomSelectEvent, } from "@thorium/hooks/useEventListener"; import { useStation } from "@thorium/routes/station/useStation"; import { SVGImageLoader } from "@thorium/ui/SVGImageLoader"; import { cn } from "@thorium/utils/cn"; import { useCallback, useRef, type ReactNode, type RefObject } from "react"; import { Suspense } from "react"; import { useShipMapStore } from "./useShipMapStore"; type DeckChildren = ( deck: { name: string }, deckIndex: number, ref: RefObject, ) => ReactNode; export function ShipView({ deckIndex, deckChildren, }: { deckIndex: number; cardLoaded: boolean; deckChildren?: DeckChildren; }) { const { shipId } = useStation(); const [cargoRooms] = q.cargoControl.rooms.useNetRequest({ shipId }); const { decks } = cargoRooms; useEventListener(ShipMapDeckSelectEvent.name, (event: ShipMapDeckSelectEvent) => { useShipMapStore.setState({ deckIndex: event.deckIndex }); }); useEventListener(ShipMapRoomSelectEvent.name, (event: ShipMapRoomSelectEvent) => { useShipMapStore.setState({ selectedRoomId: event.roomId }); }); return (
{decks.map((d, i) => ( ))}
); } function Deck({ d, i, deckIndex, deckChildren, }: { d: { name: string; backgroundUrl?: string }; i: number; deckIndex: number; deckChildren?: DeckChildren; }) { const ref = useRef(null); const onClick = useCallback(() => useShipMapStore.setState({ selectedRoomId: null }), []); return (
i, })} > {deckChildren?.(d, i, ref)}
); }