remove AppState assertion related to group actions

This commit is contained in:
dwelle 2023-08-04 23:25:34 +02:00
parent 21d757c892
commit 40cc901d56
2 changed files with 20 additions and 13 deletions

View File

@ -149,11 +149,14 @@ export const actionGroup = register({
]; ];
return { return {
appState: selectGroup( appState: {
newGroupId, ...appState,
{ ...appState, selectedGroupIds: {} }, ...selectGroup(
getNonDeletedElements(nextElements), newGroupId,
) as AppState, { ...appState, selectedGroupIds: {} },
getNonDeletedElements(nextElements),
),
},
elements: nextElements, elements: nextElements,
commitToHistory: true, commitToHistory: true,
}; };
@ -216,7 +219,7 @@ export const actionUngroup = register({
getNonDeletedElements(nextElements), getNonDeletedElements(nextElements),
appState, appState,
null, null,
) as AppState; );
frames.forEach((frame) => { frames.forEach((frame) => {
if (frame) { if (frame) {
@ -243,7 +246,7 @@ export const actionUngroup = register({
); );
return { return {
appState: updateAppState, appState: { ...appState, ...updateAppState },
elements: nextElements, elements: nextElements,
commitToHistory: true, commitToHistory: true,
}; };

View File

@ -17,7 +17,10 @@ export const selectGroup = (
groupId: GroupId, groupId: GroupId,
appState: InteractiveCanvasAppState, appState: InteractiveCanvasAppState,
elements: readonly NonDeleted<ExcalidrawElement>[], elements: readonly NonDeleted<ExcalidrawElement>[],
): InteractiveCanvasAppState => { ): Pick<
InteractiveCanvasAppState,
"selectedGroupIds" | "selectedElementIds" | "editingGroupId"
> => {
const elementsInGroup = elements.reduce((acc, element) => { const elementsInGroup = elements.reduce((acc, element) => {
if (element.groupIds.includes(groupId)) { if (element.groupIds.includes(groupId)) {
acc[element.id] = true; acc[element.id] = true;
@ -31,7 +34,7 @@ export const selectGroup = (
appState.editingGroupId === groupId appState.editingGroupId === groupId
) { ) {
return { return {
...appState, selectedElementIds: appState.selectedElementIds,
selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: false }, selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: false },
editingGroupId: null, editingGroupId: null,
}; };
@ -40,7 +43,7 @@ export const selectGroup = (
} }
return { return {
...appState, editingGroupId: appState.editingGroupId,
selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: true }, selectedGroupIds: { ...appState.selectedGroupIds, [groupId]: true },
selectedElementIds: { selectedElementIds: {
...appState.selectedElementIds, ...appState.selectedElementIds,
@ -226,12 +229,13 @@ export const selectGroupsFromGivenElements = (
} }
if (groupIds.length > 0) { if (groupIds.length > 0) {
const groupId = groupIds[groupIds.length - 1]; const groupId = groupIds[groupIds.length - 1];
nextAppState = selectGroup(groupId, nextAppState, elements); nextAppState = {
...nextAppState,
...selectGroup(groupId, nextAppState, elements),
};
} }
} }
// nextAppState = selectGroups(elements, elements, appState);
return nextAppState.selectedGroupIds; return nextAppState.selectedGroupIds;
}; };