dropdown_menu.ts 820 B

123456789101112131415161718192021222324252627282930313233
  1. import { createReducer } from '@reduxjs/toolkit';
  2. import { closeDropdownMenu, openDropdownMenu } from '../actions/dropdown_menu';
  3. interface DropdownMenuState {
  4. openId: string | null;
  5. keyboard: boolean;
  6. scrollKey: string | null;
  7. }
  8. const initialState: DropdownMenuState = {
  9. openId: null,
  10. keyboard: false,
  11. scrollKey: null,
  12. };
  13. export const dropdownMenuReducer = createReducer(initialState, (builder) => {
  14. builder
  15. .addCase(
  16. openDropdownMenu,
  17. (state, { payload: { id, keyboard, scrollKey } }) => {
  18. state.openId = id;
  19. state.keyboard = keyboard;
  20. state.scrollKey = scrollKey;
  21. },
  22. )
  23. .addCase(closeDropdownMenu, (state, { payload: { id } }) => {
  24. if (state.openId === id) {
  25. state.openId = null;
  26. state.scrollKey = null;
  27. }
  28. });
  29. });