~cytrogen/masto-fe

ref: 96ba9cbc15c562529b2eba4892226dfe6455a349 masto-fe/app/javascript/flavours/glitch/reducers/alerts.js -rw-r--r-- 607 bytes
96ba9cbc — Cytrogen Merge PR #64: Bookmark folders 14 days 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;
  }
}