Skip to content

Commit 467e717

Browse files
committed
fix: improve sorting of notification items by handling various timestamp fields
1 parent b568d64 commit 467e717

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

frontend/src/components/navbar/Notification.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@ const fetchEnrichedNotifications = async () => {
8888
8989
const { data: notifications } = useQuery({ key: ['notifications'], query: fetchEnrichedNotifications });
9090
91-
const notificationItems = computed(() => (notifications.value?.data as EnrichedNotification[]) || []);
91+
const notificationItems = computed(() => {
92+
const items = (notifications.value?.data as EnrichedNotification[]) || [];
93+
// sort newest first — try common timestamp fields (date, createdAt, created_at)
94+
return items.slice().sort((a, b) => {
95+
const aTs = Date.parse((a as any).date || (a as any).createdAt || (a as any).created_at || "");
96+
const bTs = Date.parse((b as any).date || (b as any).createdAt || (b as any).created_at || "");
97+
const na = Number.isFinite(aTs) ? aTs : 0;
98+
const nb = Number.isFinite(bTs) ? bTs : 0;
99+
return nb - na;
100+
});
101+
});
92102
93103
const _deleteNotificationMutation = useDeleteNotificationMutation();
94104
const _deleteAllNotificationsMutation = useDeleteAllNotificationsMutation();

0 commit comments

Comments
 (0)