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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import PersistenceRegistry from '../base/redux/PersistenceRegistry';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import { IPoll } from '../polls/types';
  4. import { REMOVE_POLL_FROM_HISTORY, SAVE_POLL_IN_HISTORY } from './actionTypes';
  5. const INITIAL_STATE = {
  6. polls: {}
  7. };
  8. export interface IPollsHistoryState {
  9. polls: {
  10. [meetingId: string]: {
  11. [pollId: string]: IPoll;
  12. };
  13. };
  14. }
  15. const STORE_NAME = 'features/polls-history';
  16. PersistenceRegistry.register(STORE_NAME, INITIAL_STATE);
  17. ReducerRegistry.register<IPollsHistoryState>(STORE_NAME, (state = INITIAL_STATE, action): IPollsHistoryState => {
  18. switch (action.type) {
  19. case REMOVE_POLL_FROM_HISTORY: {
  20. if (Object.keys(state.polls[action.meetingId] ?? {})?.length === 1) {
  21. delete state.polls[action.meetingId];
  22. } else {
  23. delete state.polls[action.meetingId]?.[action.pollId];
  24. }
  25. return state;
  26. }
  27. case SAVE_POLL_IN_HISTORY: {
  28. return {
  29. ...state,
  30. polls: {
  31. ...state.polls,
  32. [action.meetingId]: {
  33. ...state.polls[action.meetingId],
  34. [action.pollId]: action.poll
  35. }
  36. }
  37. };
  38. }
  39. default:
  40. return state;
  41. }
  42. });