2017-02-05 02:48:11 +01:00
|
|
|
import {
|
|
|
|
MEDIA_OPEN,
|
|
|
|
MODAL_CLOSE,
|
|
|
|
MODAL_INDEX_DECREASE,
|
|
|
|
MODAL_INDEX_INCREASE
|
|
|
|
} from '../actions/modal';
|
|
|
|
import Immutable from 'immutable';
|
2016-10-24 18:07:40 +02:00
|
|
|
|
|
|
|
const initialState = Immutable.Map({
|
2017-02-05 02:48:11 +01:00
|
|
|
media: null,
|
|
|
|
index: 0,
|
2016-10-24 18:07:40 +02:00
|
|
|
open: false
|
|
|
|
});
|
|
|
|
|
|
|
|
export default function modal(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2017-01-16 13:27:58 +01:00
|
|
|
case MEDIA_OPEN:
|
|
|
|
return state.withMutations(map => {
|
2017-02-05 02:48:11 +01:00
|
|
|
map.set('media', action.media);
|
|
|
|
map.set('index', action.index);
|
2017-01-16 13:27:58 +01:00
|
|
|
map.set('open', true);
|
|
|
|
});
|
|
|
|
case MODAL_CLOSE:
|
|
|
|
return state.set('open', false);
|
2017-02-05 02:48:11 +01:00
|
|
|
case MODAL_INDEX_DECREASE:
|
2017-02-26 01:23:44 +01:00
|
|
|
return state.update('index', index => (index - 1) % state.get('media').size);
|
2017-02-05 02:48:11 +01:00
|
|
|
case MODAL_INDEX_INCREASE:
|
2017-02-26 01:23:44 +01:00
|
|
|
return state.update('index', index => (index + 1) % state.get('media').size);
|
2017-01-16 13:27:58 +01:00
|
|
|
default:
|
|
|
|
return state;
|
2016-10-24 18:07:40 +02:00
|
|
|
}
|
|
|
|
};
|