From 0d19a65d8d140c5e801ab6a1dfd4bb18189052cd Mon Sep 17 00:00:00 2001
From: Austin <75064473+amsierco@users.noreply.github.com>
Date: Sat, 12 Aug 2023 18:52:14 -0400
Subject: [PATCH] save
---
src/components/Post/Post.jsx | 5 ++++-
src/pages/Timeline/Timeline.jsx | 17 +++++++++--------
src/root.css | 1 -
src/utils/ImageFormat.js | 4 ++--
4 files changed, 15 insertions(+), 12 deletions(-)
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 ?