restored important part

This commit is contained in:
slawk0
2024-11-02 21:38:28 +01:00
parent c6ed8951ca
commit 96f87c2fe8

View File

@@ -14,6 +14,7 @@ type ContactsListProps = {
setCurrentContact: React.Dispatch<React.SetStateAction<string | null>>;
updateContactStatus: (contactObj: ContactsProps, read: true) => void;
};
function ContactsList({
InitializeContact,
contactsList,
@@ -62,6 +63,15 @@ function ContactsList({
};
}, []);
function removeContact(usernamecontact: string) {
deleteContact(usernamecontact); // Remove contact from server
// Remove contact on client
setContactsList((prevContacts) =>
prevContacts.filter(
(contact) => contact.usernamecontact !== usernamecontact,
),
);
}
const sortedContacts = [...contactsList].sort((a, b) => {
if (a.read !== b.read) {
return a.read ? 1 : -1;
@@ -90,7 +100,7 @@ function ContactsList({
<button
onClick={(e) => {
e.stopPropagation();
deleteContact(contact.usernamecontact);
removeContact(contact.usernamecontact);
setCurrentContact(null);
localStorage.removeItem('contact');
}}