diff --git a/client/src/App.js b/client/src/App.js index 65ad5ce..8b87f3c 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -49,7 +49,7 @@ function App() { - + diff --git a/client/src/views/communityDetail/CommunityDetailScreen.js b/client/src/views/communityDetail/CommunityDetailScreen.js index 2a73950..c42d303 100644 --- a/client/src/views/communityDetail/CommunityDetailScreen.js +++ b/client/src/views/communityDetail/CommunityDetailScreen.js @@ -44,7 +44,7 @@ const CommunityDetailScreen = ({ community, posts }) => { {/* ===== TOOLBAR ===== */}
- + { - + { - + { const [posts, setPosts] = useState(null); - let { id } = useParams(); + let { id, category } = useParams(); const [token] = useLocalStorage('token'); const [refreshEdit, setRefreshEdit] = useState(''); - // const [refreshPost, setRefreshPost] = useState('') const handleEdit = async (data) => { setRefreshEdit(''); @@ -23,7 +22,6 @@ const CommunityPosts = () => { const response = await editPost(token, id, data._id, postData); setRefreshEdit(response.message); toastr['success'](response.message); - // alert(response.message) }; const handleGetPosts = async () => { @@ -31,11 +29,27 @@ const CommunityPosts = () => { return response; }; + let filterBy; + switch (category) { + case 'social': + filterBy = 'Social Events'; + break; + case 'incidents': + filterBy = 'Incident Reports'; + break; + case 'discussions': + filterBy = 'Discussions'; + break; + default: + filterBy = ''; + } + useEffect(() => { (async () => { const data = await handleGetPosts(); - console.log(data); - setPosts(data); + const filteredPosts = data.filter((post) => post.category === filterBy); + console.log(filteredPosts); + setPosts(filteredPosts); })(); console.log(posts); //eslint-disable-next-line @@ -46,6 +60,7 @@ const CommunityPosts = () => { posts={posts} handleEdit={handleEdit} setRefreshEdit={setRefreshEdit} + category={filterBy} /> ); }; diff --git a/client/src/views/communityPost/CommunityPostScreen.js b/client/src/views/communityPost/CommunityPostScreen.js index f0cb532..3202df2 100644 --- a/client/src/views/communityPost/CommunityPostScreen.js +++ b/client/src/views/communityPost/CommunityPostScreen.js @@ -1,30 +1,35 @@ -import React, { useState } from "react" -import CreatePostModal from "../../components/CreatePostModal" -import PostCard from "../../components/PostCard" -import { useHistory } from "react-router-dom" +import React, { useState } from 'react'; +import CreatePostModal from '../../components/CreatePostModal'; +import PostCard from '../../components/PostCard'; +import { useHistory } from 'react-router-dom'; -const CommunityPostScreen = ({ posts, handleEdit, setRefreshEdit }) => { - const [show, setShow] = useState(false) - const handleShow = () => setShow(true) - const history = useHistory() +const CommunityPostScreen = ({ + posts, + handleEdit, + setRefreshEdit, + category, +}) => { + const [show, setShow] = useState(false); + const handleShow = () => setShow(true); + const history = useHistory(); return (
-
+
-
-

Posts

+

{category}

{ />
- {posts?.map((post) => ( - - ))} + {posts?.length ? ( + posts?.map((post) => ( + + )) + ) : ( +
+ Looks like there are no posts yet... +
+ )}
- ) -} + ); +}; -export default CommunityPostScreen +export default CommunityPostScreen;