I want to write a function where if isActive.id === ‘singlesided’ then its status is toggled and at the same time ‘doublesided’ is set to false.
Idea is that singleSided and soubleSided cannot be true at the same time.
Managed to toggle the first option, but cannot find a way to set second to false…
setup.store.ts:
const initialState: LightboxState = {
isActive: [
{ id: 'singleSided', status: false },
{ id: 'doubleSided', status: false },
{ id: 'illuminated', status: false },
{ id: 'notIlluminated', status: false },
{ id: 'standing', status: false },
{ id: 'hanging', status: false },
],
}
export const LightboxStore = signalStore(
{ providedIn: 'root' },
withState(initialState),
withMethods((store) => ({
activeStatus(statusId: string, statusFalse: string): void {
patchState(store, {
isActive: store.isActive().map((isActiveId) => {
if (isActiveId.id === statusId) {
return { ...isActiveId, status: !isActiveId.status };
}
return isActiveId;
}),
});
},
}))
);
I want to run it through a button click as:
store.activeStatus('singleSided', 'doubleSided')
where the first option is toggled(true/false) and second is set to false.