Merge branch 'master' of https://codefirst.iut.uca.fr/git/noan.randon/Favor
continuous-integration/drone/push Build encountered an error
Details
continuous-integration/drone/push Build encountered an error
Details
commit
b92ae332da
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -1,45 +0,0 @@
|
|||||||
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 <p>Loading...</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<ul>
|
|
||||||
{!isEmpty(postsData[0]) &&
|
|
||||||
postsData.map((post) => {
|
|
||||||
return <Post post={post} key={post._id}/>
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NouveauDisplayPosts;
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue