diff --git a/Site Web/client/src/actions/post.actions.js b/Site Web/client/src/actions/post.actions.js index 46940b94..e42b12df 100644 --- a/Site Web/client/src/actions/post.actions.js +++ b/Site Web/client/src/actions/post.actions.js @@ -7,7 +7,22 @@ export const getPosts = (num) => { return axios .get(`${process.env.REACT_APP_API_URL}api/post/`) .then((res) => { - const array = res.data.slice(0, num); + let array = res.data.slice(0, num); + dispatch(setPostData(array)); + }) + .catch((err) => console.log(err)) + } +} + +export const getPostsDisc = (num) => { + return (dispatch) => { + return axios + .get(`${process.env.REACT_APP_API_URL}api/post/`) + .then((res) => { + console.log("test"); + let array = res.data.sort((a, b) => b.likers.length - a.likers.length); + array = array.slice(0, num); + console.log(array); dispatch(setPostData(array)); }) .catch((err) => console.log(err)) diff --git a/Site Web/client/src/components/Configurations/ConfigurationDuProfil.js b/Site Web/client/src/components/Configurations/ConfigurationDuProfil.js index 62bc15f3..fe05ce31 100644 --- a/Site Web/client/src/components/Configurations/ConfigurationDuProfil.js +++ b/Site Web/client/src/components/Configurations/ConfigurationDuProfil.js @@ -105,7 +105,7 @@ const ConfigurationDuProfil = ()=>{
- +
@@ -119,7 +119,7 @@ const ConfigurationDuProfil = ()=>{
diff --git a/Site Web/client/src/components/Post/ActionComment.js b/Site Web/client/src/components/Post/ActionComment.js index 5bb8c085..1b22a76c 100644 --- a/Site Web/client/src/components/Post/ActionComment.js +++ b/Site Web/client/src/components/Post/ActionComment.js @@ -1,6 +1,6 @@ import React, { useContext, useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; -import { deleteComment } from '../../actions/post.actions'; +import { deleteComment, editComment } from '../../actions/post.actions'; import { UidContext } from '../AppContext'; @@ -14,46 +14,48 @@ const ActionComment = ( { commentaire , postId}) => { const handleEdit = (e) => { e.preventDefault(); if(message){ - //dispatch(); + dispatch(editComment(postId, commentaire._id, message)); setMessage(''); setEdit(false); } }; const handleDelete = () => { - //dispatch(deleteComment(postId, commentaire._id)) + dispatch(deleteComment(postId, commentaire._id)); }; useEffect(() => { const verifCreateur = () => { - if(uid === commentaire.commenterId){ + if(uid === commentaire.commentId){ setCreateur(true); } } + console.log(commentaire); verifCreateur(); + console.log(createur); }, [uid, commentaire.commenterId]); return ( -
+
{createur && edit === false && ( setEdit(!edit)}> - editer + )} {createur && edit && (
+ className="edit-comment-form"> setMessage(e.target.value)} defaultValue={commentaire.text}/> - -
+
+
{ if(window.confirm("Etes-vous sur de supprimer ce commentaire ?")){ handleDelete(); } }}> - Icon supprimer +
diff --git a/Site Web/client/src/components/Post/Comment.js b/Site Web/client/src/components/Post/Comment.js index 76bac47c..b9a3b727 100644 --- a/Site Web/client/src/components/Post/Comment.js +++ b/Site Web/client/src/components/Post/Comment.js @@ -21,97 +21,68 @@ const Comment = ({ post }) => { } }; - return ( -
- {post.comments.map((comment) => { - return ( -
- ppCommentaire { - if (user._id === comment.commenterId) return user.picture; - else return null; - }).join('') - }/> -

{comment.commenterPseudo}

- {comment.commenterPseudo !== userData._id && ( - )} - - {timestampParser(comment.timestamp)} -

{comment.text}

- + return ( +
+ {post.comments.map((comment) => { + return ( +
+
+ { + if (user._id === comment.commenterId) return user.picture; + else return null; + }) + .join("") + } + alt="commenter-pic" + /> +
+
+
+
+

{comment.commenterPseudo}

+ {comment.commenterId !== userData._id && ( + + )}
- ); - })} - {userData._id && ( - - setMessage(e.target.value)} value={message} placeholder="Ajoutez un commentaire" /> - - - )} + {timestampParser(comment.timestamp)} +
+

{comment.text}

+ +
+
+ ); + })} + {userData._id && ( +
+ setMessage(e.target.value)} + value={message} + placeholder="Laisser un commentaire" + /> +
+ +
+ )}
- ); + ); }; -// return ( -//
-// {post.comments.map((comment) => { -// return ( -//
-//
-// { -// if (user._id === comment.commenterId) return user.picture; -// else return null; -// }) -// .join("") -// } -// alt="commenter-pic" -// /> -//
-//
-//
-//
-//

{comment.commenterPseudo}

-// {comment.commenterId !== userData._id && ( -// -// )} -//
-// {timestampParser(comment.timestamp)} -//
-//

{comment.text}

-// -//
-//
-// ); -// })} -// {userData._id && ( -//
-// setMessage(e.target.value)} -// value={message} -// placeholder="Laisser un commentaire" -// /> -//
-// -//
-// )} -//
-// ); + export default Comment; \ No newline at end of file diff --git a/Site Web/client/src/components/Post/DisplayPosts.js b/Site Web/client/src/components/Post/DisplayPosts.js index 170af9d8..97b25675 100644 --- a/Site Web/client/src/components/Post/DisplayPosts.js +++ b/Site Web/client/src/components/Post/DisplayPosts.js @@ -1,10 +1,10 @@ import React, { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { getPosts } from '../../actions/post.actions'; +import { getPosts, getPostsDisc } from '../../actions/post.actions'; import { isEmpty } from "../Utils"; import Post from './Post'; -const DisplayPosts = () => { +const DisplayPosts = ( {type} ) => { const [loadPost, setLoadPost] = useState(true); const [count , setCount] = useState(5); const dispatch = useDispatch(); @@ -21,7 +21,12 @@ const DisplayPosts = () => { } if (loadPost) { - dispatch(getPosts(count)); + if(type === "discover"){ + dispatch(getPostsDisc(count)); + } + else{ + dispatch(getPosts(count)); + } setLoadPost(false); setCount(count + 5); } diff --git a/Site Web/client/src/components/UserProfil/SuggestFriends.js b/Site Web/client/src/components/UserProfil/SuggestFriends.js index 0d79a235..d4651c7b 100644 --- a/Site Web/client/src/components/UserProfil/SuggestFriends.js +++ b/Site Web/client/src/components/UserProfil/SuggestFriends.js @@ -43,12 +43,9 @@ const SuggestFriends = () => { const stateTopFollowers = () => { let array = []; let obj = JSON.parse(JSON.stringify(usersData)); - console.log("obj"); - console.log(obj); obj.sort((a, b) => b.followers.length - a.followers.length); - console.log(obj); obj.map((user) => { - if(user._id !== userData._id){ + if(user._id !== userData._id && !user.followers.includes(userData._id)){ return array.push(user._id); } }) @@ -69,19 +66,19 @@ const SuggestFriends = () => { }, [userData, usersData, change]) return ( -
-
+
+
Vous pourriez suivre
{chargement ? ( ) : ( -
+
{friends && friends.map((user) => { for(let i = 0; i < usersData.length; i++){ if(user === usersData[i]._id){ return ( -
+
img

{usersData[i].pseudo}

diff --git a/Site Web/client/src/pages/Discover.js b/Site Web/client/src/pages/Discover.js index 76b82952..ac7f06f0 100644 --- a/Site Web/client/src/pages/Discover.js +++ b/Site Web/client/src/pages/Discover.js @@ -9,7 +9,7 @@ const Discover = () => {
- +
diff --git a/Site Web/client/src/pages/Home.js b/Site Web/client/src/pages/Home.js index 2ad27e0f..484842b9 100644 --- a/Site Web/client/src/pages/Home.js +++ b/Site Web/client/src/pages/Home.js @@ -12,7 +12,7 @@ const Home = () => {
- +
diff --git a/Site Web/controllers/post.controller.js b/Site Web/controllers/post.controller.js index 36fa4732..aeb07920 100644 --- a/Site Web/controllers/post.controller.js +++ b/Site Web/controllers/post.controller.js @@ -175,8 +175,8 @@ module.exports.commentPost = (req, res) => { { $push: { comments: { - commenterId: req.body.commenterId, - commenterPseudo: req.body.commenterPseudo, + commentId: req.body.commenterId, + commentPseudo: req.body.commenterPseudo, text: req.body.text, timestamp: new Date().getTime(), },