1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-22 18:48:43 +09:00
YuruToot/app/assets/javascripts/components/reducers/modal.jsx

33 lines
800 B
React
Raw Normal View History

import {
MEDIA_OPEN,
MODAL_CLOSE,
MODAL_INDEX_DECREASE,
MODAL_INDEX_INCREASE
} from '../actions/modal';
import Immutable from 'immutable';
2016-10-25 01:07:40 +09:00
const initialState = Immutable.Map({
media: null,
index: 0,
2016-10-25 01:07:40 +09:00
open: false
});
export default function modal(state = initialState, action) {
switch(action.type) {
2017-01-16 21:27:58 +09:00
case MEDIA_OPEN:
return state.withMutations(map => {
map.set('media', action.media);
map.set('index', action.index);
2017-01-16 21:27:58 +09:00
map.set('open', true);
});
case MODAL_CLOSE:
return state.set('open', false);
case MODAL_INDEX_DECREASE:
return state.update('index', index => Math.max(index - 1, 0));
case MODAL_INDEX_INCREASE:
return state.update('index', index => Math.min(index + 1, state.get('media').size - 1));
2017-01-16 21:27:58 +09:00
default:
return state;
2016-10-25 01:07:40 +09:00
}
};