diff --git a/code/frontend/src/App.tsx b/code/frontend/src/App.tsx index d77cd4f..573ef9a 100644 --- a/code/frontend/src/App.tsx +++ b/code/frontend/src/App.tsx @@ -33,10 +33,10 @@ function App() { path="/register" element={} > - }> + }> + - diff --git a/code/frontend/src/components/Bio.tsx b/code/frontend/src/components/Bio.tsx index ebc372d..9324ea8 100644 --- a/code/frontend/src/components/Bio.tsx +++ b/code/frontend/src/components/Bio.tsx @@ -7,14 +7,14 @@ import "../styles/colors.css"; import IconButton from "@mui/material/IconButton"; import EditSquareIcon from "@mui/icons-material/EditSquare"; import ButtonPrimary from "./ButtonRotkehlchen"; +import api from "../api/axios"; -export default function BioTextField({ ownAccount }: { ownAccount: boolean }) { - const [bio, setBio] = useState(""); - const [oldBio, setOldbio] = useState(""); +export default function BioTextField({ ownAccount, bioText, setBio } : { ownAccount: boolean, bioText: string | undefined, setBio: (bio: string) => void }) { + const [oldBio, setOldbio] = useState(bioText || ""); const [editMode, setEditable] = useState(false); const toggleEditMode = () => { - !editMode && setOldbio(bio); + !editMode && setOldbio(bioText || ""); ownAccount && setEditable(!editMode); }; @@ -23,6 +23,22 @@ export default function BioTextField({ ownAccount }: { ownAccount: boolean }) { setEditable(false); }; + const saveBio = async () => { + try { + const response = await api.post("http://localhost:3001/api/profile/updateBio", { + bio: bioText, + }); + setBio(response.data.data.bio); + setEditable(false); + } catch (error) { + console.error("Error saving bio: ", error); + } + } + + const handleChange = (event: React.ChangeEvent) => { + setBio(event.target.value); + } + return ( setBio(e.target.value)} + value={bioText} + onChange={handleChange} /> {ownAccount && ( @@ -57,8 +73,8 @@ export default function BioTextField({ ownAccount }: { ownAccount: boolean }) { { - console.log("Username component mounted"); - }, []); return ( <> ({ + id: "", + username: "", + bio: "default", + profilePictureUrl: null, + followers: 0, + following: 0, + // posts: 0, + }); + + const userProfile = async () => { + try { + const response = await api.get(`/profile/get/${username}`); + setUserData(response.data.data); + return + } catch (error) { + navigate("/", { replace: true }); /* replace to 404 page */ + console.error("Error fetching user profile:", error); + return null; + } + }; + + const ownAccount = username === user?.username; +useEffect(() => { + + userProfile(); +}, []); + +const setBio = (bio: string) => { + setUserData((prevData) => { + if (prevData) { + return { ...prevData, bio: bio }; + } + return prevData; + }); +} return ( - - + + {/* TODO: Change data to data from Database */} - 50 + {userData?.following} Posts - 100 + {userData?.followers} Followers - 50 + {userData?.following} Following