Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
amsierco committed Aug 12, 2023
1 parent 39fdd95 commit 0d19a65
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -63,6 +63,7 @@ const Post = ({ post }) => {
// Handle delete
const handleDelete = async() => {
await axios.post(`/api/posts/${post._id}/delete`, {}, axiosConfig);
reloadPage();
}

// Comment submit
Expand All @@ -88,6 +89,8 @@ const Post = ({ post }) => {

// Load API data
useEffect(() => {


// Check like status
const getLikeStatus = async () => {
try {
Expand Down
17 changes: 9 additions & 8 deletions src/pages/Timeline/Timeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? <Loading /> :
Expand All @@ -41,7 +42,7 @@ const Timeline = () => {
{timeline.map(post => {
return (
<li key={post._id}>
<Post post={post}/>
<Post post={post} reloadPage={reloadPage}/>
</li>
);
})}
Expand Down
1 change: 0 additions & 1 deletion src/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ body,
--icon-post-size: 5rem;

color: var(--dark-gray);
background-color: #FFFFFF;

width: 100vw;
height: 100vh;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ImageFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const ImageFormat = (img) => {
// Returns guest img if undefined
if(undefined === img){
return {
backgroundImage: `url(${'../../public/user-solid.svg'})`,
backgroundImage: `url(${'../../user-solid.svg'})`,
backgroundSize: 'contain',
backgroundPositionY: '3px',
backgroundColor: 'var(--medium-gray)'
}
}

// Determine if img type is url or base64
// Determine if img type is url or base64 and return corresponding style
if(img.substring(0,4) === 'http'){
return { backgroundImage: `url(${img})` }
} else {
Expand Down

0 comments on commit 0d19a65

Please sign in to comment.