- fix RIS in pendenti, se troppi msg, non compariva piu

- cataloghi, ricerca pickup
This commit is contained in:
Surya Paolo
2024-05-09 23:36:58 +02:00
parent 58f53f8c52
commit faf0fabfb0
68 changed files with 1776 additions and 188 deletions

View File

@@ -12,6 +12,7 @@ import { useUserStore } from '@store/UserStore'
export const useNotifStore = defineStore('NotifStore', {
state: (): INotifState => ({
last_notifs: [],
last_notifcoins: [],
show_all: true,
updateNotification: false,
countNotif: 0,
@@ -26,14 +27,14 @@ export const useNotifStore = defineStore('NotifStore', {
},
getlasts_coins: (mystate: INotifState) => (): INotif[] => {
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 20).filter((rec) => (mystate.show_all ? true : !rec.read) && (rec.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS)) : []
const ctrec = (mystate.last_notifcoins) ? mystate.last_notifcoins.filter((rec) => (mystate.show_all ? true : !rec.read) && (rec.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS)) : []
return (ctrec)
},
getnotifs_coinsreq: (mystate: INotifState) => (): INotif[] => {
const ctrec = (mystate.last_notifs) ? mystate.last_notifs.slice(0, 20).filter((rec) => rec.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && rec.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ && rec.status === shared_consts.CircuitsNotif.STATUS_NONE) : []
const ctrec = (mystate.last_notifcoins) ? mystate.last_notifcoins.filter((rec) => rec.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS && rec.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ && rec.status === shared_consts.CircuitsNotif.STATUS_NONE) : []
return (ctrec)
},
@@ -44,7 +45,7 @@ export const useNotifStore = defineStore('NotifStore', {
},
getnumCoinsUnread: (mystate: INotifState) => () => {
const myarr = mystate.last_notifs.filter((notif) => !notif.read && (notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS))
const myarr = mystate.last_notifcoins.filter((notif) => !notif.read && (notif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS))
return (tools.isArray(myarr) ? myarr.length : 0)
},
@@ -85,6 +86,18 @@ export const useNotifStore = defineStore('NotifStore', {
}
}
},
updateRecNotifCoins(recnotif: INotif) {
if (recnotif) {
const myrec = this.last_notifcoins.find((rec: any) => rec._id === recnotif._id)
if (myrec) {
myrec.status = recnotif.status
myrec.read = recnotif.read
myrec.descr = recnotif.descr
this.updateArrNotif()
}
}
},
updateArrRecNotifFromServer(arrrecnotif: INotif[]) {
// console.log('arrrecnotif', arrrecnotif)
if (arrrecnotif && arrrecnotif.length > 0) {
@@ -93,6 +106,14 @@ export const useNotifStore = defineStore('NotifStore', {
this.updateArrNotif()
}
},
updateArrRecNotifCoinsFromServer(arrrecnotifcoins: INotif[]) {
// console.log('arrrecnotif', arrrecnotif)
if (arrrecnotifcoins && arrrecnotifcoins.length > 0) {
this.last_notifcoins = arrrecnotifcoins
this.updateArrNotif()
}
},
async setBadgeIconApp() {
// Get our dummy count and update it,
@@ -129,12 +150,17 @@ export const useNotifStore = defineStore('NotifStore', {
})
},
setRead(_id: string) {
setRead(_id: string, notifcoins: boolean) {
return Api.SendReq(`/sendnotif/set/${_id}/${process.env.APP_ID}`, 'GET', null)
.then((res) => {
// console.log('res', res)
if (res) {
const rec = this.last_notifs.find((rec: any) => rec._id === _id)
let rec = null
if (!notifcoins)
rec = this.last_notifs.find((rec: any) => rec._id === _id)
else
rec = this.last_notifcoins.find((rec: any) => rec._id === _id)
if (rec) {
rec.read = true
}
@@ -148,12 +174,15 @@ export const useNotifStore = defineStore('NotifStore', {
})
},
deleteRec(username: string, id: string) {
deleteRec(username: string, id: string, notifcoins: boolean) {
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)
if (!notifcoins)
this.last_notifs = this.last_notifs.filter((rec) => rec._id !== id)
else
this.last_notifcoins = this.last_notifcoins.filter((rec) => rec._id !== id)
}
this.updateArrNotif()
@@ -171,9 +200,9 @@ export const useNotifStore = defineStore('NotifStore', {
// console.log('res', res)
if (res) {
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS)
this.last_notifs = this.last_notifs.filter((rec: INotif) => rec.typedir !== shared_consts.TypeNotifs.TYPEDIR_CIRCUITS)
this.last_notifcoins = []
else if (qualinotif === shared_consts.QualiNotifs.OTHERS)
this.last_notifs = this.last_notifs.filter((rec: INotif) => rec.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS)
this.last_notifs = []
this.updateArrNotif()
}
@@ -189,16 +218,22 @@ export const useNotifStore = defineStore('NotifStore', {
return ''
},
async updateNotifDataFromServer({ username, lastdataread }: { username: string, lastdataread: Date }) {
async updateNotifDataFromServer({ username, lastdataread, qualinotif }: { username: string, lastdataread: Date, qualinotif: number }) {
// console.log('updateNotifDataFromServer', username, lastdataread)
return Api.SendReq(`/sendnotif/${username}/${lastdataread}/${process.env.APP_ID}`, 'GET', null)
return Api.SendReq(`/sendnotif/${username}/${lastdataread}/${process.env.APP_ID}/${qualinotif}`, 'GET', null)
.then((res) => {
// console.log('res', res)
if (!!res.data && !!res.data.arrnotif) {
this.last_notifs = res.data.arrnotif
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS)
this.last_notifcoins = res.data.arrnotif
else
this.last_notifs = res.data.arrnotif
} else {
this.last_notifs = []
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS)
this.last_notifcoins = []
else
this.last_notifs = []
}
this.updateArrNotif()
tools.updateMyData(res.data.ris)