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.

32 lines
804 B

  1. import {
  2. MEDIA_OPEN,
  3. MODAL_CLOSE,
  4. MODAL_INDEX_DECREASE,
  5. MODAL_INDEX_INCREASE
  6. } from '../actions/modal';
  7. import Immutable from 'immutable';
  8. const initialState = Immutable.Map({
  9. media: null,
  10. index: 0,
  11. open: false
  12. });
  13. export default function modal(state = initialState, action) {
  14. switch(action.type) {
  15. case MEDIA_OPEN:
  16. return state.withMutations(map => {
  17. map.set('media', action.media);
  18. map.set('index', action.index);
  19. map.set('open', true);
  20. });
  21. case MODAL_CLOSE:
  22. return state.set('open', false);
  23. case MODAL_INDEX_DECREASE:
  24. return state.update('index', index => (index - 1) % state.get('media').size);
  25. case MODAL_INDEX_INCREASE:
  26. return state.update('index', index => (index + 1) % state.get('media').size);
  27. default:
  28. return state;
  29. }
  30. };