Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions frontend/src/routes/users/ProfileCard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Form, useNavigate, useParams } from "react-router-dom"
import { useNavigate, useParams } from "react-router-dom"
import { useState, useEffect, useRef } from "react"
import '../../style/ProfileCard.css'
import noProfileImage from "../../images/noprofileimage.png"
Expand All @@ -9,6 +9,15 @@ import axios from "axios";

const API_BASE = "http://localhost:3001"

const checkUser = (user, param) => {
if(user){
if(param === "i"){
return user && !user.profileImage
}
return user && !user.coverImage
}
}

const ProfileCard = () => {
const clickCover = useRef(null);
const clickProfile = useRef(null);
Expand Down Expand Up @@ -38,16 +47,6 @@ const ProfileCard = () => {
}, []);


let check1 = false;
if(user && !user.profileImage) {
check1 = true;
}

let check2 = false;
if(user && !user.coverImage) {
check2 = true;
}

if(user && !user.bio){
user.bio = "";
}
Expand Down Expand Up @@ -89,7 +88,7 @@ const ProfileCard = () => {
<div class="profilecard">
<div class="coverContainer">
{
check2 ? (
checkUser(user, "c") ? (
<img class="coverimage" src={noCoverImage}></img>
) : (
<img class="coverimage" src={`${API_BASE}/${user.coverImage}`}></img>
Expand All @@ -104,7 +103,7 @@ const ProfileCard = () => {
</div>
<div class="perfilcontainer">
{
check1 ? (
checkUser(user, "i") ? (
<img class="profileimage" src={noProfileImage}></img>
) : (
<img class="profileimage" src={`${API_BASE}/${user.profileImage}`}></img>
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/routes/users/UserEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import RemoveCard from "./RemoveCard"

const API_BASE = "http://localhost:3001"

const userImageExists = (user) => {
return user && !user.profileImage
}
const UserEdit = () => {

const [user, setUser] = useState(null);
Expand All @@ -25,11 +28,6 @@ const UserEdit = () => {
})
}, []);

let check = false;
if(user && !user.profileImage) {
check = true;
}

const showProfileInfo = () => {
setRemoveCard(false);
setpasswordCard(false);
Expand All @@ -48,13 +46,13 @@ const UserEdit = () => {
setRemoveCard(!removeCard);
};

return ( user ? (
return ( (user) ? (
<div class="tudinhoo">
<div class="cardmenu">
<div class="topinfo">
<p class="titleusereditcard">Menu de Edição</p>
{
check ? (
userImageExists(user) ? (
<img src={noProfileImage} class="profilepictureusercard"></img>
):(
<img src={`${API_BASE}/${user.profileImage}`} class="profilepictureusercard"></img>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/routes/users/UserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getUserIdFromToken() {
try {
const payload = token.split('.')[1];
const decodedPayload = JSON.parse(atob(payload));
return decodedPayload.userId; // Ensure this matches your JWT payload
return decodedPayload.userId;
} catch (error) {
console.error('Error decoding token:', error);
return null;
Expand All @@ -30,10 +30,11 @@ const UserProfile = () => {
const [currentUser, setCurrentUser] = useState(null)
const [user, setUser] = useState(null);
const { id } = useParams()

const [error, setError] = useState(null)
const [modalFollow, setModalFollow] = useState(false)
const [modalUnfollow, setModalUnfollow] = useState(false)
console.log(currentUser);

useEffect(() => {
fetch( API_BASE + '/users/' + id)
.then(response => {
Expand Down