From f05a1a0d14703c3a8ffaef57560b67bec9c057af Mon Sep 17 00:00:00 2001 From: Noan07 <84435602+Noan07@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:23:09 +0100 Subject: [PATCH] ajout post --- Site Web/client/src/actions/post.actions.js | 9 +- Site Web/client/src/components/AjoutLien.js | 51 ++++++++--- Site Web/client/src/components/Navbar.js | 51 +---------- Site Web/client/src/components/NewPoste.js | 3 - .../client/src/components/Post/ButtonLike.js | 61 +++++++------ .../src/components/Post/DisplayPosts.js | 7 +- Site Web/client/src/components/Post/Post.js | 4 - .../components/UserProfil/FollowHandler.js | 3 +- Site Web/client/src/pages/SearchBar.js | 89 +++++++++++-------- Site Web/client/src/reducers/post.reducer.js | 14 +-- Site Web/client/src/styles/_settings.scss | 1 + Site Web/client/src/styles/index.scss | 2 +- Site Web/client/src/styles/pages/_profil.scss | 1 + .../client/src/styles/pages/_searchBar.scss | 23 +++++ Site Web/controllers/auth.controller.js | 4 - Site Web/controllers/post.controller.js | 1 + Site Web/controllers/user.controller.js | 2 - Site Web/models/post.model.js | 6 +- Site Web/models/user.model.js | 1 - 19 files changed, 169 insertions(+), 164 deletions(-) create mode 100644 Site Web/client/src/styles/pages/_searchBar.scss diff --git a/Site Web/client/src/actions/post.actions.js b/Site Web/client/src/actions/post.actions.js index e42b12df..2e856650 100644 --- a/Site Web/client/src/actions/post.actions.js +++ b/Site Web/client/src/actions/post.actions.js @@ -19,10 +19,13 @@ export const getPostsDisc = (num) => { 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); + let currentTime = new Date().getTime(); + let array = res.data.filter(post => { + let postTime = new Date(post.createdAt); + return (currentTime - postTime) / (1000 * 60 * 60) < 24 + }); + array = array.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/AjoutLien.js b/Site Web/client/src/components/AjoutLien.js index 4ef8e33f..630d2924 100644 --- a/Site Web/client/src/components/AjoutLien.js +++ b/Site Web/client/src/components/AjoutLien.js @@ -10,33 +10,43 @@ const AjoutLien = () => { const [displayAdd, setDisplayAdd] = useState(false); const [lien, setLien] = useState(""); const [description, setDescription] = useState(""); + const [tag, setTag] = useState(''); + const [tags, setTags] = useState([]); const dispatch = useDispatch(); + const handleSubmit = (e) => { + e.preventDefault(); + setTags([...tags, tag]); + setTag(''); + } + + + const handlePost = async () => { - if(isValidUrl(lien)) - if ((description || lien) ){ - putData(); - dispatch(getPosts()); - cancelPost(); - setDisplayAdd(false); - window.location.reload(); - }else { - alert("Veuillez compléter tous les champs.") + if(isValidUrl(lien)){ + if ((description || lien) && tags.length > 0){ + putData(); + dispatch(getPosts()); + cancelPost(); + setDisplayAdd(false); + window.location.reload(); + }else { + alert("Veuillez compléter tous les champs et ajouter au moins un tag.") + } + }else{ + alert("Veuillez saisir un lien valide.") } - else{ - alert("Ce n'est pas lien!") - } }; - const cancelPost = () => { setDescription(""); setLien(""); + setTags([]); }; const putData = async() => { axios - .post(`${process.env.REACT_APP_API_URL}api/post/`, { postedId: userData._id, message: description, lien: lien} + .post(`${process.env.REACT_APP_API_URL}api/post/`, { postedId: userData._id, message: description, lien: lien, tags: tags} ) .then((res) => { // if (res.data.errors) { @@ -95,6 +105,19 @@ const AjoutLien = () => { /> + setTag(e.target.value)} + /> + Add Tag + +