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.

reducer.ts 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. ADD_GIF_FOR_PARTICIPANT,
  4. HIDE_GIF_FOR_PARTICIPANT,
  5. REMOVE_GIF_FOR_PARTICIPANT,
  6. SET_GIF_DRAWER_VISIBILITY,
  7. SET_GIF_MENU_VISIBILITY
  8. } from './actionTypes';
  9. const initialState = {
  10. drawerVisible: false,
  11. gifList: new Map(),
  12. menuOpen: false
  13. };
  14. export interface IGif {
  15. gifUrl?: string;
  16. timeoutID?: number;
  17. }
  18. export interface IGifsState {
  19. drawerVisible: boolean;
  20. gifList: Map<string, IGif>;
  21. menuOpen: boolean;
  22. }
  23. ReducerRegistry.register<IGifsState>(
  24. 'features/gifs',
  25. (state = initialState, action): IGifsState => {
  26. switch (action.type) {
  27. case ADD_GIF_FOR_PARTICIPANT: {
  28. const newList = state.gifList;
  29. newList.set(action.participantId, {
  30. gifUrl: action.gifUrl,
  31. timeoutID: action.timeoutID
  32. });
  33. return {
  34. ...state,
  35. gifList: newList
  36. };
  37. }
  38. case REMOVE_GIF_FOR_PARTICIPANT: {
  39. const newList = state.gifList;
  40. newList.delete(action.participantId);
  41. return {
  42. ...state,
  43. gifList: newList
  44. };
  45. }
  46. case HIDE_GIF_FOR_PARTICIPANT: {
  47. const newList = state.gifList;
  48. const gif = state.gifList.get(action.participantId);
  49. newList.set(action.participantId, {
  50. gifUrl: gif?.gifUrl ?? '',
  51. timeoutID: action.timeoutID
  52. });
  53. return {
  54. ...state,
  55. gifList: newList
  56. };
  57. }
  58. case SET_GIF_DRAWER_VISIBILITY:
  59. return {
  60. ...state,
  61. drawerVisible: action.visible
  62. };
  63. case SET_GIF_MENU_VISIBILITY:
  64. return {
  65. ...state,
  66. menuOpen: action.visible
  67. };
  68. }
  69. return state;
  70. });