You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
820 B
34 lines
820 B
1 year ago
|
import { createReducer } from '@reduxjs/toolkit';
|
||
|
|
||
|
import { closeDropdownMenu, openDropdownMenu } from '../actions/dropdown_menu';
|
||
|
|
||
|
interface DropdownMenuState {
|
||
|
openId: string | null;
|
||
|
keyboard: boolean;
|
||
|
scrollKey: string | null;
|
||
|
}
|
||
|
|
||
|
const initialState: DropdownMenuState = {
|
||
|
openId: null,
|
||
|
keyboard: false,
|
||
|
scrollKey: null,
|
||
|
};
|
||
|
|
||
|
export const dropdownMenuReducer = createReducer(initialState, (builder) => {
|
||
|
builder
|
||
|
.addCase(
|
||
|
openDropdownMenu,
|
||
|
(state, { payload: { id, keyboard, scrollKey } }) => {
|
||
|
state.openId = id;
|
||
|
state.keyboard = keyboard;
|
||
|
state.scrollKey = scrollKey;
|
||
|
},
|
||
|
)
|
||
|
.addCase(closeDropdownMenu, (state, { payload: { id } }) => {
|
||
|
if (state.openId === id) {
|
||
|
state.openId = null;
|
||
|
state.scrollKey = null;
|
||
|
}
|
||
|
});
|
||
|
});
|