import { SystemView, WdButton } from '@/hooks/Mapper/components/ui-kit'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; import { OutCommand } from '@/hooks/Mapper/types'; import { PingType } from '@/hooks/Mapper/types/ping.ts'; import clsx from 'clsx'; import { Dialog } from 'primereact/dialog'; import { InputTextarea } from 'primereact/inputtextarea'; import { useCallback, useRef, useState } from 'react'; const PING_TITLES = { [PingType.Rally]: 'RALLY', [PingType.Alert]: 'ALERT', }; interface SystemPingDialogProps { systemId: string; type: PingType; visible: boolean; setVisible: (visible: boolean) => void; } export const SystemPingDialog = ({ systemId, type, visible, setVisible }: SystemPingDialogProps) => { const { outCommand } = useMapRootState(); const [message, setMessage] = useState(''); const inputRef = useRef(); const ref = useRef({ message, outCommand, systemId, type }); ref.current = { message, outCommand, systemId, type }; const handleSave = useCallback(() => { const { message, outCommand, systemId, type } = ref.current; outCommand({ type: OutCommand.addPing, data: { solar_system_id: systemId, type, message, }, }); setVisible(false); }, [setVisible]); const onShow = useCallback(() => { inputRef.current?.focus(); }, []); return (
Ping:{` `}
{PING_TITLES[type]}
in
} visible={visible} draggable={true} style={{ width: '450px' }} onShow={onShow} onHide={() => { if (!visible) { return; } setVisible(false); }} >
setMessage(e.target.value)} />
); };