From 4bf2a9250eb00f2f847c216cf16a03eccb49ae9b Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Tue, 17 Jan 2023 09:09:57 +0100 Subject: [PATCH 1/3] add link profil --- Site Web/client/src/actions/user.actions.js | 14 -- Site Web/client/src/components/AjoutLien.js | 2 +- Site Web/client/src/components/MiniProfil.js | 37 ++++ Site Web/client/src/components/Navbar.js | 4 +- Site Web/client/src/components/Notif.js | 38 ++-- .../components/Post/NouveauDisplayPosts.js | 4 + .../client/src/components/Routes/index.js | 2 +- Site Web/client/src/pages/Profil.js | 195 +++++++++--------- Site Web/client/src/pages/Trends.js | 64 +----- Site Web/controllers/post.controller.js | 13 +- Site Web/controllers/user.controller.js | 11 +- 11 files changed, 193 insertions(+), 191 deletions(-) create mode 100644 Site Web/client/src/components/MiniProfil.js diff --git a/Site Web/client/src/actions/user.actions.js b/Site Web/client/src/actions/user.actions.js index 4e4078ab..ed923594 100644 --- a/Site Web/client/src/actions/user.actions.js +++ b/Site Web/client/src/actions/user.actions.js @@ -13,20 +13,6 @@ export const getUser = (uid) => { }; }; -export const getNotif = (uid) => { - console.log("loadNotif3"); - - return (dispatch)=> { - return axios - .get(`${process.env.REACT_APP_API_URL}api/user/notif/${uid}`) - .then((res) => { - dispatch(setUserData(res.data)) - }) - .catch((err) => console.log(err)); - }; -}; - - export const uploadPicture = (data, id) => { return (dispatch) => { return axios diff --git a/Site Web/client/src/components/AjoutLien.js b/Site Web/client/src/components/AjoutLien.js index 4ef8e33f..8c192a19 100644 --- a/Site Web/client/src/components/AjoutLien.js +++ b/Site Web/client/src/components/AjoutLien.js @@ -19,7 +19,7 @@ const AjoutLien = () => { dispatch(getPosts()); cancelPost(); setDisplayAdd(false); - window.location.reload(); + //window.location.reload(); }else { alert("Veuillez compléter tous les champs.") } diff --git a/Site Web/client/src/components/MiniProfil.js b/Site Web/client/src/components/MiniProfil.js new file mode 100644 index 00000000..47776f58 --- /dev/null +++ b/Site Web/client/src/components/MiniProfil.js @@ -0,0 +1,37 @@ +import React, {useEffect,useState} from 'react'; +import {useDispatch, useSelector} from "react-redux"; +import {getPosts} from "../actions/post.actions"; +import {getUserTemp} from "../actions/user.actions"; +import {useParams} from "react-router-dom"; +import {isEmpty} from "./Utils"; +import FollowHandler from "./UserProfil/FollowHandler"; + +const MiniProfil = ({uid} ) => { + const [userData, setUserData] = useState(null); + + useEffect(() => { + async function fetchData() { + const response = await fetch(`${process.env.REACT_APP_API_URL}api/user/${uid}`); + const data = await response.json(); + setUserData(data); + } + fetchData(); + }, [uid]); + + if (!userData) { + return

Loading...

; + } + + + + return ( +
+
+ + {userData.pseudo} +
+
+ ); +}; + +export default MiniProfil; diff --git a/Site Web/client/src/components/Navbar.js b/Site Web/client/src/components/Navbar.js index 90ece44f..125dbb64 100644 --- a/Site Web/client/src/components/Navbar.js +++ b/Site Web/client/src/components/Navbar.js @@ -23,7 +23,7 @@ const Navbar = () => { data.append('postedId', userData._id); data.append('message', description); data.append('lien', lien); - console.log(data); + //console.log("test",data); putData(data); console.log(data); cancelPost(); @@ -110,7 +110,7 @@ const Navbar = () => {
  • - + Me diff --git a/Site Web/client/src/components/Notif.js b/Site Web/client/src/components/Notif.js index 52316d9f..9ac3e9a7 100644 --- a/Site Web/client/src/components/Notif.js +++ b/Site Web/client/src/components/Notif.js @@ -1,30 +1,30 @@ -import React from 'react'; -import {isEmpty} from "./Utils"; +import React, {useEffect,useState} from 'react'; +import {useDispatch, useSelector} from "react-redux"; +import {getPosts} from "../actions/post.actions"; +import {getUserTemp} from "../actions/user.actions"; +import MiniProfil from "./MiniProfil"; -const Notif = ({notification} ) => { - const messageNotif = (typeNotif) =>{ - if(typeNotif == 'like') { +const Notif = ({notification} ) => { + console.log('notification',notification) + + + const MessageNotif = (notification) =>{ + if(notification.typeNotif == 'like') { return "a like"; } - return 'a commenter' + else if(notification.typeNotif == 'commente') { + return "a commenter votre post"; + } + return 'vous follow' } + return ( -
    +
    +
    - -
    -
    -
    - {notification.typeNotif} -
    -
    -
    - { - messageNotif(notification.typeNotif) - } + { MessageNotif(notification) }
    - ); }; diff --git a/Site Web/client/src/components/Post/NouveauDisplayPosts.js b/Site Web/client/src/components/Post/NouveauDisplayPosts.js index bdb651a0..a95c213d 100644 --- a/Site Web/client/src/components/Post/NouveauDisplayPosts.js +++ b/Site Web/client/src/components/Post/NouveauDisplayPosts.js @@ -26,6 +26,10 @@ const NouveauDisplayPosts = () => { return () => window.removeEventListener('scroll',loadMore); }, [loadPost,dispatch,count]) + if (!loadPost) { + return

    Loading...

    ; + } + return (
      diff --git a/Site Web/client/src/components/Routes/index.js b/Site Web/client/src/components/Routes/index.js index 2d30b656..43a3efe5 100644 --- a/Site Web/client/src/components/Routes/index.js +++ b/Site Web/client/src/components/Routes/index.js @@ -16,7 +16,7 @@ const index = () => { } /> } /> {/* } /> */} - } /> + } /> }/> diff --git a/Site Web/client/src/pages/Profil.js b/Site Web/client/src/pages/Profil.js index 6e2fa11a..ac383372 100644 --- a/Site Web/client/src/pages/Profil.js +++ b/Site Web/client/src/pages/Profil.js @@ -1,21 +1,34 @@ -import {React, useState} from 'react'; +import React,{useEffect, useState} from 'react'; + import { useDispatch, useSelector } from 'react-redux'; +import { useParams } from 'react-router-dom' import Navbar from '../components/Navbar'; -import { dateParser } from '../components/Utils'; +import {dateParser, isEmpty} from '../components/Utils'; import FollowHandler from '../components/UserProfil/FollowHandler'; import PostPersonnels from '../components/UserProfil/NavigationProfil/PostsPersonnels'; import DossierPersonnels from '../components/UserProfil/NavigationProfil/DossiersPersonnels'; import PostsLikes from '../components/UserProfil/NavigationProfil/PostsLikes'; +import MiniProfil from "../components/MiniProfil"; const Profil = () => { - const userData = useSelector((state) => state.user.user); - const usersData = useSelector((state) => state.users.users); - const dispatch = useDispatch(); + const { uid } = useParams(); + const [userData, setUserData] = useState(null); + + useEffect(() => { + async function fetchData() { + const response = await fetch(`${process.env.REACT_APP_API_URL}api/user/${uid}`); + const data = await response.json(); + setUserData(data); + } + fetchData(); + }, [uid]); + + const [followingPopup, setFollowingPopup] = useState(false); const [followerPopup, setFollowerPopup] = useState(false); const [dossierPersonnels,setdossierPersonnels ] = useState(false); const [postPersonnels,setpostPersonnels ] = useState(true); - const [postLikes,setpostLikes ] =useState(false) + const [postLikes,setpostLikes ] = useState(false) const handleModals = (e) => { if (e.target.id === "DossierPersonnels") { @@ -31,37 +44,39 @@ const Profil = () => { setpostPersonnels(false); setpostLikes(true); } - }; - + }; + if (!userData) { + return

      Loading...

      ; + } return ( <> {/*
      -

      Compte créé le : {dateParser(userData.createdAt)}

      +

      Compte créé le : {dateParser(userData.createdAt)}

      Profil

      {userData.pseudo}

      -

      @{userData.pseudo}

      +

      @{userData.pseudo}

      -
      setFollowingPopup(true)} className="bloc-aboonnements-abonner"> -
      {userData.following.length}
      -
      Abonnement
      +
      setFollowingPopup(true)} classNameName="bloc-aboonnements-abonner"> +
      {userData.following.length}
      +
      Abonnement
      -
      setFollowerPopup(true)} className="bloc-aboonnements-abonner"> -
      {userData.followers.length}
      -
      Abonnée
      +
      setFollowerPopup(true)} classNameName="bloc-aboonnements-abonner"> +
      {userData.followers.length}
      +
      Abonnée
      {followingPopup && ( -
      -
      +
      +

      Abonnements

      - setFollowingPopup(false)}> + setFollowingPopup(false)}> ✕
        @@ -72,7 +87,7 @@ const Profil = () => {
      • user-pic

        {user.pseudo}

        -
        +
      • @@ -86,10 +101,10 @@ const Profil = () => {
      )} {followerPopup && ( -
      -
      +
      +

      Abonnés

      - setFollowerPopup(false)}> + setFollowerPopup(false)}> ✕
        @@ -100,7 +115,7 @@ const Profil = () => {
      • user-pic

        {user.pseudo}

        -
        +
      • @@ -123,24 +138,24 @@ const Profil = () => {
        -
        - +
        +
        -
        -

        {userData.pseudo}

        +
        +

        {userData.pseudo}

        {/*

        suuu

        */}
        -
        - Suivre + + -
        -
        setFollowingPopup(true)}> +
        +
        setFollowingPopup(true)}>

        {userData.following.length}

        -

        Abonnements

        +

        Abonnements

        -
        setFollowerPopup(true)}> +
        setFollowerPopup(true)}>

        {userData.followers.length}

        -

        Abonnés

        +

        Abonnés

        {followingPopup && ( @@ -151,50 +166,42 @@ const Profil = () => { ✕
          - {usersData.map((user) => { - for (let i = 0; i < userData.following.length; i++) { - if (user._id === userData.following[i]) { - return ( -
        • - user-pic -

          {user.pseudo}

          -
          - -
          -
        • - ); - } + { + userData.following.map((follower, i) => { + return ( +
        • + +
          + +
          +
        • + ) + }) } - return null; - })}
        )} {followerPopup && ( -
        -
        +
        +

        Abonnés

        - setFollowerPopup(false)}> + setFollowerPopup(false)}> ✕
          - {usersData.map((user) => { - for (let i = 0; i < userData.followers.length; i++) { - if (user._id === userData.followers[i]) { - return ( -
        • - user-pic -

          {user.pseudo}

          -
          - -
          -
        • - ); + { + userData.followers.map((follower, i) => { + return ( +
        • + +
          + +
          +
        • + ) + }) } - } - return null; - })}
        @@ -202,29 +209,29 @@ const Profil = () => {
        - - -
        -
        + + +
        +
        -