diff --git a/src/components/Post/Post.jsx b/src/components/Post/Post.jsx
index bff078d..045f3e7 100644
--- a/src/components/Post/Post.jsx
+++ b/src/components/Post/Post.jsx
@@ -22,7 +22,7 @@ import {
// Components
import Comment from "../Comment/Comment";
-const Post = ({ post }) => {
+const Post = ({ post, reloadPage }) => {
const [isLiked, setLiked] = useState(false);
const [likeCount, setLikeCount] = useState(post.likes.count)
const [date, setDate] = useState();
@@ -63,6 +63,7 @@ const Post = ({ post }) => {
// Handle delete
const handleDelete = async() => {
await axios.post(`/api/posts/${post._id}/delete`, {}, axiosConfig);
+ reloadPage();
}
// Comment submit
@@ -88,6 +89,8 @@ const Post = ({ post }) => {
// Load API data
useEffect(() => {
+
+
// Check like status
const getLikeStatus = async () => {
try {
diff --git a/src/pages/Timeline/Timeline.jsx b/src/pages/Timeline/Timeline.jsx
index 6809cb9..887df16 100644
--- a/src/pages/Timeline/Timeline.jsx
+++ b/src/pages/Timeline/Timeline.jsx
@@ -13,25 +13,26 @@ import SuggestedUsers from "../../components/SuggestedUsers/SuggestedUsers";
const Timeline = () => {
const[loading, setLoadingState] = useState(true);
- const [timeline, setTimeline] = useState([]);
+ const[timeline, setTimeline] = useState([]);
+ const[reload, initReload] = useState(false);
+
+ const reloadPage = () => {
+ initReload(!reload);
+ }
- // Once on mount
useEffect(() => {
setLoadingState(true);
- // API function
const getTimeline = async () => {
try {
const response = await axios.get('/api/posts');
setTimeline(response.data);
setLoadingState(false);
} catch (err) {
- console.log(err);
+ alert(err);
}
}
- // Call API function
getTimeline();
-
- }, []);
+ }, [reload]);
return(
loading === true ?