diff --git a/Site Web/client/src/actions/post.actions.js b/Site Web/client/src/actions/post.actions.js
index 999a1d75..46940b94 100644
--- a/Site Web/client/src/actions/post.actions.js
+++ b/Site Web/client/src/actions/post.actions.js
@@ -49,11 +49,11 @@ export const addPost = (data) => {
.post(`${process.env.REACT_APP_API_URL}api/post/`, data)
.then((res) => {
console.log(data,"test");
- /* if (res.data.errors) {
+ if (res.data.errors) {
dispatch(setPostError({payload: res.data.errors }));
} else {
dispatch(setPostError({payload: "" }));
- }*/
+ }
});
};
};
diff --git a/Site Web/client/src/actions/user.actions.js b/Site Web/client/src/actions/user.actions.js
index ff7e48ce..8b0f42fd 100644
--- a/Site Web/client/src/actions/user.actions.js
+++ b/Site Web/client/src/actions/user.actions.js
@@ -13,6 +13,18 @@ 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) => {
diff --git a/Site Web/client/src/components/AjoutLien.js b/Site Web/client/src/components/AjoutLien.js
index c7d6ff27..4ef8e33f 100644
--- a/Site Web/client/src/components/AjoutLien.js
+++ b/Site Web/client/src/components/AjoutLien.js
@@ -19,14 +19,13 @@ const AjoutLien = () => {
dispatch(getPosts());
cancelPost();
setDisplayAdd(false);
- /* window.location.reload();*/
+ window.location.reload();
}else {
alert("Veuillez compléter tous les champs.")
}
else{
alert("Ce n'est pas lien!")
}
-
};
diff --git a/Site Web/client/src/components/Notif.js b/Site Web/client/src/components/Notif.js
index 22d9cf41..52316d9f 100644
--- a/Site Web/client/src/components/Notif.js
+++ b/Site Web/client/src/components/Notif.js
@@ -1,11 +1,13 @@
-import React, {useEffect} from 'react';
+import React from 'react';
import {isEmpty} from "./Utils";
-import {useSelector} from "react-redux";
-import axios from "axios";
-import { useDispatch } from 'react-redux';
-
-const Notif = ({message} ) => {
+const Notif = ({notification} ) => {
+ const messageNotif = (typeNotif) =>{
+ if(typeNotif == 'like') {
+ return "a like";
+ }
+ return 'a commenter'
+ }
return (
@@ -13,11 +15,13 @@ const Notif = ({message} ) => {
- bastien
+ {notification.typeNotif}
- {message}
+ {
+ messageNotif(notification.typeNotif)
+ }
diff --git a/Site Web/client/src/pages/Trends.js b/Site Web/client/src/pages/Trends.js
index 34376b44..9a53390e 100644
--- a/Site Web/client/src/pages/Trends.js
+++ b/Site Web/client/src/pages/Trends.js
@@ -1,8 +1,69 @@
-import React from 'react';
+import React, {useEffect, 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";
+
const Trends = () => {
+ console.log('test');
+ const [loadNotif, setLoadNotif] = useState(true);
+ const [count , setCount] = useState(5);
+ const dispatch = useDispatch();
+
+ 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 (
+
+
+
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 (
diff --git a/Site Web/controllers/auth.controller.js b/Site Web/controllers/auth.controller.js
index 2f380fba..84d34716 100644
--- a/Site Web/controllers/auth.controller.js
+++ b/Site Web/controllers/auth.controller.js
@@ -31,17 +31,29 @@ module.exports.signUp = async (req, res) => {
}
module.exports.signIn = async (req, res) => {
- console.log(req.body);
+ console.log("signin: ",req.body);
const {email, password} = req.body
try {
+ console.log("test user1 ");
+
const user = await UserModel.login({email, password});
+ console.log("test user2 ");
+
+
//creation d'un token
const token = createToken(user._id);
+ console.log("test user3 ");
+
res.cookie('jwt', token, { httpOnly: true, maxAge});
+ console.log("test user4 ");
+
res.status(200).json({ user: user._id});
}
catch(err) {
+
const errors = signInErrors(err);
+ console.log("echec test user ",errors);
+
res.status(200).send({ errors });
}
}
diff --git a/Site Web/controllers/notifFonction.js b/Site Web/controllers/notifFonction.js
index 993622ac..97e66c63 100644
--- a/Site Web/controllers/notifFonction.js
+++ b/Site Web/controllers/notifFonction.js
@@ -1,12 +1,10 @@
const UserModel = require("../models/user.model");
+const PostModel = require("../models/post.model");
-module.exports.addNotification = (userId, notification) => {
- UserModel.findById(userId, (err, user) => {
- if (err) {
- console.log(err);
- } else {
- user.notif.push(notification);
- user.save();
- }
- });
+module.exports.addNotification = async (userId, notification) => {
+ await UserModel.findByIdAndUpdate(
+ userId,
+ { $addToSet: { notif: notification } },
+ { new: true, upsert: true }
+ );
};
\ No newline at end of file
diff --git a/Site Web/controllers/post.controller.js b/Site Web/controllers/post.controller.js
index f218b189..36fa4732 100644
--- a/Site Web/controllers/post.controller.js
+++ b/Site Web/controllers/post.controller.js
@@ -68,7 +68,7 @@ module.exports.deletePost = (req, res) => {
module.exports.likePost = async (req, res) => {
//notif
const idUser = await PostModel.findOne({ _id: ObjectID( req.params.id) });
- console.log(idUser);
+ console.log("like",idUser);
addNotification.addNotification(idUser.postedId, {
typeNotif: "like",
id_user: req.body.id,
diff --git a/Site Web/controllers/user.controller.js b/Site Web/controllers/user.controller.js
index 20e57a56..c762ea97 100644
--- a/Site Web/controllers/user.controller.js
+++ b/Site Web/controllers/user.controller.js
@@ -7,6 +7,13 @@ module.exports.getAllUsers = async (req, res) => {
res.status(200).json(users);
};
+module.exports.getNotif = async (req, res) => {
+
+ const users = await UserModel.find().select("-password");
+ console.log('api get notif',users);
+ res.status(200).json(users);
+};
+
//req.params par url
module.exports.userInfo = (req, res) => {
if (!ObjectID.isValid(req.params.id))
diff --git a/Site Web/routes/user.routes.js b/Site Web/routes/user.routes.js
index a2ab8860..b9b93be3 100644
--- a/Site Web/routes/user.routes.js
+++ b/Site Web/routes/user.routes.js
@@ -20,6 +20,7 @@ router.put('/:id', userController.updateUser);
router.delete('/:id', userController.deleteUser);
router.patch('/follow/:id', userController.follow);
router.patch('/unfollow/:id', userController.unfollow);
+router.patch('/notif/:id', userController.getNotif);
//upload pb avec postman
router.post("/upload", upload.single('file'), uploadController.uploadProfil);