Modrinth/store/user.js
Geometrically 5017c5a5f1
Use base URL for axios (#241)
* Switch site to use axios base url

* Fix team invites

* Fix find/replace setting the wrong thing

* Fix analytics being blocking, small issues
2021-05-28 10:19:13 -07:00

36 lines
764 B
JavaScript

export const state = () => ({
notifications: {
count: 0,
lastUpdated: 0,
},
})
export const mutations = {
SET_NOTIFICATIONS(state, count) {
state.notifications.count = count
state.notifications.lastUpdated = Date.now()
},
}
export const actions = {
async fetchNotifications(
{ commit, state, rootState },
{ force = false } = {}
) {
if (
rootState.auth.user &&
rootState.auth.user.id &&
(force || Date.now() - state.notifications.lastUpdated > 300000)
) {
const notifications = (
await this.$axios.get(
`user/${rootState.auth.user.id}/notifications`,
rootState.auth.headers
)
).data
commit('SET_NOTIFICATIONS', notifications.length)
}
},
}