Skip to content

Commit

Permalink
Merge pull request #537 from marcussfu/master
Browse files Browse the repository at this point in the history
adjust 'Make editing comments (reply requests) easier'
  • Loading branch information
MrOrz committed Apr 19, 2023
2 parents 9ef4cbd + 52eac6b commit cc7fe81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions components/CreateReplyRequestForm/CreateReplyRequestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const SubmitButton = ({
};

const CreateReplyRequestForm = React.memo(
({ articleId, articleUserId, requestedForReply, onNewReplyButtonClick }) => {
({ articleId, articleUserId, ownReplyRequest, onNewReplyButtonClick }) => {
const buttonRef = useRef(null);
const [disabled, setDisabled] = useState(false);
const [showForm, setShowForm] = useState(false);
Expand All @@ -160,6 +160,10 @@ const CreateReplyRequestForm = React.memo(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
setText(t => (ownReplyRequest ? ownReplyRequest.reason : t));
}, [ownReplyRequest]);

// event scroll listener
useEffect(() => {
const observer = new IntersectionObserver(
Expand Down Expand Up @@ -190,6 +194,7 @@ const CreateReplyRequestForm = React.memo(
const handleReasonSubmitted = () => {
setText('');
setDisabled(false);
setShowForm(!showForm);
requestAnimationFrame(() => (localStorage.text = ''));
};

Expand Down Expand Up @@ -249,7 +254,7 @@ const CreateReplyRequestForm = React.memo(
onClick={() => setShowForm(!showForm)}
disableElevation
>
{requestedForReply === true ? t`Update comment` : t`Comment`}
{ownReplyRequest ? t`Update comment` : t`Comment`}
</Button>
<Button
type="button"
Expand Down
6 changes: 5 additions & 1 deletion pages/article/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ function ArticlePage() {
(currentUser ? true : positiveFeedbackCount - negativeFeedbackCount > 0)
);

const ownReplyRequest = replyRequestsWithComments.find(
element => element.user && currentUser && element.user.id === currentUser.id
);

return (
<AppLayout>
<Head>
Expand Down Expand Up @@ -475,8 +479,8 @@ function ArticlePage() {
</>
) : null}
<CreateReplyRequestForm
requestedForReply={article.requestedForReply}
articleId={article.id}
ownReplyRequest={ownReplyRequest}
articleUserId={article.user?.id || 'N/A'}
onNewReplyButtonClick={() => {
setShowForm(true);
Expand Down

0 comments on commit cc7fe81

Please sign in to comment.