Skip to content

Commit

Permalink
fix: fix set notification read (#510)
Browse files Browse the repository at this point in the history
* fix: fix set notification read

* chore: added TODO in notification.js

Co-authored-by: Irman Nur Muhammad Alamsyah <irmannmal@gmail.com>
  • Loading branch information
ciniiia and irmannmal committed Sep 22, 2022
1 parent 6bcb8f5 commit 0de212b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/components/HeaderNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ export default {
name: "",
listNotif: [],
notifLength: 0,
showDialog: false,
notifReads: []
showDialog: false
}),
methods: {
Expand Down Expand Up @@ -141,11 +140,10 @@ export default {
async gotoRoute(notif, index) {
if (this.listNotif[index].read == false) {
clearTimeout(timeout)
this.listNotif[index].read = true;
this.notifReads.push(notif.id)
this.listNotif[index].read = true
timeout = setTimeout(async () => {
await setReadNotification(this.notifReads)
await setReadNotification(notif.notifId)
}, 2000)
this.$store.dispatch("substrate/updateDataListNotification", {
Expand Down
28 changes: 15 additions & 13 deletions src/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { getNotification } from "@/lib/api"
import store from "../store"
import { fmtReferenceFromHex } from "@/lib/string-format"

//TODO: move every route name to global
const routes = {
"New Order": "lab-dashboard-process-order",
"Add service": "lab-dashboard-services-detail"
"Add service": "lab-dashboard-services",
"Account Verified": "lab-dashboard-account"
}

export async function getUnlistedNotification (roles, newBlock, lastBlock) {
Expand All @@ -15,16 +17,18 @@ export async function getUnlistedNotification (roles, newBlock, lastBlock) {
const toId = localStorage.getAddress()
const { data } = await getNotification(toId, lastBlock, newBlock, role, from)
const storageName = "LOCAL_NOTIFICATION_BY_ADDRESS_" + toId + "_" + roles;
const reverse = data.reverse()

let listNotification = []
const listNotificationJson = localStorage.getLocalStorageByName(storageName);
if (listNotificationJson) {
listNotification = JSON.parse(listNotificationJson)
}
if (!listNotificationJson) return

listNotification = JSON.parse(listNotificationJson)


if(lastBlock >= parseInt(data[data.length-1].block_number)) return

data.forEach(event => {
reverse.forEach(event => {
const dateSet = new Date(event.created_at)
const timestamp = dateSet.getTime().toString()
const notifDate = dateSet.toLocaleString("en-US", {
Expand All @@ -44,17 +48,15 @@ export async function getUnlistedNotification (roles, newBlock, lastBlock) {
message,
timestamp,
route: routes[event.entity],
params: event.reference_id,
params: {orderId: event.reference_id},
block: event.block_number,
read: false,
read: event.read,
notifId: event.id,
notifDate
})

localStorage.setLocalStorageByName(storageName, JSON.stringify(listNotification));
listNotification.reverse();

store.dispatch("substrate/SET_LIST_NOTIFICATION", listNotification)

});

localStorage.setLocalStorageByName(storageName, JSON.stringify(listNotification));
store.commit("substrate/SET_LIST_NOTIFICATION", listNotification)
}

0 comments on commit 0de212b

Please sign in to comment.