sorting contact to display unreaded firtst

This commit is contained in:
slawk0
2024-10-31 00:25:02 +01:00
parent efe7559265
commit 7953a4ee2c
3 changed files with 23 additions and 1 deletions

View File

@@ -69,7 +69,14 @@ function ContactsList({
});
}
const addContactsList = contactsList.map((contact: ContactsProps, index) => (
const sortedContats = [...contactsList].sort((a, b) => {
if (a.read !== b.read) {
return a.read ? 1 : -1;
}
return 0;
});
const addContactsList = sortedContats.map((contact: ContactsProps, index) => (
<li
className="flex hover:bg-green-700 p-2 rounded cursor-pointer justify-between items-center min-h-[40px]" // Added min-h-[40px]
onClick={() => {

View File

@@ -81,6 +81,7 @@ function Chat() {
}),
);
}
return (
<>
<div className="text-white flex h-screen">

14
server/utils/authorize.js Normal file
View File

@@ -0,0 +1,14 @@
const { verifyJwtToken } = require("../auth/jwt");
function authorizeUser(res, token) {
if (!token) {
return res.status(401).json({ message: "Unauthorized" });
}
try {
const { username } = verifyJwtToken(token);
if (username) {
return res.status(200).json({ message: "Authorized", username: username });
}
}
}