diff --git a/assets/js/hooks/Mapper/components/mapInterface/components/AddSystemDialog/AddSystemDialog.tsx b/assets/js/hooks/Mapper/components/mapInterface/components/AddSystemDialog/AddSystemDialog.tsx index 1e754467..28ebc302 100644 --- a/assets/js/hooks/Mapper/components/mapInterface/components/AddSystemDialog/AddSystemDialog.tsx +++ b/assets/js/hooks/Mapper/components/mapInterface/components/AddSystemDialog/AddSystemDialog.tsx @@ -15,12 +15,20 @@ import { sortWHClasses } from '@/hooks/Mapper/helpers'; export type SearchOnSubmitCallback = (item: SearchSystemItem) => void; interface AddSystemDialogProps { + title?: string; visible: boolean; setVisible: (visible: boolean) => void; onSubmit?: SearchOnSubmitCallback; + excludedSystems?: number[]; } -export const AddSystemDialog = ({ visible, setVisible, onSubmit }: AddSystemDialogProps) => { +export const AddSystemDialog = ({ + title = 'Add system', + visible, + setVisible, + onSubmit, + excludedSystems = [], +}: AddSystemDialogProps) => { const { outCommand, data: { wormholesData }, @@ -54,20 +62,24 @@ export const AddSystemDialog = ({ visible, setVisible, onSubmit }: AddSystemDial }, }); - const sorted = (result.systems as SearchSystemItem[]).sort((a, b) => { + let prepared = (result.systems as SearchSystemItem[]).sort((a, b) => { const amatch = a.label.indexOf(query); const bmatch = b.label.indexOf(query); return amatch - bmatch; }); - setFilteredItems(sorted); + if (excludedSystems) { + prepared = prepared.filter(x => !excludedSystems.includes(x.system_static_info.solar_system_id)); + } + + setFilteredItems(prepared); } catch (error) { console.error('Error fetching data:', error); setFilteredItems([]); } } }, - [outCommand], + [excludedSystems, outCommand], ); const ref = useRef({ onSubmit, selectedItem }); @@ -89,7 +101,7 @@ export const AddSystemDialog = ({ visible, setVisible, onSubmit }: AddSystemDial return ( { const distA = a.has_connection ? a.systems?.length || 0 : Infinity; @@ -163,6 +168,12 @@ export const RoutesWidgetContent = () => { export const RoutesWidgetComp = () => { const [routeSettingsVisible, setRouteSettingsVisible] = useState(false); const { data, update } = useRouteProvider(); + const { + data: { hubs = [] }, + outCommand, + } = useMapRootState(); + + const preparedHubs = useMemo(() => hubs.map(x => parseInt(x)), [hubs]); const isSecure = data.path_type === 'secure'; const handleSecureChange = useCallback(() => { @@ -174,6 +185,23 @@ export const RoutesWidgetComp = () => { const ref = useRef(null); const compact = useMaxWidth(ref, 155); + const [openAddSystem, setOpenAddSystem] = useState(false); + + const onAddSystem = useCallback(() => setOpenAddSystem(true), []); + + const handleSubmitAddSystem: SearchOnSubmitCallback = useCallback( + async item => { + if (preparedHubs.includes(item.value)) { + return; + } + + await outCommand({ + type: OutCommand.addHub, + data: { system_id: item.value }, + }); + }, + [hubs, outCommand], + ); return ( {
Routes + + { classNameLabel={clsx('text-red-400')} /> - setRouteSettingsVisible(true)} /> + setRouteSettingsVisible(true)} + tooltip={{ + content: 'Click here to open Routes settings', + }} + />
} > + + setOpenAddSystem(false)} + onSubmit={handleSubmitAddSystem} + />
); }; diff --git a/assets/js/hooks/Mapper/components/mapWrapper/MapWrapper.tsx b/assets/js/hooks/Mapper/components/mapWrapper/MapWrapper.tsx index 3dff0f8c..7867fa30 100644 --- a/assets/js/hooks/Mapper/components/mapWrapper/MapWrapper.tsx +++ b/assets/js/hooks/Mapper/components/mapWrapper/MapWrapper.tsx @@ -17,7 +17,7 @@ import { getSystemById } from '@/hooks/Mapper/helpers'; import { Node, XYPosition } from 'reactflow'; import { Commands } from '@/hooks/Mapper/types/mapHandlers.ts'; -import { useMapEventListener } from '@/hooks/Mapper/events'; +import { emitMapEvent, useMapEventListener } from '@/hooks/Mapper/events'; import { STORED_INTERFACE_DEFAULT_VALUES } from '@/hooks/Mapper/mapRootProvider/MapRootProvider'; import { useDeleteSystems } from '@/hooks/Mapper/components/contexts/hooks'; @@ -134,6 +134,14 @@ export const MapWrapper = () => { const handleSubmitAddSystem: SearchOnSubmitCallback = useCallback( async item => { + if (ref.current.systems.some(x => x.system_static_info.solar_system_id === item.value)) { + emitMapEvent({ + name: Commands.centerSystem, + data: item.value.toString(), + }); + return; + } + await outCommand({ type: OutCommand.manualAddSystem, data: { coordinates: openAddSystem, solar_system_id: item.value },