~cytrogen/masto-fe

ref: f8dc013b0d81d5d463c086e291ce99ab1d796a9d masto-fe/app/javascript/mastodon/reducers/alerts.js -rw-r--r-- 610 bytes
f8dc013b — Cytrogen [feature] Add language selector to local settings 5 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 "../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;
  }
}