mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 10:45:54 +00:00
chore: release version v1.12.6
This commit is contained in:
@@ -2,27 +2,22 @@ import { Node, useReactFlow } from 'reactflow';
|
|||||||
import { useCallback, useRef } from 'react';
|
import { useCallback, useRef } from 'react';
|
||||||
import { CommandAddSystems } from '@/hooks/Mapper/types/mapHandlers.ts';
|
import { CommandAddSystems } from '@/hooks/Mapper/types/mapHandlers.ts';
|
||||||
import { convertSystem2Node } from '../../helpers';
|
import { convertSystem2Node } from '../../helpers';
|
||||||
import { useMapState } from '@/hooks/Mapper/components/map/MapProvider.tsx';
|
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
||||||
|
|
||||||
export const useMapAddSystems = () => {
|
export const useMapAddSystems = () => {
|
||||||
const rf = useReactFlow();
|
const rf = useReactFlow();
|
||||||
const {
|
const {
|
||||||
data: { systems },
|
data: { systems },
|
||||||
update,
|
} = useMapRootState();
|
||||||
} = useMapState();
|
|
||||||
|
|
||||||
const ref = useRef({ rf, systems, update });
|
const ref = useRef({ rf, systems });
|
||||||
ref.current = { update, systems, rf };
|
ref.current = { systems, rf };
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
(systems: CommandAddSystems) => {
|
(systems: CommandAddSystems) => {
|
||||||
const nodes = rf.getNodes();
|
const nodes = rf.getNodes();
|
||||||
const prepared: Node[] = systems.filter(x => !nodes.some(y => x.id === y.id)).map(convertSystem2Node);
|
const prepared: Node[] = systems.filter(x => !nodes.some(y => x.id === y.id)).map(convertSystem2Node);
|
||||||
rf.addNodes(prepared);
|
rf.addNodes(prepared);
|
||||||
|
|
||||||
ref.current.update({
|
|
||||||
systems: [...ref.current.systems.filter(sys => systems.some(x => sys.id !== x.id)), ...systems],
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[rf],
|
[rf],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user