From 1820def8beae37636811bce07f98ab100b8fda38 Mon Sep 17 00:00:00 2001 From: Boredalien248 Date: Wed, 29 Nov 2023 00:44:20 -0700 Subject: [PATCH] fixed postpage and postslist sharing button click --- client/src/components/post/PostsList.tsx | 55 ++++++++++--------- client/src/components/post/SharePostModal.tsx | 6 +- .../components/post/post-item/PostPage.tsx | 11 ++++ 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/client/src/components/post/PostsList.tsx b/client/src/components/post/PostsList.tsx index 81a011fd..accc4f5e 100644 --- a/client/src/components/post/PostsList.tsx +++ b/client/src/components/post/PostsList.tsx @@ -51,8 +51,8 @@ const PostsList = ({ const [postToComment, setPostToComment] = useState(); const [isShareModalOpen, setIsShareModalOpen] = useState(false); const [sharedPost, setSharedPost] = useState(null); - const [isShareButtonDisabled, setIsShareButtonDisabled] = useState(false); const navigate = useNavigate(); + const [isSharingAllowed, setIsSharingAllowed] = useState(true); const useFollowers = () => { // this is only for the logged in user's followers @@ -95,14 +95,13 @@ const PostsList = ({ const shouldDisableShareButton = post.visibility === 'PRIVATE' || (post.visibility === 'FRIENDS' && post.contentType.includes("base64")); - + if (shouldDisableShareButton) { - return; // Exit early if sharing is disabled + return ; + } else { + setIsShareModalOpen(true); + setSharedPost(post); } - - setIsShareButtonDisabled(true); - setIsShareModalOpen(true); - setSharedPost(post); }; const openMakeCommentModal = (post: Post) => { @@ -278,28 +277,21 @@ const PostsList = ({ - + - event.stopPropagation()} - onClick={event => { - event.stopPropagation(); - event.preventDefault(); - handleShare(post); - }} - disabled={isShareButtonDisabled} - > - - + event.stopPropagation()} + onClick={event => { + event.stopPropagation(); + event.preventDefault(); + handleShare(post); + }} + > + + - @@ -344,6 +336,15 @@ const PostsList = ({ setIsCModalOpen={setIsMakeCommentModalOpen} /> } + {isShareModalOpen && + + } + ); }; diff --git a/client/src/components/post/SharePostModal.tsx b/client/src/components/post/SharePostModal.tsx index e3ca6040..b729edfd 100644 --- a/client/src/components/post/SharePostModal.tsx +++ b/client/src/components/post/SharePostModal.tsx @@ -15,7 +15,7 @@ interface SharePostModalProps { isModalOpen: boolean; setIsModalOpen: (isOpen: boolean) => void; followers: Author[]; - post: Post | null; + post: Post; } const SharePostModal = ({ isModalOpen, setIsModalOpen, followers, post }: SharePostModalProps) => { @@ -26,8 +26,8 @@ const SharePostModal = ({ isModalOpen, setIsModalOpen, followers, post }: ShareP }; const copyLink = () => { - const authorID = post?.author?.id ? getAuthorIdFromResponse(post.author.id) : ''; - const postID = post?.id ? getAuthorIdFromResponse(post.id) : ''; + const authorID = getAuthorIdFromResponse(post.author.id); + const postID = getAuthorIdFromResponse(post.id); const url = window.location.href; const path = window.location.pathname; const uri = url.replace(path, ''); diff --git a/client/src/components/post/post-item/PostPage.tsx b/client/src/components/post/post-item/PostPage.tsx index b7f57f88..7048386b 100644 --- a/client/src/components/post/post-item/PostPage.tsx +++ b/client/src/components/post/post-item/PostPage.tsx @@ -54,6 +54,7 @@ const PostPage = () => { const [isShareModalOpen, setIsShareModalOpen] = useState(false); const [sharedPost, setSharedPost] = useState(null); + const [isShareButtonDisabled, setIsShareButtonDisabled] = useState(false); const fetchPost = async (): Promise => { const endpoint = `authors/${authorId}/posts/${postId}/`; @@ -328,6 +329,15 @@ const PostPage = () => { const { followers } = useFollowers(); const handleShare = (post: Post) => { + const shouldDisableShareButton = + post.visibility === 'PRIVATE' || + (post.visibility === 'FRIENDS' && post.contentType.includes("base64")); + + if (shouldDisableShareButton) { + return; // Exit early if sharing is disabled + } + + setIsShareButtonDisabled(true); setIsShareModalOpen(true); setSharedPost(post); }; @@ -506,6 +516,7 @@ const PostPage = () => { { handleShare(post); }}