diff --git a/Site Web/client/src/actions/user.actions.js b/Site Web/client/src/actions/user.actions.js index c208c591..aa0a1414 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 ea76df87..4ef8e33f 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.") } @@ -70,7 +70,7 @@ const AjoutLien = () => { } {displayAdd && ( -
+

Ajout d'un lien

setDisplayAdd(false)}> 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 ( +
+ +
+ ); +}; + +export default MiniProfil; diff --git a/Site Web/client/src/components/Navbar.js b/Site Web/client/src/components/Navbar.js index 89b0cbe4..d5a4eae0 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(); @@ -78,7 +78,6 @@ const Navbar = () => { window.location = "/"; } - return (
{uid ? ( @@ -110,7 +109,7 @@ const Navbar = () => {
  • - + Me diff --git a/Site Web/client/src/components/Notif.js b/Site Web/client/src/components/Notif.js index 52316d9f..8616aede 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') { - return "a like"; +const Notif = ({notification} ) => { + console.log('notification',notification) + + + const MessageNotif = (notification) =>{ + if(notification.typeNotif == 'like') { + return "a like votre post"; } - 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 new file mode 100644 index 00000000..a95c213d --- /dev/null +++ b/Site Web/client/src/components/Post/NouveauDisplayPosts.js @@ -0,0 +1,45 @@ +import React, { useEffect, useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { getPosts } from '../../actions/post.actions'; +import { isEmpty } from "../Utils"; +import Post from './PostNouvelleAffichage'; + +const NouveauDisplayPosts = () => { + const [loadPost, setLoadPost] = useState(true); + const [count , setCount] = useState(5); + const dispatch = useDispatch(); + const postsData = useSelector((state) => state.post.post); + + const loadMore = () => { + if (window.innerHeight + document.documentElement.scrollTop + 1 > document.scrollingElement.scrollHeight){ + setLoadPost(true); + } + } + + useEffect(() => { + if (loadPost) { + dispatch(getPosts(count)); + setLoadPost(false); + setCount(count + 5); + } + window.addEventListener('scroll', loadMore); + return () => window.removeEventListener('scroll',loadMore); + }, [loadPost,dispatch,count]) + + if (!loadPost) { + return

    Loading...

    ; + } + + return ( +
    +
      + {!isEmpty(postsData[0]) && + postsData.map((post) => { + return + })} +
    +
    + ); +}; + +export default NouveauDisplayPosts; \ No newline at end of file diff --git a/Site Web/client/src/components/Post/Post.js b/Site Web/client/src/components/Post/Post.js index c0899def..143ed619 100644 --- a/Site Web/client/src/components/Post/Post.js +++ b/Site Web/client/src/components/Post/Post.js @@ -6,6 +6,7 @@ import { dateParser, isEmpty } from '../Utils'; import ButtonLike from './ButtonLike'; import Comment from './Comment'; import Commentaire from '../../assets/img/commentaire.png'; +import MiniProfil from "../MiniProfil"; const LinkPreview = ({ link }) => { const [preview, setPreview] = useState({ image: '', title: '', description: '' }); @@ -63,24 +64,8 @@ const Post = ( { post } ) => {
    - { - if (user._id === post.postedId) return user.picture; - else return null; - }).join('') - }/> -
    - { - !isEmpty(usersData[0]) && - usersData.map((user) => { - if(user._id === post.postedId) return user.pseudo; - else return null; - }).join('') - } -
    - {post.postedId !== userData._id && - ()} + + {post.postedId !== userData._id && ()}
    {dateParser(post.createdAt)}
    diff --git a/Site Web/client/src/components/Routes/index.js b/Site Web/client/src/components/Routes/index.js index 581b316a..254b0168 100644 --- a/Site Web/client/src/components/Routes/index.js +++ b/Site Web/client/src/components/Routes/index.js @@ -18,7 +18,7 @@ const index = () => { } /> } /> {/* } /> */} - } /> + } /> }/> diff --git a/Site Web/client/src/pages/Profil.js b/Site Web/client/src/pages/Profil.js index 1bd20af5..ac383372 100644 --- a/Site Web/client/src/pages/Profil.js +++ b/Site Web/client/src/pages/Profil.js @@ -1,25 +1,36 @@ -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 LesPostPersonnels from '../components/UserProfil/NavigationProfil/PostsPersonnels'; -import LesDossierPersonnels from '../components/UserProfil/NavigationProfil/DossiersPersonnels'; -import LesPostsLikes from '../components/UserProfil/NavigationProfil/PostsLikes'; +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 [followingPopup, setFollowingPopup] = useState(false); - const [followerPopup, setFollowerPopup] = useState(false); + 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 [dossierPersonnel,setdossierPersonnels ] = useState(true); - const [postPersonnel,setpostPersonnels ] = useState(false); - const [postLike,setpostLikes ] =useState(false); + 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 handleModalsProfil = (e) => { + const handleModals = (e) => { if (e.target.id === "DossierPersonnels") { setdossierPersonnels(true); setpostPersonnels(false); @@ -33,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)}> ✕
      @@ -74,7 +87,7 @@ const Profil = () => {
    • user-pic

      {user.pseudo}

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

    Abonnés

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

      {user.pseudo}

      -
      +
    • @@ -125,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 && ( @@ -153,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; - })}
      @@ -204,54 +209,55 @@ const Profil = () => {
      - - -
      -
      + + +
      +
      - -
      -
      +
      +
      Vous pourriez suivre
      -
      -
      - +
      +
      + UtiT - Suivre + Suivre
      -
      - +
      + UtiT - Suivre + Suivre
      -
      - +
      + UtiT - Suivre + Suivre
      diff --git a/Site Web/client/src/pages/Trends.js b/Site Web/client/src/pages/Trends.js index 1d3ca6c4..0ae4975a 100644 --- a/Site Web/client/src/pages/Trends.js +++ b/Site Web/client/src/pages/Trends.js @@ -1,80 +1,29 @@ -import React, {useEffect, useState} from 'react'; +import React, {useState} from 'react'; import Navbar from '../components/Navbar'; import Notif from '../components/Notif'; -import {useDispatch, useSelector} from "react-redux"; -import {getNotif, getUser} from '../actions/user.actions'; -import {isEmpty} from "../components/Utils"; -import axios from "axios"; -import FollowHandler from "../components/UserProfil/FollowHandler"; -import Post from "../components/Post/Post"; +import {useSelector} from "react-redux"; const Trends = () => { - console.log('test'); - const [loadNotif, setLoadNotif] = useState(true); - const [count , setCount] = useState(5); - const dispatch = useDispatch(); - + const [setLoadNotif] = useState(true); const userData = useSelector((state) => state.user.user); - const usersData = useSelector((state) => state.users.users); - - const loadMore = () => { - if (window.innerHeight + document.documentElement.scrollTop + 1 > document.scrollingElement.scrollHeight){ - setLoadNotif(true); - } - } - - console.log("userData",userData,userData.notif, userData.notif.length); return (

      Notification

      - { /*userData.notif.length ? userData.notif.filter(notif => notif._id === userData.notif._id).map((notif) => ) - :

      Aucune Notification

      */ - + { userData.notif != null && userData.notif.map((notif) => { - return + return ( +
    • + +
    • + ); }) }
      ); - - - /* - return ( -
      - -

      Notification

      - { - return(

      Aucune Notification

      ); - userData.notif.map((notif) => { - for (let i = 0; i < userData.notif.length; i++) { - if (notif._id === userData.notif[i]) { - return ( - - - ); - } - } - return

      Aucune Notification

      ; - }) - } -
      - );*/ - - // return ( - //
      - // - //

      Notification

      - // - // - // - // - // - // - //
      ); }; export default Trends; \ No newline at end of file diff --git a/Site Web/controllers/post.controller.js b/Site Web/controllers/post.controller.js index aeb07920..03d83b30 100644 --- a/Site Web/controllers/post.controller.js +++ b/Site Web/controllers/post.controller.js @@ -165,7 +165,9 @@ module.exports.unlikePost = async (req, res) => { // } // }; -module.exports.commentPost = (req, res) => { +module.exports.commentPost = async (req, res) => { + const idUser = await PostModel.findOne({ _id: ObjectID( req.params.id) }); + if (!ObjectID.isValid(req.params.id)) return res.status(400).send("ID unknown : " + req.params.id); @@ -183,7 +185,14 @@ module.exports.commentPost = (req, res) => { }, }, { new: true }) - .then((data) => res.send(data)) + .then((data) => { + addNotification.addNotification(idUser.postedId, { + typeNotif: "commente", + id_user: req.body.commenterId, + id_post1: req.params.id, + id_post2: data.comments.slice(-1)[0]._id + }); + res.send(data);}) .catch((err) => res.status(500).send({ message: err })); } catch (err) { return res.status(400).send(err); diff --git a/Site Web/controllers/user.controller.js b/Site Web/controllers/user.controller.js index ae9ed671..ee192b5c 100644 --- a/Site Web/controllers/user.controller.js +++ b/Site Web/controllers/user.controller.js @@ -8,9 +8,7 @@ module.exports.getAllUsers = async (req, res) => { }; module.exports.getNotif = async (req, res) => { - const users = await UserModel.find().select("-password"); - console.log('api get notif',users); res.status(200).json(users); }; @@ -18,10 +16,15 @@ module.exports.getNotif = async (req, res) => { module.exports.userInfo = (req, res) => { if (!ObjectID.isValid(req.params.id)) return res.status(400).send("ID unknown : " + req.params.id); + console.log('userinfo:',req.params.id) UserModel.findById(req.params.id, (err, docs) => { - if (!err) res.send(docs); - else console.log("ID unknown : " + err); + if (!err) { + console.log('doc:',docs) + res.send(docs); + } + else + console.log("ID unknown : " + err); }).select("-password"); };