2020-08-06 05:24:20 +01:00
|
|
|
import {
|
|
|
|
TOAST_SHOW,
|
|
|
|
TOAST_DISMISS,
|
|
|
|
TOAST_CLEAR,
|
|
|
|
} from '../actions/toasts'
|
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'
|
|
|
|
|
|
|
|
const initialState = ImmutableList([])
|
|
|
|
|
|
|
|
export default function toasts(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case TOAST_SHOW:
|
2020-12-08 04:39:13 +00:00
|
|
|
return state.set(state.size, ImmutableMap({
|
2020-08-06 05:24:20 +01:00
|
|
|
key: state.size > 0 ? state.last().get('key') + 1 : 0,
|
2020-12-08 04:39:13 +00:00
|
|
|
message: 'action.message',
|
2020-08-06 05:24:20 +01:00
|
|
|
type: action.toastType,
|
|
|
|
}))
|
|
|
|
case TOAST_DISMISS:
|
2020-12-08 04:39:13 +00:00
|
|
|
return state.filterNot(item => item.get('key') === action.toastKey)
|
2020-08-06 05:24:20 +01:00
|
|
|
case TOAST_CLEAR:
|
|
|
|
return state.clear()
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|