Skip to content

Commit

Permalink
notification support seen date and send date
Browse files Browse the repository at this point in the history
  • Loading branch information
saltykheera committed Jan 26, 2025
1 parent 59ed944 commit 1cafed1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/molecules/NotificationList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-list two-line>
<template v-for="(notification, index) in formattedNotifications">
<template v-for="(notification, index) in notifications">
<v-list-item
:key="notification.id"
@click="$emit('go-to-redirect', notification)"
Expand All @@ -26,9 +26,19 @@
<v-list-item-subtitle
>Sent by {{ notification.author }}</v-list-item-subtitle
>
<v-list-item-subtitle>{{
notification.createdDate
}}</v-list-item-subtitle>
<v-list-item-subtitle
class="text-caption grey--text text--darken-1 mt-1"
>
At: {{ formatFrontendDate(notification.createdDate) }}
</v-list-item-subtitle>

<!-- Notification read date (conditional) -->
<v-list-item-subtitle
v-if="notification.readAt"
class="text-caption success--text mt-1"
>
Seen: {{ formatFrontendDate(notification.readAt) }}
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon @click.stop="$emit('mark-as-read', notification)">
Expand All @@ -40,7 +50,7 @@
</v-list-item>
<v-divider
v-if="index < notifications.length - 1"
:key="`divider-${notification.id}`"
:key="`divider-${index}`"
></v-divider>
</template>
</v-list>
Expand All @@ -55,18 +65,10 @@ export default {
required: true,
},
},
computed: {
formattedNotifications() {
return this.notifications.map((notification) => ({
...notification,
createdDate: this.formatDate(notification.createdDate), // Convert date
}))
},
},
methods: {
formatDate(timestamp) {
formatFrontendDate(timestamp) {
const date = new Date(timestamp)
return date.toLocaleString()
return date.toLocaleString() // Format the date in a human-readable way
},
},
}
Expand Down
1 change: 1 addition & 0 deletions src/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class UserController extends Controller {
// Update inbox array
if (inboxIndex !== -1) {
userToUpdate.inbox[inboxIndex].read = true;
userToUpdate.inbox[inboxIndex].readAt = Date.now();
}

if (notificationIndex !== -1 || inboxIndex !== -1) {
Expand Down
5 changes: 5 additions & 0 deletions src/models/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @param {string} description - The description value.
*/

import { read } from "fs"

export default class Notification {
constructor({
title,
Expand All @@ -13,6 +15,7 @@ export default class Notification {
read,
testId,
accessLevel,
readAt,
} = {}) {
this.title = title
this.description = description
Expand All @@ -22,6 +25,7 @@ export default class Notification {
this.read = read
this.testId = testId
this.accessLevel = accessLevel ?? null
this.readAt = readAt ?? null
}
static toNotification(data) {
return new Notification(data)
Expand All @@ -37,6 +41,7 @@ export default class Notification {
read: this.read,
testId: this.testId,
accessLevel: this.accessLevel,
read : this.read,
}
}
}
1 change: 1 addition & 0 deletions src/views/admin/NotificationPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default {
window.open(`/${notification.redirectsTo}`)
},
async markAsRead(notification) {
console.log(notification);
await this.$store.dispatch('markNotificationAsRead', {
notification: notification,
user: this.user,
Expand Down

0 comments on commit 1cafed1

Please sign in to comment.