From 1dc0b08a0560e14699e08b8ef5ec2a5f01bd502a Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 20 Jan 2023 10:01:11 +0100 Subject: [PATCH] button FollowHandler.js en false de base --- .../src/components/Post/ActionComment.js | 2 +- .../components/UserProfil/FollowHandler.js | 51 +++++++++++++++++-- .../components/UserProfil/SuggestFriends.js | 2 +- Site Web/client/src/pages/Profil.js | 4 +- Site Web/client/src/styles/_settings.scss | 6 +++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Site Web/client/src/components/Post/ActionComment.js b/Site Web/client/src/components/Post/ActionComment.js index a46668ec..84edb78b 100644 --- a/Site Web/client/src/components/Post/ActionComment.js +++ b/Site Web/client/src/components/Post/ActionComment.js @@ -22,7 +22,7 @@ const ActionComment = ( { commentaire , postId}) => { const handleDelete = () => { dispatch(deleteComment(postId, commentaire._id)); - setMessage('commantaire suprimer'); + setMessage('commentaire supprimé'); setEdit(false); }; diff --git a/Site Web/client/src/components/UserProfil/FollowHandler.js b/Site Web/client/src/components/UserProfil/FollowHandler.js index cd995312..3a01cf48 100644 --- a/Site Web/client/src/components/UserProfil/FollowHandler.js +++ b/Site Web/client/src/components/UserProfil/FollowHandler.js @@ -1,13 +1,58 @@ import axios from 'axios'; -import React, { useEffect, useState } from 'react'; +import React, {useContext, useEffect, useState} from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { followUser, unFollowUser } from '../../actions/user.actions'; +import { followUser, unFollowUser,getUser } from '../../actions/user.actions'; import { setUserToFollowData, setUserToUnFollowData } from '../../reducers/user.reducer'; import { isEmpty } from '../Utils'; +import {UidContext} from "../AppContext"; +import Coeur from "../../assets/img/coeurs.png"; +import CoeurPlein from "../../assets/img/coeursPlein.png"; +import MiniProfil from "../MiniProfil"; const FollowHandler = ( { idToFollow , type } ) => { + const uid = useContext(UidContext); + const dispatch = useDispatch(); const userData = useSelector((state) => state.user.user); + + console.log("userData: ",userData) + //const [isFollowed, setIsFollowed] = useState(userData.following.includes(idToFollow)); const [isFollowed, setIsFollowed] = useState(false); + + const follow = (e) => { + e.preventDefault(); + setIsFollowed(true); + dispatch(followUser(userData._id, idToFollow)); + }; + + const unfollow = (e) => { + e.preventDefault(); + setIsFollowed(false); + dispatch(unFollowUser(userData._id, idToFollow)); + }; + + return ( + <> + { uid !== idToFollow && isFollowed && !isEmpty(userData) && ( + + {type === "card" && } + {type === "suggest" && } + + )} + {uid !== idToFollow && isFollowed === false && !isEmpty(userData) && ( + + {type === "card" && } + {type === "suggest" && } + + )} + + ); + + + + /* + const userData = useSelector((state) => state.user.user); + const [isFollowed, setIsFollowed] = useState(userData.following.includes(idToFollow)); + console.log("isFollowed",isFollowed) const dispatch = useDispatch(); const handleFollow = (e) => { @@ -66,7 +111,7 @@ const FollowHandler = ( { idToFollow , type } ) => { )} - ); + );*/ }; export default FollowHandler; \ No newline at end of file diff --git a/Site Web/client/src/components/UserProfil/SuggestFriends.js b/Site Web/client/src/components/UserProfil/SuggestFriends.js index b6f8ec0a..a1b0cf71 100644 --- a/Site Web/client/src/components/UserProfil/SuggestFriends.js +++ b/Site Web/client/src/components/UserProfil/SuggestFriends.js @@ -41,7 +41,7 @@ const SuggestFriends = () => { setFriends(array); } - const stateTopFollowers = () => { + const stateTopFollowers = async () => { let array = []; let obj = JSON.parse(JSON.stringify(usersData)); obj.sort((a, b) => b.followers.length - a.followers.length); diff --git a/Site Web/client/src/pages/Profil.js b/Site Web/client/src/pages/Profil.js index 832da86a..83898a28 100644 --- a/Site Web/client/src/pages/Profil.js +++ b/Site Web/client/src/pages/Profil.js @@ -71,7 +71,9 @@ const Profil = () => { {/*

suuu

*/}
- { uidS && Suivre +} + { /*uidS && Suivre +*/ + + }
setFollowingPopup(true)}> diff --git a/Site Web/client/src/styles/_settings.scss b/Site Web/client/src/styles/_settings.scss index 33fc8e31..6cc69462 100644 --- a/Site Web/client/src/styles/_settings.scss +++ b/Site Web/client/src/styles/_settings.scss @@ -40,3 +40,9 @@ body{ clip-path:circle(50%); } +.follow-btn{ + //background-color: #4CAF50; + width:70px; + border: none; +} +