Skip to content

Commit c68ba5e

Browse files
committed
Updated remove friend button to actually remove friend
1 parent 998e5d6 commit c68ba5e

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

client/src/components/ui/popups/user_friends_select_popup.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Link from "next/link";
44
import React from "react";
55

6+
import { removeFriend } from "../../../lib/api/friends";
67
import ProfilePicture from "../profile_picture";
78

89
type MyFriends = {
@@ -15,9 +16,25 @@ type ItemModalProps = {
1516
isOpen: boolean;
1617
item: MyFriends | null;
1718
onClose: () => void;
19+
onFriendRemoved: (id: number) => void;
1820
};
1921

20-
function UserFriendsSelectPopup({ isOpen, item, onClose }: ItemModalProps) {
22+
function UserFriendsSelectPopup({
23+
isOpen,
24+
item,
25+
onClose,
26+
onFriendRemoved,
27+
}: ItemModalProps) {
28+
if (!item) return;
29+
const handleRemoveFriend = async () => {
30+
try {
31+
await removeFriend(item.id);
32+
onFriendRemoved(item.id);
33+
onClose();
34+
} catch (err) {
35+
console.error("Failed to remove friend", err);
36+
}
37+
};
2138
if (!isOpen || !item) return null;
2239
return (
2340
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
@@ -80,7 +97,7 @@ function UserFriendsSelectPopup({ isOpen, item, onClose }: ItemModalProps) {
8097
</button>
8198
</Link>
8299
<button
83-
onClick={onClose}
100+
onClick={handleRemoveFriend}
84101
className="rounded bg-red-600 px-4 py-2 text-white hover:bg-red-700"
85102
>
86103
<div className="flex items-center justify-between">

client/src/components/ui/user_tables/user_friends_table.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const UserFriendsTable = () => {
1111
const [isModalOpen, setIsModalOpen] = useState(false);
1212
const [friends, setFriends] = useState<Friend[]>([]);
1313

14+
const handleFriendRemoved = (id: number) => {
15+
setFriends((prev) => prev.filter((friend) => friend.id !== id));
16+
};
17+
1418
useEffect(() => {
1519
getFriends().then((res) => {
1620
setFriends(res.data.friends);
@@ -44,6 +48,7 @@ const UserFriendsTable = () => {
4448
isOpen={isModalOpen}
4549
item={selectedItem}
4650
onClose={() => setIsModalOpen(false)}
51+
onFriendRemoved={handleFriendRemoved}
4752
/>
4853
</>
4954
);

0 commit comments

Comments
 (0)