backend notifications implementation

This commit is contained in:
Čarodej
2022-03-10 11:49:02 +01:00
parent 70d7f2f5bd
commit 64e80d387b
20 changed files with 617 additions and 280 deletions

View File

@@ -5,6 +5,8 @@ import router from '../../router'
const defaultState = {
isVisibleNavigationBars: localStorage.getItem('is_navigation_bars') !== 'false',
isVisibleNotificationCenter: false,
notificationCount: 0,
isDarkMode: false,
isVisibleSidebar: localStorage.getItem('file_info_visibility') === 'true' || false,
itemViewType: localStorage.getItem('preview_type') || 'list',
@@ -167,10 +169,18 @@ const mutations = {
UPDATE_DARK_MODE_STATUS(state, val) {
state.isDarkMode = val
},
UPDATE_NOTIFICATION_COUNT(state, val) {
state.notificationCount = val
},
TOGGLE_NOTIFICATION_CENTER(state) {
state.isVisibleNotificationCenter = !state.isVisibleNotificationCenter
},
}
const getters = {
isVisibleNotificationCenter: (state) => state.isVisibleNotificationCenter,
isVisibleNavigationBars: (state) => state.isVisibleNavigationBars,
notificationCount: (state) => state.notificationCount,
isVisibleSidebar: (state) => state.isVisibleSidebar,
itemViewType: (state) => state.itemViewType,
requestedPlan: (state) => state.requestedPlan,

View File

@@ -3,14 +3,15 @@ const defaultState = {
}
const actions = {
runConnection: ({ commit, getters }) => {
runConnection: ({ commit, getters, dispatch }) => {
commit('SET_RUNNING_COMMUNICATION')
Echo.private(`test.${getters.user.data.id}`)
.listen('.Domain\\Notifications\\Events\\TestUpdate', (e) => {
console.log(e);
});
Echo.private(`App.Users.Models.User.${getters.user.data.id}`)
.notification(() => {
// TODO: call sound
dispatch('getAppData')
});
},
}

View File

@@ -18,6 +18,7 @@ const actions = {
resolve(response)
commit('RETRIEVE_USER', response.data)
commit('UPDATE_NOTIFICATION_COUNT', response.data.data.relationships.unreadNotifications.data.length)
if (! getters.isRunningConnection) {
dispatch('runConnection')
@@ -172,6 +173,13 @@ const mutations = {
}
})
},
PUSH_NEW_NOTIFICATION(state, notification) {
state.user.data.relationships.unreadNotifications.data.push(notification)
},
FLUSH_NOTIFICATIONS(state) {
state.user.data.relationships.readNotifications.data = []
state.user.data.relationships.unreadNotifications.data = []
},
}
const getters = {