Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 163e154

Browse files
committed
remove edit button when a user does not have permissions to edit it
1 parent 537be96 commit 163e154

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/components/PostView.tsx

+21-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,22 @@ interface PostViewProps {
2525
* Display a post view.
2626
*/
2727
const PostView = ({ chapterId, item, topicId }: PostViewProps) => {
28-
const { translate } = useContext(GlobalContext);
29-
const { category, content, id, likes, links, sites, title, topics } = item;
28+
const { translate, user } = useContext(GlobalContext);
29+
const {
30+
category,
31+
createdById,
32+
content,
33+
id,
34+
likes,
35+
links,
36+
sites,
37+
title,
38+
topics,
39+
} = item;
3040
const youtube = links?.find((link) => containsYoutubeUrl(link));
3141
const [next, setNext] = useState<Post.NextLesson | null>(null);
42+
const isAuthoral = category === 'posts' || category === 'questions';
43+
const isEditable = !isAuthoral || createdById === user?.uid;
3244

3345
useEffect(() => {
3446
let active = true;
@@ -88,11 +100,13 @@ const PostView = ({ chapterId, item, topicId }: PostViewProps) => {
88100
margin: theme.spacing(2),
89101
}}
90102
>
91-
<NextLink href="/posts/[id]/edit" as={`/posts/${id}/edit`} passHref>
92-
<Button component="a" color="primary">
93-
{translate('improve_page')}
94-
</Button>
95-
</NextLink>
103+
{isEditable && (
104+
<NextLink href="/posts/[id]/edit" as={`/posts/${id}/edit`} passHref>
105+
<Button component="a" color="primary">
106+
{translate('improve_page')}
107+
</Button>
108+
</NextLink>
109+
)}
96110

97111
{next && (
98112
<NextLink

0 commit comments

Comments
 (0)