amélioration affichage notif
continuous-integration/drone/push Build encountered an error Details

master
Bastien OLLIER 2 years ago
parent e80ed4149e
commit 5de0542907

@ -49,11 +49,11 @@ export const addPost = (data) => {
.post(`${process.env.REACT_APP_API_URL}api/post/`, data) .post(`${process.env.REACT_APP_API_URL}api/post/`, data)
.then((res) => { .then((res) => {
console.log(data,"test"); console.log(data,"test");
/* if (res.data.errors) { if (res.data.errors) {
dispatch(setPostError({payload: res.data.errors })); dispatch(setPostError({payload: res.data.errors }));
} else { } else {
dispatch(setPostError({payload: "" })); dispatch(setPostError({payload: "" }));
}*/ }
}); });
}; };
}; };

@ -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) => { export const uploadPicture = (data, id) => {

@ -19,14 +19,13 @@ const AjoutLien = () => {
dispatch(getPosts()); dispatch(getPosts());
cancelPost(); cancelPost();
setDisplayAdd(false); setDisplayAdd(false);
/* window.location.reload();*/ window.location.reload();
}else { }else {
alert("Veuillez compléter tous les champs.") alert("Veuillez compléter tous les champs.")
} }
else{ else{
alert("Ce n'est pas lien!") alert("Ce n'est pas lien!")
} }
}; };

@ -1,11 +1,13 @@
import React, {useEffect} from 'react'; import React from 'react';
import {isEmpty} from "./Utils"; import {isEmpty} from "./Utils";
import {useSelector} from "react-redux";
import axios from "axios";
import { useDispatch } from 'react-redux'; const Notif = ({notification} ) => {
const messageNotif = (typeNotif) =>{
const Notif = ({message} ) => { if(typeNotif == 'like') {
return "a like";
}
return 'a commenter'
}
return ( return (
<div className='conteneur_notif'> <div className='conteneur_notif'>
<div className={'contenue_notif'}> <div className={'contenue_notif'}>
@ -13,11 +15,13 @@ const Notif = ({message} ) => {
</div> </div>
<div className={'contenue_notif'} > <div className={'contenue_notif'} >
<h6 id="NomProfile"> <h6 id="NomProfile">
bastien {notification.typeNotif}
</h6> </h6>
</div> </div>
<div className={'contenue_notif'}> <div className={'contenue_notif'}>
{message} {
messageNotif(notification.typeNotif)
}
</div> </div>
</div> </div>

@ -1,8 +1,69 @@
import React from 'react'; import React, {useEffect, useState} from 'react';
import Navbar from '../components/Navbar'; import Navbar from '../components/Navbar';
import Notif from '../components/Notif'; 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 = () => { 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 (
<div id={'listeNotif'}>
<Navbar />
<h1>Notification</h1>
{ /*userData.notif.length ? userData.notif.filter(notif => notif._id === userData.notif._id).map((notif) => <Notif message="dfdf"/>)
: <h3>Aucune Notification</h3>*/
userData.notif != null && userData.notif.map((notif) => {
return <Notif notification={notif}/>
})
}
</div>
);
/*
return (
<div id={'listeNotif'}>
<Navbar />
<h1>Notification</h1>
{
return(<h3>Aucune Notification</h3>);
userData.notif.map((notif) => {
for (let i = 0; i < userData.notif.length; i++) {
if (notif._id === userData.notif[i]) {
return (
<Notif message="dfdf"/>
);
}
}
return <h3>Aucune Notification</h3>;
})
}
</div>
);*/
return ( return (
<div id={'listeNotif'}> <div id={'listeNotif'}>
<Navbar /> <Navbar />

@ -31,17 +31,29 @@ module.exports.signUp = async (req, res) => {
} }
module.exports.signIn = async (req, res) => { module.exports.signIn = async (req, res) => {
console.log(req.body); console.log("signin: ",req.body);
const {email, password} = req.body const {email, password} = req.body
try { try {
console.log("test user1 ");
const user = await UserModel.login({email, password}); const user = await UserModel.login({email, password});
console.log("test user2 ");
//creation d'un token //creation d'un token
const token = createToken(user._id); const token = createToken(user._id);
console.log("test user3 ");
res.cookie('jwt', token, { httpOnly: true, maxAge}); res.cookie('jwt', token, { httpOnly: true, maxAge});
console.log("test user4 ");
res.status(200).json({ user: user._id}); res.status(200).json({ user: user._id});
} }
catch(err) { catch(err) {
const errors = signInErrors(err); const errors = signInErrors(err);
console.log("echec test user ",errors);
res.status(200).send({ errors }); res.status(200).send({ errors });
} }
} }

@ -1,12 +1,10 @@
const UserModel = require("../models/user.model"); const UserModel = require("../models/user.model");
const PostModel = require("../models/post.model");
module.exports.addNotification = (userId, notification) => { module.exports.addNotification = async (userId, notification) => {
UserModel.findById(userId, (err, user) => { await UserModel.findByIdAndUpdate(
if (err) { userId,
console.log(err); { $addToSet: { notif: notification } },
} else { { new: true, upsert: true }
user.notif.push(notification); );
user.save();
}
});
}; };

@ -68,7 +68,7 @@ module.exports.deletePost = (req, res) => {
module.exports.likePost = async (req, res) => { module.exports.likePost = async (req, res) => {
//notif //notif
const idUser = await PostModel.findOne({ _id: ObjectID( req.params.id) }); const idUser = await PostModel.findOne({ _id: ObjectID( req.params.id) });
console.log(idUser); console.log("like",idUser);
addNotification.addNotification(idUser.postedId, { addNotification.addNotification(idUser.postedId, {
typeNotif: "like", typeNotif: "like",
id_user: req.body.id, id_user: req.body.id,

@ -7,6 +7,13 @@ module.exports.getAllUsers = async (req, res) => {
res.status(200).json(users); 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 //req.params par url
module.exports.userInfo = (req, res) => { module.exports.userInfo = (req, res) => {
if (!ObjectID.isValid(req.params.id)) if (!ObjectID.isValid(req.params.id))

@ -20,6 +20,7 @@ router.put('/:id', userController.updateUser);
router.delete('/:id', userController.deleteUser); router.delete('/:id', userController.deleteUser);
router.patch('/follow/:id', userController.follow); router.patch('/follow/:id', userController.follow);
router.patch('/unfollow/:id', userController.unfollow); router.patch('/unfollow/:id', userController.unfollow);
router.patch('/notif/:id', userController.getNotif);
//upload pb avec postman //upload pb avec postman
router.post("/upload", upload.single('file'), uploadController.uploadProfil); router.post("/upload", upload.single('file'), uploadController.uploadProfil);

Loading…
Cancel
Save