Skip to content

Commit

Permalink
Disable at final node
Browse files Browse the repository at this point in the history
  • Loading branch information
cznrhubarb committed Feb 26, 2024
1 parent 2d5d6f2 commit ab48281
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/social/pages/CommunityPost/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom';

Expand All @@ -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 (
Expand All @@ -42,11 +54,13 @@ const CommunityPost = ({
isCoach(currentUser) &&
<NavButtonGroup isFullWidth>
<PrimaryButton
disabled={olderButtonDisabled}
onClick={() => onOlderPost(communityId, postId)}
>
&lt; Older
</PrimaryButton>
<PrimaryButton
disabled={newerButtonDisabled}
onClick={() => onNewerPost(communityId, postId)}
>
Newer &gt;
Expand Down

0 comments on commit ab48281

Please sign in to comment.