diff --git a/app/community/[communityId]/CommunityClientPage.tsx b/app/community/[communityId]/comments/CommunityClientPage.tsx similarity index 73% rename from app/community/[communityId]/CommunityClientPage.tsx rename to app/community/[communityId]/comments/CommunityClientPage.tsx index 6bd67d2..013a22a 100644 --- a/app/community/[communityId]/CommunityClientPage.tsx +++ b/app/community/[communityId]/comments/CommunityClientPage.tsx @@ -6,7 +6,10 @@ import About from "@/components/community/about/About"; import CommunityHeader from "@/components/community/community-header/CommunityHeader"; import PageContent from "@/components/layout/PageContent"; import Posts from "@/components/posts/Posts"; +import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; +import RestrictedCommunityBanner from "@/components/community/RestrictedCommunityBanner"; import { Community } from "@/types/community"; +import { Stack } from "@chakra-ui/react"; import { useAtom } from "jotai"; import React, { useEffect } from "react"; @@ -39,17 +42,23 @@ const CommunityClientPage: React.FC = ({ ? communityStateValue.currentCommunity : communityData; + const { canView } = useCommunityPermissions(currentCommunity); + return ( <> <> - - - - <> - + {canView ? ( + <> + + + + ) : ( + + )} + <>{canView && } ); diff --git a/app/community/[communityId]/comments/[pid]/PostClientPage.tsx b/app/community/[communityId]/comments/[pid]/PostClientPage.tsx index f4d8544..9f8dc20 100644 --- a/app/community/[communityId]/comments/[pid]/PostClientPage.tsx +++ b/app/community/[communityId]/comments/[pid]/PostClientPage.tsx @@ -12,6 +12,7 @@ import usePostDeletion from "@/hooks/posts/usePostDeletion"; import usePostState from "@/hooks/posts/usePostState"; import usePostVote from "@/hooks/posts/usePostVote"; import usePostVoteSync from "@/hooks/posts/usePostVoteSync"; +import RestrictedCommunityBanner from "@/components/community/RestrictedCommunityBanner"; import { Community } from "@/types/community"; import { Post } from "@/types/post"; import { Stack } from "@chakra-ui/react"; @@ -41,7 +42,8 @@ const PostPage: React.FC = ({ communityData, postData }) => { useAtom(communityStateAtom); const currentCommunity = communityStateValue.currentCommunity || communityData; - const { isAdmin } = useCommunityPermissions(currentCommunity); + const { isAdmin, canView, canPost } = + useCommunityPermissions(currentCommunity); const [user] = useAuthState(auth); useEffect(() => { @@ -60,47 +62,49 @@ const PostPage: React.FC = ({ communityData, postData }) => { } }, [postData, setPostStateValue]); + if (!canView) { + return ( + + + <> + + ); + } + return ( - {/* Left */} <> - {!postData && !postStateValue.selectedPost ? ( - - ) : ( - <> - - {postStateValue.selectedPost && ( - item.postId === postStateValue.selectedPost?.id - )?.voteValue - } - userIsCreator={ - user?.uid === postStateValue.selectedPost?.creatorId - } - userIsAdmin={isAdmin} - showCommunityImage={true} - /> - )} - - - - - )} + + {postStateValue.selectedPost && ( + item.postId === postStateValue.selectedPost!.id + )?.voteValue + } + userIsCreator={ + user?.uid === postStateValue.selectedPost.creatorId + } + userIsAdmin={isAdmin} + votingDisabled={!canPost} + /> + )} + + + + <> + - {currentCommunity && } - {/* Right */} - <> ); }; + export default PostPage; diff --git a/app/community/[communityId]/page.tsx b/app/community/[communityId]/page.tsx index b3bf8d4..d2cef6e 100644 --- a/app/community/[communityId]/page.tsx +++ b/app/community/[communityId]/page.tsx @@ -1,6 +1,6 @@ import { getCommunityData } from "@/lib/community/getCommunityData"; import { notFound } from "next/navigation"; -import CommunityClientPage from "./CommunityClientPage"; +import CommunityClientPage from "./comments/CommunityClientPage"; /** * Server component that loads community data and renders the client view. diff --git a/app/community/[communityId]/submit/SubmitPostClientPage.tsx b/app/community/[communityId]/submit/SubmitPostClientPage.tsx index 519101a..7f562ca 100644 --- a/app/community/[communityId]/submit/SubmitPostClientPage.tsx +++ b/app/community/[communityId]/submit/SubmitPostClientPage.tsx @@ -12,6 +12,8 @@ import { Box, Stack, Text } from "@chakra-ui/react"; import { useAtom, useSetAtom } from "jotai"; import React, { useEffect } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; +import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; +import RestrictedCommunityBanner from "@/components/community/RestrictedCommunityBanner"; type SubmitPostPageProps = { communityData: Community; @@ -37,6 +39,19 @@ const SubmitPostPage: React.FC = ({ communityData }) => { const currentCommunity = communityStateValue.currentCommunity || communityData; + const { canPost } = useCommunityPermissions(currentCommunity); + + if (!canPost) { + return ( + + + + + ); + } return ( diff --git a/components/community/CreatePostLink.tsx b/components/community/CreatePostLink.tsx index 683ee17..912b43f 100644 --- a/components/community/CreatePostLink.tsx +++ b/components/community/CreatePostLink.tsx @@ -4,6 +4,8 @@ import React from "react"; import { BsLink45Deg } from "react-icons/bs"; import { IoIosCreate } from "react-icons/io"; import { IoImageOutline } from "react-icons/io5"; +import useCommunityState from "@/hooks/community/useCommunityState"; +import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; type CreatePostProps = {}; @@ -14,6 +16,14 @@ type CreatePostProps = {}; */ const CreatePostLink: React.FC = () => { const { onClick } = useCallCreatePost(); // hook for creating a new post + const { communityStateValue } = useCommunityState(); + const { canPost } = useCommunityPermissions( + communityStateValue.currentCommunity + ); + + if (communityStateValue.currentCommunity && !canPost) { + return null; + } return ( = ({ + title = "This community is private", + description = "Posts are only shown to subscribers.", +}) => { + return ( + + + + {title} + + {description} + + ); +}; + +export default RestrictedCommunityBanner; diff --git a/components/community/about/About.tsx b/components/community/about/About.tsx index 44cdb81..ae7c981 100644 --- a/components/community/about/About.tsx +++ b/components/community/about/About.tsx @@ -7,6 +7,7 @@ import CommunityMembersModal from "../../modal/community-members/CommunityMember import AboutCommunity from "./AboutCommunity"; import AboutHeaderBar from "./AboutHeaderBar"; import AdminSectionAbout from "./AdminSectionAbout"; +import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; /** * @param {string} communityName - Name of the community @@ -37,6 +38,11 @@ const About: React.FC = ({ communityData }) => { (item) => item.communityId === communityData.id ); const [isMembersModalOpen, setMembersModalOpen] = useState(false); + const { canView, canPost } = useCommunityPermissions(communityData); + + if (!canView) { + return null; + } return ( // sticky position for the about section @@ -59,14 +65,16 @@ const About: React.FC = ({ communityData }) => { )} - + {canPost && ( + + )} {isJoined && (