~cytrogen/masto-fe

ref: 85a2c62a93f40807d01db1d38dfb3386e85d88c1 masto-fe/app/javascript/flavours/glitch/reducers/alerts.js -rw-r--r-- 607 bytes
85a2c62a — nicole mikołajczyk port 'Add toast with option to open post after publishing in web UI' 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { List as ImmutableList } from 'immutable';

import {
  ALERT_SHOW,
  ALERT_DISMISS,
  ALERT_CLEAR,
} from 'flavours/glitch/actions/alerts';

const initialState = ImmutableList([]);

let id = 0;

const addAlert = (state, alert) =>
  state.push({
    key: id++,
    ...alert,
  });

export default function alerts(state = initialState, action) {
  switch(action.type) {
  case ALERT_SHOW:
    return addAlert(state, action.alert);
  case ALERT_DISMISS:
    return state.filterNot(item => item.key === action.alert.key);
  case ALERT_CLEAR:
    return state.clear();
  default:
    return state;
  }
}