Skip to content

Commit

Permalink
Merge pull request #138 from rairprotocol/add-clear-button-notification
Browse files Browse the repository at this point in the history
Sort order of notifications
  • Loading branch information
sarora180673 authored Jul 30, 2024
2 parents a8c1e89 + 18e13f6 commit 8e256b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rair-front/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function App() {
const getNotificationsCount = useCallback( async () => {
if (currentUserAddress) {
const result = await rFetch(`/api/notifications?onlyUnread=true`);
if (result.success && result.totalCount > 0) {
if (result.success && result.totalCount >= 0) {
setNotificationCount(result.totalCount);
}
}
Expand Down
13 changes: 11 additions & 2 deletions rair-front/src/components/Header/MainHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,22 @@ const MainHeader: React.FC<IMainHeader> = ({
const getNotifications = useCallback(
async (pageNum?: number) => {
if (currentUserAddress) {
// const result = await rFetch(`/api/notifications${itemsPerPage && pageNum ? `?itemsPerPage=${itemsPerPage}&pageNum=${pageNum}` : ''}`);
const result = await rFetch(
`/api/notifications${pageNum ? `?pageNum=${Number(pageNum)}` : ''}`
);

if (result.success) {
setRealDataNotification(result.notifications);
const sortedNotifications = result.notifications.sort((a, b) => {
if (!a.read && b.read) return -1;
if (a.read && !b.read) return 1;

const dateA = new Date(a.createdAt).getTime();
const dateB = new Date(b.createdAt).getTime();

return dateB - dateA;
})
console.info(result.notifications, 'result.notifications')
setRealDataNotification(sortedNotifications);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ const MobileNavigationList: React.FC<IMobileNavigationList> = ({
setFlagLoading(true);
const result = await rFetch(`/api/notifications${ pageNum ? `?pageNum=${Number(pageNum)}` : ''}`);
if (result.success) {
setNotificationArray(result.notifications);
const sortedNotifications = result.notifications.sort((a, b) => {
if (!a.read && b.read) return -1;
if (a.read && !b.read) return 1;

const dateA = new Date(a.createdAt).getTime();
const dateB = new Date(b.createdAt).getTime();

return dateB - dateA;
})
setNotificationArray(sortedNotifications);
}

setFlagLoading(false);
Expand Down

0 comments on commit 8e256b9

Please sign in to comment.