From ab48281554df5ec30e8a560c91d8429c58b391f1 Mon Sep 17 00:00:00 2001 From: cznrhubarb Date: Mon, 26 Feb 2024 12:38:41 -0700 Subject: [PATCH] Disable at final node --- src/social/pages/CommunityPost/index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/social/pages/CommunityPost/index.js b/src/social/pages/CommunityPost/index.js index 714d7d241..c64b52fdd 100644 --- a/src/social/pages/CommunityPost/index.js +++ b/src/social/pages/CommunityPost/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { useNavigate } from 'react-router-dom'; @@ -23,15 +23,27 @@ const CommunityPost = ({ }) => { const { fetchNextPostInCommunity } = useConfig(); const { user: currentUser } = useUser(currentUserId, [currentUserId]); + const [olderButtonDisabled, setOlderButtonDisabled] = useState(false); + const [newerButtonDisabled, setNewerButtonDisabled] = useState(false); const navigate = useNavigate(); const onOlderPost = async (communityId, postId) => { const nextPostPath = await fetchNextPostInCommunity(communityId, postId, "AFTER"); - navigate(nextPostPath); + if (nextPostPath) { + navigate(nextPostPath); + setNewerButtonDisabled(false); + } else { + setOlderButtonDisabled(true); + } }; const onNewerPost = async () => { const nextPostPath = await fetchNextPostInCommunity(communityId, postId, "BEFORE"); - navigate(nextPostPath); + if (nextPostPath) { + navigate(nextPostPath); + setOlderButtonDisabled(false); + } else { + setNewerButtonDisabled(true); + } }; return ( @@ -42,11 +54,13 @@ const CommunityPost = ({ isCoach(currentUser) && onOlderPost(communityId, postId)} > < Older onNewerPost(communityId, postId)} > Newer >