feat(ui): remove selectionDeleted action

This commit is contained in:
psychedelicious 2024-05-19 14:54:35 +10:00
parent 7cceafe0dd
commit b8b671c0db
2 changed files with 17 additions and 23 deletions

View File

@ -17,7 +17,6 @@ import {
edgesChanged,
nodesChanged,
redo,
selectionDeleted,
undo,
} from 'features/nodes/store/nodesSlice';
import { $flow } from 'features/nodes/store/reactFlowInstance';
@ -263,8 +262,22 @@ export const Flow = memo(() => {
useHotkeys('esc', onEscapeHotkey);
const onDeleteHotkey = useCallback(() => {
dispatch(selectionDeleted());
}, [dispatch]);
const { nodes, edges } = store.getState().nodes.present;
const nodeChanges: NodeChange[] = [];
const edgeChanges: EdgeChange[] = [];
nodes
.filter((n) => n.selected)
.forEach(({ id }) => {
nodeChanges.push({ type: 'remove', id });
});
edges
.filter((e) => e.selected)
.forEach(({ id }) => {
edgeChanges.push({ type: 'remove', id });
});
dispatch(nodesChanged(nodeChanges));
dispatch(edgesChanged(edgeChanges));
}, [dispatch, store]);
useHotkeys(['delete', 'backspace'], onDeleteHotkey);
return (

View File

@ -347,23 +347,6 @@ export const nodesSlice = createSlice({
state.nodes = [];
state.edges = [];
},
selectionDeleted: (state) => {
const selectedNodes = state.nodes.filter((n) => n.selected);
const selectedEdges = state.edges.filter((e) => e.selected);
const nodeChanges: NodeChange[] = selectedNodes.map((n) => ({
id: n.id,
type: 'remove',
}));
const edgeChanges: EdgeChange[] = selectedEdges.map((e) => ({
id: e.id,
type: 'remove',
}));
state.nodes = applyNodeChanges(nodeChanges, state.nodes);
state.edges = applyEdgeChanges(edgeChanges, state.edges);
},
undo: (state) => state,
redo: (state) => state,
},
@ -414,7 +397,6 @@ export const {
nodesChanged,
nodeUseCacheChanged,
notesNodeValueChanged,
selectionDeleted,
undo,
redo,
} = nodesSlice.actions;
@ -530,6 +512,5 @@ export const isAnyNodeOrEdgeMutation = isAnyOf(
nodeLabelChanged,
nodeNotesChanged,
nodeUseCacheChanged,
notesNodeValueChanged,
selectionDeleted
notesNodeValueChanged
);