Added toasts redux for alerts
• Added: - toasts redux for alerts
This commit is contained in:
@@ -39,6 +39,7 @@ import status_revisions from './status_revisions'
|
||||
import suggestions from './suggestions'
|
||||
import tenor from './tenor'
|
||||
import timelines from './timelines'
|
||||
import toasts from './toasts'
|
||||
import user from './user'
|
||||
import user_lists from './user_lists'
|
||||
|
||||
@@ -83,6 +84,7 @@ const reducers = {
|
||||
suggestions,
|
||||
tenor,
|
||||
timelines,
|
||||
toasts,
|
||||
user,
|
||||
user_lists,
|
||||
}
|
||||
|
||||
25
app/javascript/gabsocial/reducers/toasts.js
Normal file
25
app/javascript/gabsocial/reducers/toasts.js
Normal file
@@ -0,0 +1,25 @@
|
||||
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:
|
||||
return state.push(ImmutableMap({
|
||||
key: state.size > 0 ? state.last().get('key') + 1 : 0,
|
||||
message: action.message,
|
||||
type: action.toastType,
|
||||
}))
|
||||
case TOAST_DISMISS:
|
||||
return state.filterNot(item => item.get('key') === action.toast.key)
|
||||
case TOAST_CLEAR:
|
||||
return state.clear()
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user