summaryrefslogtreecommitdiffstats
path: root/webapp/src/store/notifications.js
blob: 4687b78544e25558a21385511656cb20b82daac7 (plain) (blame)
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
31
32
33
34
35
36
37
38
39
export default {
  namespaced: true,
  state: {
    alerts: [],
    snackbars: [],
    newAlertCount: 0
  },
  getters: {
    nextSnackbar (state) {
      if (state.snackbars) return state.snackbars[0]
      else return null
    }
  },
  mutations: {
    shiftSnackbars (state) {
      state.snackbars.shift()
    },
    newSnackbar (state, data) {
      state.snackbars.push(data)
    },
    newAlert (state, data) {
      data.show = true
      state.newAlertCount++
      state.alerts.unshift(data)
    },
    removeAlert (state, id) {
      const a = state.alerts.find(el => el.id === id)
      a.show = false
      setTimeout(function () {
        var index = state.alerts.indexOf(a)
        state.alerts.splice(index, 1)
        if (index < state.newAlertCount && index >= 0) state.newAlertCount--
      }, 200)
    },
    resetNewAlertCount (state) {
      state.newAlertCount = 0
    }
  }
}