mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-11-16 22:26:11 +00:00
32 lines
960 B
TypeScript
32 lines
960 B
TypeScript
import { getSystemById } from '@/hooks/Mapper/helpers';
|
|
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
|
import { useMemo } from 'react';
|
|
import { getSystemStaticInfo } from '../../mapRootProvider/hooks/useLoadSystemStatic';
|
|
|
|
interface UseSystemInfoProps {
|
|
systemId: string;
|
|
}
|
|
|
|
export const useSystemInfo = ({ systemId }: UseSystemInfoProps) => {
|
|
const {
|
|
data: { systems, connections },
|
|
} = useMapRootState();
|
|
|
|
return useMemo(() => {
|
|
const staticInfo = getSystemStaticInfo(parseInt(systemId));
|
|
const dynamicInfo = getSystemById(systems, systemId);
|
|
|
|
if (!staticInfo || !dynamicInfo) {
|
|
return { dynamicInfo, staticInfo, leadsTo: [] };
|
|
}
|
|
|
|
const leadsTo = connections
|
|
.filter(x => [x.source, x.target].includes(systemId))
|
|
.map(x => [x.source, x.target])
|
|
.flat()
|
|
.filter(x => x !== systemId);
|
|
|
|
return { dynamicInfo, staticInfo, leadsTo };
|
|
}, [systemId, systems, connections]);
|
|
};
|