Notifications

Settings Notifications
User Panel
This commit is contained in:
Paolo Arena
2022-07-23 17:44:44 +02:00
parent 6ae82f14cc
commit e2006e683b
18 changed files with 328 additions and 69 deletions

View File

@@ -18,7 +18,7 @@ export const useNotifStore = defineStore('NotifStore', {
getters: {
getlasts_notifs: (mystate: INotifState) => (): INotif[] => {
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 5).filter((rec) => mystate.show_all ? true : !rec.read) : []
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 10).filter((rec) => mystate.show_all ? true : !rec.read) : []
// const ctrec = (mystate.notifs) ? mystate.notifs.slice().reverse().slice(0, 5) : []
return (ctrec)
@@ -33,7 +33,7 @@ export const useNotifStore = defineStore('NotifStore', {
actions: {
setNotif(notif: INotif) {
// console.log('arrnotif', arrnotif)
console.log('setNotif', notif)
if (notif) {
this.last_notifs = [notif, ...this.last_notifs]
}
@@ -61,15 +61,42 @@ export const useNotifStore = defineStore('NotifStore', {
console.error(error)
return false
})
},
deleteRec(username: string, id: string) {
return Api.SendReq(`/sendnotif/del/${username}/${id}/${process.env.APP_ID}`, 'GET', null)
.then((res) => {
// console.log('res', res)
if (res) {
this.last_notifs = this.last_notifs.filter((rec) => rec._id !== id)
}
})
.catch((error) => {
console.error(error)
return false
})
},
deleteRec(id: string) {
deleteAll(username: string, id: string) {
return Api.SendReq(`/sendnotif/delall/${username}/${process.env.APP_ID}`, 'GET', null)
.then((res) => {
// console.log('res', res)
if (res) {
this.last_notifs = []
}
})
.catch((error) => {
console.error(error)
return false
})
},
deactivateRec(id: string) {
return ''
},
async updateNotifDataFromServer({ username, lastdataread }: {username: string, lastdataread: Date}) {
@@ -94,14 +121,17 @@ export const useNotifStore = defineStore('NotifStore', {
async SendNotifEvent(notif: INotif) {
console.log('SendNotifEvent', notif)
const userStore = useUserStore()
const data: INotif = { ...NotifDefault, ...notif }
data.idapp = process.env.APP_ID
data.type = notif.type
data.typedir = notif.typedir
data.typeid = notif.typeid
data.sender = notif.sender
data.dest = notif.dest
data.descr = notif.descr
data.link = notif.link
data.datenotif = tools.getDateNow()
data.read = false
@@ -110,10 +140,12 @@ export const useNotifStore = defineStore('NotifStore', {
return Api.SendReq('/sendnotif', 'POST', data)
.then((res) => {
// console.log('res', res)
console.log('res', res)
if (res.status === 200) {
if (res.data.code === serv_constants.RIS_CODE_OK) {
this.setNotif(res.data)
if (res.data.code === serv_constants.RIS_CODE_OK && res.data.record) {
if (res.data.record.dest === userStore.my.username) {
this.setNotif(res.data.record)
}
return true
}
}