forked from danskernesdigitalebibliotek/dpl-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.slice.ts
More file actions
30 lines (26 loc) · 729 Bytes
/
modal.slice.ts
File metadata and controls
30 lines (26 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { createSlice } from "@reduxjs/toolkit";
export type ModalId = string;
interface PayloadProps {
payload: {
modalId: ModalId;
};
}
interface StateProps {
modalIds: string[];
}
const modalSlice = createSlice({
name: "modal",
initialState: { modalIds: [] },
reducers: {
openModal(state: StateProps, action: PayloadProps) {
if (!state.modalIds.includes(action.payload.modalId)) {
state.modalIds.push(action.payload.modalId);
}
},
closeModal(state: StateProps, action: PayloadProps) {
state.modalIds.splice(state.modalIds.indexOf(action.payload.modalId), 1);
}
}
});
export const { openModal, closeModal } = modalSlice.actions;
export default modalSlice.reducer;