Refactor path point handling in App.tsx

This commit is contained in:
2026-04-13 22:28:12 +02:00
parent c4fa489bf9
commit 7eaa6f2612

View File

@@ -5235,37 +5235,43 @@ export function App({ store, initialStatusMessage }: AppProps) {
} }
try { try {
const nextPath = createScenePath({ const nextPoint = createAppendedScenePathPoint(selectedPath);
...selectedPath,
points: [...selectedPath.points, createAppendedScenePathPoint(selectedPath)]
});
commitPathChange(selectedPath, nextPath, "Added a Path point."); store.executeCommand(
createAddPathPointCommand({
pathId: selectedPath.id,
point: nextPoint,
label: "Add path point"
})
);
requestViewportFocus(
{
kind: "pathPoint",
pathId: selectedPath.id,
pointId: nextPoint.id
},
`Appended path point ${selectedPath.points.length + 1} to ${getPathLabelById(selectedPath.id, pathList)}.`
);
} catch (error) { } catch (error) {
setStatusMessage(getErrorMessage(error)); setStatusMessage(getErrorMessage(error));
} }
}; };
const handleDeletePathPoint = (pointIndex: number) => { const handleDeletePathPoint = (pointId: string) => {
if (selectedPath === null) { if (selectedPath === null) {
setStatusMessage("Select a path before removing a point."); setStatusMessage("Select a path before removing a point.");
return; return;
} }
if (selectedPath.points.length <= MIN_SCENE_PATH_POINT_COUNT) {
setStatusMessage(
`Paths must keep at least ${MIN_SCENE_PATH_POINT_COUNT} points.`
);
return;
}
try { try {
const nextPath = createScenePath({ store.executeCommand(
...selectedPath, createDeletePathPointCommand({
points: selectedPath.points.filter((_, index) => index !== pointIndex) pathId: selectedPath.id,
}); pointId,
label: "Delete path point"
commitPathChange(selectedPath, nextPath, "Removed a Path point."); })
);
setStatusMessage("Removed the selected path point.");
} catch (error) { } catch (error) {
setStatusMessage(getErrorMessage(error)); setStatusMessage(getErrorMessage(error));
} }