2016-10-02 22:14:26 +09:00
|
|
|
import {
|
2016-10-19 00:09:45 +09:00
|
|
|
NOTIFICATION_SHOW,
|
|
|
|
NOTIFICATION_DISMISS,
|
|
|
|
NOTIFICATION_CLEAR
|
2016-10-30 23:06:43 +09:00
|
|
|
} from '../actions/notifications';
|
|
|
|
import Immutable from 'immutable';
|
2016-09-13 02:20:55 +09:00
|
|
|
|
2016-10-19 00:09:45 +09:00
|
|
|
const initialState = Immutable.List([]);
|
2016-09-17 23:36:10 +09:00
|
|
|
|
2016-09-20 06:25:59 +09:00
|
|
|
export default function notifications(state = initialState, action) {
|
2016-09-13 02:20:55 +09:00
|
|
|
switch(action.type) {
|
2016-10-19 00:09:45 +09:00
|
|
|
case NOTIFICATION_SHOW:
|
|
|
|
return state.push(Immutable.Map({
|
|
|
|
key: state.size > 0 ? state.last().get('key') + 1 : 0,
|
|
|
|
title: action.title,
|
|
|
|
message: action.message
|
|
|
|
}));
|
2016-09-13 02:20:55 +09:00
|
|
|
case NOTIFICATION_DISMISS:
|
2016-09-22 05:07:18 +09:00
|
|
|
return state.filterNot(item => item.get('key') === action.notification.key);
|
|
|
|
case NOTIFICATION_CLEAR:
|
2016-09-13 02:20:55 +09:00
|
|
|
return state.clear();
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|