This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2016-10-02 15:14:26 +02:00
|
|
|
import {
|
2016-10-18 17:09:45 +02:00
|
|
|
NOTIFICATION_SHOW,
|
|
|
|
NOTIFICATION_DISMISS,
|
|
|
|
NOTIFICATION_CLEAR
|
|
|
|
} from '../actions/notifications';
|
|
|
|
import Immutable from 'immutable';
|
2016-09-12 19:20:55 +02:00
|
|
|
|
2016-10-18 17:09:45 +02:00
|
|
|
const initialState = Immutable.List([]);
|
2016-09-17 16:36:10 +02:00
|
|
|
|
2016-09-19 23:25:59 +02:00
|
|
|
export default function notifications(state = initialState, action) {
|
2016-09-12 19:20:55 +02:00
|
|
|
switch(action.type) {
|
2016-10-18 17:09:45 +02: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-12 19:20:55 +02:00
|
|
|
case NOTIFICATION_DISMISS:
|
2016-09-21 22:07:18 +02:00
|
|
|
return state.filterNot(item => item.get('key') === action.notification.key);
|
|
|
|
case NOTIFICATION_CLEAR:
|
2016-09-12 19:20:55 +02:00
|
|
|
return state.clear();
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|