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}
+ ) : (
+
+ )}
diff --git a/web_server/blueprints/user.py b/web_server/blueprints/user.py
index 933a968..98d566d 100644
--- a/web_server/blueprints/user.py
+++ b/web_server/blueprints/user.py
@@ -61,6 +61,22 @@ def user_profile_picture_save():
return jsonify({"message": "Profile picture saved", "path": thumbnail_path})
+@login_required
+@user_bp.route('/user/bio/change', methods=['POST'])
+def user_change_bio():
+ """
+ Changes users bio
+ """
+ user_id = session.get("user_id")
+
+ try:
+ data = request.get_json()
+ bio = data.get("bio")
+ update_bio(user_id, bio)
+ return jsonify({"status": "Success"}), 200
+ except Exception as e:
+ return jsonify({"error": str(e)}), 400
+
## Subscription Routes
@login_required
@user_bp.route('/user/subscription/
')
diff --git a/web_server/utils/user_utils.py b/web_server/utils/user_utils.py
index f597fb6..282a8bd 100644
--- a/web_server/utils/user_utils.py
+++ b/web_server/utils/user_utils.py
@@ -27,6 +27,17 @@ def get_username(user_id: str) -> Optional[str]:
""", (user_id,))
return data['username'] if data else None
+def update_bio(user_id: int, bio: str):
+ """
+ Updates users bio given their user_id
+ """
+ with Database() as db:
+ db.execute("""
+ UPDATE users
+ SET bio = ?
+ WHERE user_id = ?
+ """, (bio, user_id))
+
def get_session_info_email(email: str) -> dict:
"""
Returns username and user_id given email