import { keepPreviousData } from "@tanstack/react-query"; import { q } from "@thorium/context/AppContext"; import { pickStarmapShip } from "@thorium/cores/StarmapCore/pickShip"; import { useLocalStorage } from "@thorium/hooks/useLocalStorage"; import { useStation } from "@thorium/routes/station/useStation"; import Button from "@thorium/ui/Button"; import Checkbox from "@thorium/ui/Checkbox"; import { InputField, OutputField } from "@thorium/ui/Core"; import InfoTip from "@thorium/ui/InfoTip"; import Select from "@thorium/ui/Select"; import { cn } from "@thorium/utils/cn"; import { Suspense } from "react"; import { shortRangeStateMap } from "./shared"; export function ShortRangeCommCore() { const { shipId } = useStation(); const [shortRangeComm] = q.shortRangeComm.get.useNetRequest({ shipId }); const [{ allowOtherParticipants }, setAllowOtherParticipants] = useLocalStorage( "core-short-range-allow-other-participants", { allowOtherParticipants: false, }, ); if (!shortRangeComm) return (
No Short Range Comm
); return (
{shortRangeStateMap[shortRangeComm.state]} What would you like to set the frequency to?
100 - 350 } onClick={(value) => { if (Number.isNaN(Number(value))) return; q.shortRangeComm.setFrequency.netSend({ shipId, frequency: Math.min(350, Math.max(100, Number(value))), }); }} promptValue={shortRangeComm.frequency} > {shortRangeComm.frequency.toFixed(2)} MHz
Allow Other Participants Allow another participant to join the conversation after it is connected. } checked={allowOtherParticipants} onChange={(event) => setAllowOtherParticipants({ allowOtherParticipants: event.currentTarget.checked, }) } /> {shortRangeComm.state === "idle" ? ( ) : shortRangeComm.state === "hailing" && shortRangeComm.conversationId ? ( ) : ( )}
); } function ConversationName({ conversationId }: { conversationId: number | null | undefined }) { const { shipId } = useStation(); const [conversation] = q.shortRangeComm.conversation.useNetRequest( { conversationId }, { placeholderData: keepPreviousData }, ); return ( <> {conversation ? `: ${conversation.participants .filter((p) => p.id !== shipId) .map((p) => p.name) .join(", ")}` : ""} ); } function HailingButtons({ conversationId }: { conversationId: number }) { const { shipId } = useStation(); const [conversation] = q.shortRangeComm.conversation.useNetRequest({ conversationId, }); return (
{conversation?.targetId ? ( <> ) : null}
); } function ConversationSelect() { const { shipId } = useStation(); const [conversationTemplates] = q.conversation.conversationTemplates.useNetRequest(); const [shortRangeComm] = q.shortRangeComm.get.useNetRequest({ shipId }); return (