Files
AstralRinth/store/user.js
venashial 2c22837d9f Fix notification & follow list sorting, Add notification badge + loading animation (#206)
* Order notifications and followed mods

Fixes modrinth/knossos#195

* Add user notification badge on avatar

Closes modrinth/knossos#145

* Add loading animation

* Chain calls, remove console.log

* Chain calls

* Fix formatting to match prettier

* Remove unused userFollows

* Create user vuex store

* Add notification count indication on dashboard

* Fix background for light mode

* Move delay check to action, add force parameter

* Slightly decrease notification badge opacity on dashboard

* Remove SVG for image masking, use border around bubble

Also adds CSS for when the dropdown is opened/hovered

* Fix merge conflicts

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
2021-05-27 09:32:34 -07:00

36 lines
796 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(
`https://api.modrinth.com/api/v1/user/${rootState.auth.user.id}/notifications`,
rootState.auth.headers
)
).data
commit('SET_NOTIFICATIONS', notifications.length)
}
},
}