From 2c5c91a23f2a2c7115176ad58ec75afb62bd1949 Mon Sep 17 00:00:00 2001 From: chaaanuwu Date: Sun, 12 Apr 2026 03:10:54 +0530 Subject: [PATCH 1/3] feat: Add follow/unfollow functionality in Profile; implement followUser API integration --- client/src/api/userFollows.api.js | 6 ++++++ client/src/pages/Profile.jsx | 34 +++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 client/src/api/userFollows.api.js diff --git a/client/src/api/userFollows.api.js b/client/src/api/userFollows.api.js new file mode 100644 index 0000000..a5881f2 --- /dev/null +++ b/client/src/api/userFollows.api.js @@ -0,0 +1,6 @@ +import axiosInstance from "./axiosInstance"; + +export const followUser = async (followingId) => { + const res = await axiosInstance.post('/me/follow', { followingId }); + return res; +} \ No newline at end of file diff --git a/client/src/pages/Profile.jsx b/client/src/pages/Profile.jsx index 4053dac..626a62f 100644 --- a/client/src/pages/Profile.jsx +++ b/client/src/pages/Profile.jsx @@ -12,9 +12,11 @@ import Modal from "../components/ui/Modal"; import SearchBar from "../components/ui/SearchBar"; import { getHistoryBanner } from "../api/history.api"; import Dropdown from "../components/ui/Dropdown"; +import { followUser } from "../api/userFollows.api"; export default function Profile() { const [profileData, setProfileData] = useState(null); + const [following, setFollowing] = useState(false); const [loading, setLoading] = useState(true); const [isModalOpen, setIsModalOpen] = useState(false); const [isDropdownOpen, setIsDropdownOpen] = useState(false); @@ -27,8 +29,9 @@ export default function Profile() { useEffect(() => { const fetchProfile = async () => { try { - const data = await getProfile(userId); - setProfileData(data); + const res = await getProfile(userId); + setProfileData(res); + console.log(res); } catch (err) { console.error("Failed to fetch profile", err); } finally { @@ -38,6 +41,17 @@ export default function Profile() { fetchProfile(); }, [userId]); + const handleFollow = async () => { + try { + const res = await followUser(profileData.user._id); + if (res.status === 200) { + setFollowing(true); + } + } catch (error) { + console.error("Failed to follow user", error); + } + } + const handleChangeCover = async () => { setIsModalOpen(true); try { @@ -143,9 +157,17 @@ export default function Profile() { className="flex items-center gap-3" > {!isMyProfile ? ( - + !following ? ( + + ) : ( + + ) ) : ( - +
- )} - {/* DROPDOWN CONTAINER */} + {/* Dropdown */}
+ {/* Comments Modal */} + +
+ +
+

+ Discussion +

+

+ Responses +

+
+ +
+ {comments?.length > 0 ? ( + comments.map((c) => ( +
+ +
+
+

{profileData.user.firstName} {profileData.user.lastName}

+

{c.comment}

+
+
+ + +
+
+
+ )) + ) : ( +
+

No thoughts shared yet. Be the first to break the silence.

+
+ )} +
+ +
+
+ +