diff --git a/public/IMG_0870.jpeg b/public/IMG_0870.jpeg new file mode 100644 index 0000000000..4a1739b17a Binary files /dev/null and b/public/IMG_0870.jpeg differ diff --git a/public/Logo_color.svg b/public/Logo_color.svg new file mode 100644 index 0000000000..e79ebc44db --- /dev/null +++ b/public/Logo_color.svg @@ -0,0 +1,19 @@ + diff --git a/src/App.tsx b/src/App.tsx index 53e9c1478c..d22ba4388c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from "react"; import "./App.css"; +import { fetchProfile, saveProfile } from "./utils/profileApi"; import Profile from "./page/Profile"; import Home from "./page/Home"; @@ -7,11 +8,63 @@ import Header from "./components/Header"; import Login from "./page/Login2"; import SignUp from "./page/SignUp2"; +const saveProfileData = async ( + name: string, + title: string, + description: string, + githubLink: string +) => { + try { + let response; + if (name == "" || title == "" || description == "" || githubLink == "") { + response = await saveProfile( + { + name: name, + title: title, + description: description, + githubLink: githubLink, + }, + "post" + ); + } else { + response = await saveProfile( + { + name: name, + title: title, + description: description, + githubLink: githubLink, + }, + "put" + ); + } + // console.log("40: ", response); + console.log("Profile saved successfully"); + return response; + } catch (error) { + console.error("Error saving profile:", error); + return; + } +}; + const App: React.FC = () => { const [isLoggedin, setIsLoggedin] = useState(false); const [currentPage, setCurrentPage] = useState("login"); const [isReadOnly, setIsReadOnly] = useState(true); + // const [profileData, setProfileData] = useState({ + // name: "", + // title: "", + // description: "", + // githubLink: "", + // }); + + const [name, setName] = useState(""); + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [githubLink, setGithubLink] = useState(""); + const [projectsYouLike, setProjectsYouLike] = useState(""); + const [peopleWhoLikeYou, setPeopleWhoLikeYou] = useState(""); + const handleProfileClick = () => { setCurrentPage("profile"); setIsReadOnly(true); @@ -29,6 +82,25 @@ const App: React.FC = () => { console.log("edit clicked"); }; + const handleSaveClick = async () => { + setIsReadOnly(true); + const response = await saveProfileData( + name, + title, + description, + githubLink + ); + if (response) { + setName(response.name); + setTitle(response.title); + setDescription(response.description); + setGithubLink(response.githubLink); + } + console.log("99: ", response); + // setName(response.name); + console.log("done__icon clicked"); + }; + const handleLogin = () => { setIsLoggedin(true); setCurrentPage("home"); @@ -56,6 +128,19 @@ const App: React.FC = () => { console.log("sign in clicked"); }; + const fetchProfileData = async () => { + try { + const profileData = await fetchProfile(); + setName(profileData.profile.name); + setTitle(profileData.profile.title); + setDescription(profileData.profile.description); + setGithubLink(profileData.profile.githubLink); + console.log("138 fetchProfileData: ", profileData); + } catch (error) { + console.error("Error fetching profile:", error); + } + }; + useEffect(() => { const accessToken = localStorage.getItem("accessToken"); if (accessToken) { @@ -63,6 +148,12 @@ const App: React.FC = () => { } }, []); + useEffect(() => { + if (isLoggedin && currentPage === "profile") { + fetchProfileData(); + } + }, [currentPage]); + return (