From e2efe5647f9b6f65f0a7a62e3391a640b2b649ae Mon Sep 17 00:00:00 2001 From: Iris Hoffmeyer Date: Thu, 25 Jul 2024 18:41:59 -0400 Subject: [PATCH] Add support for multi deselects This was missed in the original run to add multiselects as Lt's fork of worm v6 doesn't use multi deselects --- composables/project.ts | 2 ++ composables/store/project.ts | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/composables/project.ts b/composables/project.ts index 0735cf5..7c29af9 100644 --- a/composables/project.ts +++ b/composables/project.ts @@ -97,6 +97,8 @@ export type ProjectObj = HasId & addons: ObjAddon[]; activateOtherChoice: boolean; activateThisChoice: string; + deactivateOtherChoice: boolean; + deactivateThisChoice: string; isSelectableMultiple: boolean; isNotSelectable: boolean; diff --git a/composables/store/project.ts b/composables/store/project.ts index 9555dc1..4be8748 100644 --- a/composables/store/project.ts +++ b/composables/store/project.ts @@ -95,15 +95,26 @@ export const useProjectStore = defineStore('project', () => { selectedN = addOrRemove(id, isSelected); const obj = getObject.value(id); - // If activateOtherChoice is true, select/unselect all objects in activateThisChoice + // If activateOtherChoice is true, select/deselect all objects in activateThisChoice if (obj.activateOtherChoice) { R.split(',', obj.activateThisChoice).forEach((objectId) => { selectedN = addOrRemove(objectId, isSelected); }); } - // Only check for incompatible objects if an object is selected + // Only care about deselecting objects if the object is currently being selected if (isSelected) { + // If deactivateOtherChoice is true, deselect all objects in deactivateThisChoice + if (obj.deactivateOtherChoice) { + // Only deselect objects in deactivateThisChoice if the object is already selected + R.intersection( + R.keys(selected.value), + R.split(',', obj.deactivateThisChoice), + ).forEach((objectId) => { + selectedN = addOrRemove(objectId, false); + }); + } + // Remove any objects that are incompatible with the selected object selectedN = R.pickBy((_, objectId): boolean => { const object = getObject.value(objectId);