Skip to content

Commit

Permalink
Merge pull request #17 from Arzte/multi-deselect
Browse files Browse the repository at this point in the history
Add support for multi deselects
  • Loading branch information
ltouroumov committed Jul 26, 2024
2 parents 3bb8f7b + e2efe56 commit fd45e31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions composables/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export type ProjectObj = HasId &
addons: ObjAddon[];
activateOtherChoice: boolean;
activateThisChoice: string;
deactivateOtherChoice: boolean;
deactivateThisChoice: string;

isSelectableMultiple: boolean;
isNotSelectable: boolean;
Expand Down
15 changes: 13 additions & 2 deletions composables/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fd45e31

Please sign in to comment.