From 633776dfe92616f9dadad4b484acec72953f5d68 Mon Sep 17 00:00:00 2001 From: JustIceO7 Date: Wed, 5 Mar 2025 02:54:50 +0000 Subject: [PATCH] FEAT: Users can now edit their own user bios --- frontend/src/pages/UserPage.tsx | 74 +++++++++++++++++++++++++++++---- web_server/blueprints/user.py | 16 +++++++ web_server/utils/user_utils.py | 11 +++++ 3 files changed, 94 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/UserPage.tsx b/frontend/src/pages/UserPage.tsx index a74cb29..76c21db 100644 --- a/frontend/src/pages/UserPage.tsx +++ b/frontend/src/pages/UserPage.tsx @@ -29,6 +29,8 @@ const UserPage: React.FC = () => { const { showAuthModal, setShowAuthModal } = useAuthModal(); const { username: loggedInUsername, profilePicture, setProfilePicture } = useAuth(); const initialProfilePicture = useRef(profilePicture); + const [isEditingBio, setIsEditingBio] = useState(false); + const [editedBio, setEditedBio] = useState(""); const { username } = useParams(); const { vods } = useVods(`/api/vods/${username}`); const navigate = useNavigate(); @@ -110,6 +112,25 @@ const UserPage: React.FC = () => { fetchProfileData(); }, [fetchProfileData]); + const saveBio = async () => { + try { + const response = await fetch("/api/user/bio/change", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ bio: editedBio }), + }); + + if (response.ok) { + setProfileData(prev => prev ? { ...prev, bio: editedBio } : undefined); + setIsEditingBio(false); + } + } catch (error) { + console.error("Error updating bio:", error); + } + }; + if (!profileData) return ; return ( @@ -205,13 +226,52 @@ const UserPage: React.FC = () => { {/* Bio */} -
- {/* User Type (e.g., "USER") */} - {userPageVariant.toUpperCase()} - -
-

About {profileData.username}

-

{profileData.bio}

+
+
+ {userPageVariant.toUpperCase()} +
+
+
+

About {profileData.username}

+ {!isEditingBio && userPageVariant === "personal" && ( + + )} +
+ {!isEditingBio ? ( +

{profileData.bio}

+ ) : ( +
+