From 4dccaefe3b24c16671e906f1e09ee079e1b59358 Mon Sep 17 00:00:00 2001 From: yunusemrealtug Date: Tue, 21 Nov 2023 01:20:47 +0300 Subject: [PATCH 1/2] added profile update modal, also mock steam external link --- ludos/frontend/src/pages/ProfilePage.js | 251 ++++++++++++++++++++---- 1 file changed, 209 insertions(+), 42 deletions(-) diff --git a/ludos/frontend/src/pages/ProfilePage.js b/ludos/frontend/src/pages/ProfilePage.js index dfc902da..77f6a2aa 100644 --- a/ludos/frontend/src/pages/ProfilePage.js +++ b/ludos/frontend/src/pages/ProfilePage.js @@ -5,6 +5,8 @@ import { Typography, Box, Button, + Modal, + TextField, } from "@mui/material"; import React, { useEffect, useState } from "react"; import steamLogo from "../assets/steam.png"; @@ -15,6 +17,12 @@ import { useNavigate } from "react-router-dom"; function ProfilePage() { const navigate = useNavigate(); + const [formData, setFormData] = useState({ + fullName: "", + steamUrl: "", + aboutMe: "", + }); + const [open, setOpen] = useState(false); const [auth, setAuth] = useState(false); const [profile, setProfile] = useState(""); const [favGames, setFavGames] = useState([]); @@ -49,6 +57,68 @@ function ProfilePage() { } }, []); + const handleOpen = () => { + setOpen(true); + }; + const handleClose = () => { + setOpen(false); + }; + const submitInformation = () => { + console.log(formData); + const link = `http://${process.env.REACT_APP_API_URL}/user/edit-info`; + + axios + .put( + link, + { + fullName: formData.fullName, + steamUrl: formData.steamUrl, + aboutMe: formData.aboutMe, + }, + { + headers: { + Authorization: "Bearer " + localStorage.getItem("accessToken"), + }, + }, + ) + .then(() => {}) + .catch((error) => { + console.log(error); + }); + setOpen(false); + }; + const handleChange = (event) => { + const { id, value } = event.target; + setFormData((prevData) => ({ + ...prevData, + [id]: value, + })); + }; + + const openSteamTab = () => { + window.open( + "https://steamcommunity.com/profiles/76561199020341351/", + "_blank", + ); + }; + + const editProfile = () => {}; + + const modalStyle = { + position: "absolute", + top: "50%", + left: "50%", + transform: "translate(-50%, -50%)", + width: 400, + backgroundColor: "rgba(255,170,0, 0.8)", + border: "2px solid #000", + boxShadow: 24, + p: 4, + display: "flex", + flexDirection: "column", + borderRadius: "5%", + }; + const boxStyle = { backgroundColor: "rgba(30, 30, 30, 0.9)", borderRadius: "10px", @@ -63,6 +133,7 @@ function ProfilePage() { height: "300px", marginTop: "7px", }; + const bioBoxStyle = { backgroundColor: "rgba(255, 255, 255, 0.06)", color: "rgb(0, 150, 255)", @@ -132,7 +203,10 @@ function ProfilePage() { lg={3} style={{ marginLeft: "3%" }} > - + + - {}} - alt="Steam" - src={steamLogo} - /> - {}} - alt="Epic Games" - src={epicLogo} - /> - {}} - alt="Itch.io" - src={itchioLogo} - /> + + + - Cemre Beydirel + {profile.fullName || "Yunus Emre"} @@ -211,7 +273,8 @@ function ProfilePage() { color: "rgb(0, 150, 255)", }} > - A university student who is interested in strategy games. + {profile.aboutMe || + "A university student who is interested in strategy games."} @@ -242,7 +305,7 @@ function ProfilePage() { component="legend" style={{ fontFamily: "Trebuchet MS, sans-serif" }} > - Nnumber of Posts + Number of Posts {}} + onClick={handleOpen} > Edit My Profile + + + + Full Name + + + + Steam ID: + + + + Bio: + + + + + @@ -364,15 +520,26 @@ function ProfilePage() { {favGames.map((game, index1) => ( - + {}} - alt="Steam" + alt={game.title} src={game.coverLink} /> Date: Tue, 21 Nov 2023 03:11:17 +0300 Subject: [PATCH 2/2] profile page implementation --- ludos/frontend/src/pages/ProfilePage.js | 141 +++++++++++++++++++++--- 1 file changed, 126 insertions(+), 15 deletions(-) diff --git a/ludos/frontend/src/pages/ProfilePage.js b/ludos/frontend/src/pages/ProfilePage.js index 77f6a2aa..5ee23579 100644 --- a/ludos/frontend/src/pages/ProfilePage.js +++ b/ludos/frontend/src/pages/ProfilePage.js @@ -7,6 +7,8 @@ import { Button, Modal, TextField, + Input, + Snackbar, } from "@mui/material"; import React, { useEffect, useState } from "react"; import steamLogo from "../assets/steam.png"; @@ -14,6 +16,7 @@ import epicLogo from "../assets/epic.png"; import itchioLogo from "../assets/itchio.png"; import axios from "axios"; import { useNavigate } from "react-router-dom"; +import NotificationsIcon from "@mui/icons-material/Notifications"; function ProfilePage() { const navigate = useNavigate(); @@ -26,6 +29,73 @@ function ProfilePage() { const [auth, setAuth] = useState(false); const [profile, setProfile] = useState(""); const [favGames, setFavGames] = useState([]); + const [avatarImage, setAvatarImage] = useState(null); + const [snackbarMessage, setSnackbarMessage] = useState(""); + const [snackbar, setSnackbar] = useState(false); + + const handleImageChange = (event) => { + const file = event.target.files[0]; + console.log(file); + + if (file) { + const reader = new FileReader(); + reader.onloadend = () => { + setAvatarImage(reader.result); + }; + reader.readAsDataURL(file); + console.log(reader); + try { + const formData = new FormData(); + formData.append("file", file); + console.log(formData); + const link = `http://${process.env.REACT_APP_API_URL}/external/upload`; + axios + .post(link, formData, { + headers: { + Authorization: "Bearer " + localStorage.getItem("accessToken"), + "Content-Type": "multipart/form-data", + }, + }) + .then((response) => { + const link2 = `http://${process.env.REACT_APP_API_URL}/user/edit-info`; + axios + .put( + link2, + { + avatar: response.data.url, + }, + { + headers: { + Authorization: + "Bearer " + localStorage.getItem("accessToken"), + }, + }, + ) + .then(() => { + setSnackbarMessage("Image uploaded successfully!"); + setSnackbar(true); + }) + .catch((error) => { + console.log(error); + setSnackbarMessage("Image could not be uploaded!"); + setSnackbar(true); + }); + + // Now you can update the profile or perform any other action with the response data + }) + .catch((error) => { + console.error("Error uploading file:", error); + setSnackbarMessage("Image could not be uploaded!"); + setSnackbar(true); + }); + + // Now you can update the profile or perform any other action with the response data + } catch (error) { + console.error("Error uploading file:", error); + } + } + }; + useEffect(() => { setAuth(false); if (localStorage.getItem("accessToken")) { @@ -63,6 +133,10 @@ function ProfilePage() { const handleClose = () => { setOpen(false); }; + const closeSnackbar = () => { + setSnackbarMessage(""); + setSnackbar(false); + }; const submitInformation = () => { console.log(formData); const link = `http://${process.env.REACT_APP_API_URL}/user/edit-info`; @@ -81,9 +155,14 @@ function ProfilePage() { }, }, ) - .then(() => {}) + .then(() => { + setSnackbarMessage("Information updated successfully!"); + setSnackbar(true); + }) .catch((error) => { console.log(error); + setSnackbarMessage("Information could not be updated!"); + setSnackbar(true); }); setOpen(false); }; @@ -102,8 +181,6 @@ function ProfilePage() { ); }; - const editProfile = () => {}; - const modalStyle = { position: "absolute", top: "50%", @@ -130,7 +207,7 @@ function ProfilePage() { backgroundColor: "rgba(30, 30, 30, 0.9)", borderRadius: "10px", paddingTop: "15px", - height: "300px", + height: "320px", marginTop: "7px", }; @@ -194,6 +271,12 @@ function ProfilePage() { + - - - + + - @{profile.username} - + + @{profile.username} + + + +