-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (54 loc) · 1.55 KB
/
app.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export const state = () => ({
theme: 'light',
isWaiting: false,
notifications: [],
hideCategories: false,
})
export const mutations = {
SET_THEME(state, theme) {
state.theme = theme
},
SET_THEME_BODY_CLASSNAME(_, themeName) {
document.body.className = themeName
},
SET_IS_WAITING(state, payload) {
state.isWaiting = payload
},
SET_SCROLL_INTO_VIEW(_, { _selector }) {
let elToReach = document.querySelector(_selector)
elToReach?.scrollIntoView({
behavior: 'smooth',
})
},
SET_HIDE_CATEGORIES(state, hideCateg) {
state.hideCategories = hideCateg
},
PUSH_NOTIFICATION(state, notification) {
state.notifications.push({
...notification,
id: (
Math.random().toString(36) + Date.now().toString(36)
).substring(2),
})
},
REMOVE_NOTIFICATION(state, notificationToRemove) {
state.notifications = state.notifications.filter(
(notification) => notification.id != notificationToRemove.id
)
},
CLEAR_NOTIFICATIONS(state) {
if (!state.notifications[0]) return
// state.notifications = []
while (state.notifications.length > 0) {
state.notifications.pop()
}
},
}
export const actions = {
addNotification({ commit }, notification) {
commit('PUSH_NOTIFICATION', notification)
},
removeNotification({ commit }, notification) {
commit('REMOVE_NOTIFICATION', notification)
},
}