source: frontend/src/components/userProfile/UserListModal.tsx@ 0808ef2

main
Last change on this file since 0808ef2 was cb4a1da, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 5 months ago

add working server side search to landing page; change some endpoints

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import { useNavigate } from "react-router-dom";
2import type { BaseNonAdminUser } from "../../utils/types";
3
4interface ModalProps {
5 title: string;
6 users: BaseNonAdminUser[];
7 onClose: () => void;
8 onFollowToggle: (targetUsername: string) => Promise<void>;
9}
10
11const UserListModal = ({
12 title,
13 users,
14 onClose,
15 onFollowToggle,
16}: ModalProps) => {
17 const navigate = useNavigate();
18 const baseURL = import.meta.env.VITE_API_BASE_URL;
19
20 return (
21 <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
22 <div className="bg-white rounded-xl shadow-2xl w-full max-w-md max-h-[70vh] flex flex-col">
23 <div className="p-4 border-b flex justify-between items-center">
24 <h2 className="text-xl font-bold">{title}</h2>
25 <button
26 onClick={onClose}
27 className="text-gray-500 hover:text-black text-2xl cursor-pointer"
28 >
29 &times;
30 </button>
31 </div>
32
33 <div className="overflow-y-auto p-4 flex-1">
34 {users.length === 0 ? (
35 <p className="text-center text-gray-500 py-8">No users found.</p>
36 ) : (
37 users.map((u) => (
38 <div
39 key={u.username}
40 className="flex items-center justify-between p-3 hover:bg-gray-50 rounded-lg transition-colors"
41 >
42 <div
43 className="flex items-center gap-4 cursor-pointer flex-1"
44 onClick={() => {
45 onClose();
46 navigate(`/users/${u.username}`);
47 }}
48 >
49 <div className="w-10 h-10 rounded-full bg-blue-100 overflow-hidden shrink-0 flex items-center justify-center">
50 {u.profilePhoto ? (
51 <img
52 src={`${baseURL}/${u.profilePhoto}`}
53 className="w-full h-full object-cover"
54 alt=""
55 />
56 ) : (
57 <span className="text-blue-600 font-bold">
58 {u.fullName.charAt(0)}
59 </span>
60 )}
61 </div>
62 <p className="font-semibold text-gray-900">{u.fullName}</p>
63 </div>
64
65 <button
66 onClick={() => onFollowToggle(u.username)}
67 className={`px-4 py-1 text-sm font-medium rounded-md transition-colors cursor-pointer ${
68 u.isFollowedByCurrentUser
69 ? "bg-gray-200 text-gray-700 hover:bg-gray-300"
70 : "bg-blue-500 text-white hover:bg-blue-600"
71 }`}
72 >
73 {u.isFollowedByCurrentUser ? "Unfollow" : "Follow"}
74 </button>
75 </div>
76 ))
77 )}
78 </div>
79 </div>
80 <div className="absolute inset-0 -z-10" onClick={onClose}></div>
81 </div>
82 );
83};
84
85export default UserListModal;
Note: See TracBrowser for help on using the repository browser.