Skip to content

Commit

Permalink
hide edit and delete button for anonymous user (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jren791 authored Apr 28, 2020
1 parent 4868662 commit a7eb654
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions frontend/src/pages/Frontpage/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,41 @@ const Post = ({
// window.location.reload();
// };

const handleButtonsShow = () => {
if (!document.cookie) return null;
const storedPostTypes = JSON.parse(localStorage.getItem('firebaseui::rememberedAccounts'));
if (!storedPostTypes) return null;

return (
<>
<div className={styles['post-edit-button']}>
<Button
variant="contained"
size="small"
startIcon={<EditIcon />}
onClick={() => {
setModal(true);
}}
>
Edit
</Button>
</div>
<div className={styles['post-delete-button']}>
<Button
variant="contained"
size="small"
startIcon={<DeleteIcon />}
onClick={() => {
setDeleteModal(true);
}}
>
Delete
</Button>
</div>
</>
);
};

return (
<Card className={styles.root}>
<div className={styles['post-box']}>
Expand Down Expand Up @@ -167,30 +202,7 @@ const Post = ({
{content}
</Typography>
</div>
<div className={styles['post-edit-button']}>
<Button
variant="contained"
size="small"
startIcon={<EditIcon />}
onClick={() => {
setModal(true);
}}
>
Edit
</Button>
</div>
<div className={styles['post-delete-button']}>
<Button
variant="contained"
size="small"
startIcon={<DeleteIcon />}
onClick={() => {
setDeleteModal(true);
}}
>
Delete
</Button>
</div>
{handleButtonsShow()}
</CardContent>
</div>
{title && (
Expand Down

0 comments on commit a7eb654

Please sign in to comment.