Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comments: Add proposal author updates. #2549

Merged
merged 50 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c538acd
enable author updates on approved proposals
amass01 Aug 26, 2021
abda44a
bug fixes & cleanup
amass01 Aug 26, 2021
d81b762
allow replies only on latest author update
amass01 Aug 26, 2021
60395bb
allow replies only on the latest author update thread
amass01 Aug 28, 2021
d3c40cf
if author updates allowed display comment form only to record author
amass01 Aug 28, 2021
1ed1331
add an XXX as a reminder to consider the billing status when it's
amass01 Aug 28, 2021
b9ba6d9
enable comment votes only on latest author update thread
amass01 Aug 28, 2021
087bb2d
visually indicate author updates.
amass01 Aug 30, 2021
ebb26c7
[wip] display each author update in a separate comments section
amass01 Sep 1, 2021
e1ad910
styling, cleanup & bug fixes
amass01 Sep 2, 2021
3c9502a
yarn prettify
amass01 Sep 2, 2021
19a4e29
Merge branch 'master' into authoruodates
amass01 Sep 3, 2021
7c08970
single thread tweaks and fixes
amass01 Sep 3, 2021
812efeb
fix document.getElementById is undefined in scrollToElement.
amass01 Sep 3, 2021
108d345
add new author updates to the top
amass01 Sep 3, 2021
b2b3fce
map backend `extra data not allowed` error code
amass01 Sep 6, 2021
ffdba8a
replace `Comment $numofcomments` with `$updatetitle $numofcomments` for
amass01 Sep 6, 2021
cc91d16
display a tooltip next to the author update title with
amass01 Sep 6, 2021
56189bc
tooltip tweaks
amass01 Sep 6, 2021
e4a3cac
yarn prettify
amass01 Sep 6, 2021
e31a2fe
push missing title tooltip icon alignment changes
amass01 Sep 6, 2021
c5f6246
add `Proposal Update` as title and the icon next to it
amass01 Sep 7, 2021
6274530
hide comments section while processing comments
amass01 Sep 7, 2021
4c5e620
cleanup
amass01 Sep 7, 2021
5554f2c
add confirmation modal when the user is submitting subsequent updates
amass01 Sep 7, 2021
dd4d4ea
yarn prettify
amass01 Sep 7, 2021
a7f2f02
typo
amass01 Sep 7, 2021
6f94200
map error code, adding margin to form error message & fix author update
amass01 Sep 7, 2021
39e94ae
yarn prettify
amass01 Sep 7, 2021
82e5550
reset form bug fix
amass01 Sep 7, 2021
cc4c941
tiny cleanup
amass01 Sep 7, 2021
5ca9087
Merge branch 'master' into authoruodates
amass01 Sep 8, 2021
e321288
[wip] fix comments dep in Detail container which causes extra
amass01 Sep 10, 2021
29d6dae
fix flickering and infinite re-renders & mem optimaization & cleanup
amass01 Sep 10, 2021
e22d49f
enhance useScrollTo
amass01 Sep 11, 2021
15145c1
Normalize comments redux state.
amass01 Sep 13, 2021
b1056b2
show comments related errors in a separate row
amass01 Sep 13, 2021
6ffd9ae
yarn prettify
amass01 Sep 13, 2021
74c8ba4
re-add optimistic comment vote.
amass01 Sep 13, 2021
8d12c8f
Merge branch 'master' into authoruodates
amass01 Sep 13, 2021
491cb7a
move useComments to global hooks dir
amass01 Sep 14, 2021
95a7f44
typo
amass01 Sep 14, 2021
0faa540
Merge branch 'master' into authoruodates
amass01 Sep 14, 2021
dca90eb
add entity dirs for e2e tests.
amass01 Sep 14, 2021
c02c8ff
e2e: Add author update thread e2e tests.
amass01 Sep 15, 2021
562792c
opps
amass01 Sep 15, 2021
0f885ec
tiny cleanup
amass01 Sep 15, 2021
1fb3fe3
add summaries mock as middleware
amass01 Sep 15, 2021
0b63edc
code review nits
amass01 Sep 18, 2021
83446c9
cleanup unnecessary useMemo usage.
amass01 Sep 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/containers/Comments/Comment/Comment.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.authorUpdate {
border: 1px solid var(--input-border-color);
margin-bottom: var(--spacing-medium);
}

.comment {
margin-bottom: 2rem;
padding: 1rem 1.4rem;
Expand Down
5 changes: 2 additions & 3 deletions src/containers/Comments/Comment/CommentWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useCallback, useMemo } from "react";
import { classNames } from "pi-ui";
import styles from "./Comment.module.css";
import CommentForm from "src/components/CommentForm/CommentFormLazy";
import Link from "src/components/Link";
Expand Down Expand Up @@ -193,7 +192,7 @@ const CommentWrapper = ({
(areAuthorUpdatesAllowed && !isInLatestUpdateCommentTree);
amass01 marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className={classNames(isAuthorUpdate && styles.authorUpdate)}>
<>
<Comment
permalink={`${recordBaseLink}/comments/${commentid}`}
seeInContextLink={contextLink}
Expand Down Expand Up @@ -241,7 +240,7 @@ const CommentWrapper = ({
isThread={isThread}>
<Replies>{children}</Replies>
</CommentContent>
</div>
</>
);
};

Expand Down
125 changes: 16 additions & 109 deletions src/containers/Comments/Comments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import React, {
useMemo,
useState
} from "react";
import { Card, H2, Text, Message, classNames, P, Select } from "pi-ui";
import { withRouter } from "react-router-dom";
import { Card, H2, Text, Message, classNames, Select } from "pi-ui";
import styles from "./Comments.module.css";
import LoggedInContent from "src/components/LoggedInContent";
import CommentForm from "src/components/CommentForm/CommentFormLazy";
import ModalConfirmWithReason from "src/components/ModalConfirmWithReason";
import { CommentContext } from "./hooks";
import CommentsListWrapper from "./CommentsList/CommentsListWrapper";
import CommentLoader from "./Comment/CommentLoader";
import Link from "src/components/Link";
import Or from "src/components/Or";
import { useQueryString, useScrollTo } from "src/hooks";
import {
getSortOptionsForSelect,
Expand All @@ -24,18 +20,10 @@ import {
handleCommentCensoringInfo,
NUMBER_OF_LIST_PLACEHOLDERS
} from "./helpers";
import { useIdentity, usePaywall } from "src/hooks";
import { IdentityMessageError } from "src/components/IdentityErrorIndicators";
import ModalLogin from "src/components/ModalLogin";
import useModalContext from "src/hooks/utils/useModalContext";
import WhatAreYourThoughts from "src/components/WhatAreYourThoughts";
import { commentsReducer, initialState, actions } from "./commentsReducer";
import { getQueryStringValue } from "src/lib/queryString";
import useLocalStorage from "src/hooks/utils/useLocalStorage";
import { debounce } from "lodash";
import { PROPOSAL_UPDATE_HINT } from "src/constants";

const COMMENTS_LOGIN_MODAL_ID = "commentsLoginModal";

const FlatModeButton = ({ isActive, onClick }) => (
<div
Expand Down Expand Up @@ -71,6 +59,7 @@ const CommentsListAndActions = ({
commentsCtx,
onCensorComment,
currentUser,
userid,
proposalState,
handleOpenModal,
handleCloseModal,
Expand All @@ -86,7 +75,6 @@ const CommentsListAndActions = ({
latestAuthorUpdateId,
areAuthorUpdatesAllowed
}) => {
const { userid } = currentUser || {};
const {
getCommentLikeOption,
enableCommentVote,
Expand Down Expand Up @@ -274,7 +262,7 @@ const CommentsListAndActions = ({
<CommentsListWrapper
lastTimeAccessed={lastVisitTimestamp}
threadParentID={threadParentID}
currentUserID={currentUser && currentUser.userid}
currentUserID={userid}
comments={state.comments}
isFlatMode={isFlatCommentsMode}
proposalState={proposalState}
Expand All @@ -301,13 +289,10 @@ const Comments = ({
recordAuthorUsername,
threadParentID,
readOnly,
readOnlyReason,
className,
history,
proposalState,
recordBaseLink,
areAuthorUpdatesAllowed,
isCurrentUserProposalAuthor,
onSubmitComment,
onCommentVote,
onCensorComment,
Expand All @@ -316,49 +301,22 @@ const Comments = ({
recordType,
lastVisitTimestamp,
currentUser,
error,
userid,
latestAuthorUpdateId,
getCommentLikeOption,
enableCommentVote,
userLoggedIn,
userEmail,
loadingLikes,
getCommentVotes
getCommentVotes,
handleOpenModal,
handleCloseModal,
handleOpenLoginModal,
paywallMissing,
identityError,
isSingleThread
}) => {
const [, identityError] = useIdentity();
const { isPaid, paywallEnabled } = usePaywall();
const [state, dispatch] = useReducer(commentsReducer, initialState);

const [handleOpenModal, handleCloseModal] = useModalContext();
const { userid } = currentUser || {};

const onRedirectToSignup = () => history.push("/user/signup");

const paywallMissing = paywallEnabled && !isPaid;
const isSingleThread = !!threadParentID;

const handleSubmitComment = useCallback(
({ comment, title }) => {
// If title is provided then we are dealing with an author
// update.
let extraData = "",
extraDataHint = "";
if (title) {
extraDataHint = PROPOSAL_UPDATE_HINT;
extraData = JSON.stringify({ title });
}
return onSubmitComment({
comment,
token: recordTokenFull,
parentID: 0,
state: proposalState,
extraData,
extraDataHint
});
},
[onSubmitComment, proposalState, recordTokenFull]
);

const hasComments = !!comments;
const hasScrollToQuery = !!getQueryStringValue("scrollToComments");
const shouldScrollToComments =
Expand All @@ -383,65 +341,14 @@ const Comments = ({
[comments, sortOption]
);

const handleOpenLoginModal = useCallback(() => {
handleOpenModal(ModalLogin, {
id: COMMENTS_LOGIN_MODAL_ID,
onLoggedIn: handleCloseModal
});
}, [handleOpenModal, handleCloseModal]);

return (
<>
<Card
id="commentArea"
className={classNames(styles.commentAreaContainer, className)}>
<div className={classNames("container", styles.commentsHeaderWrapper)}>
<LoggedInContent
fallback={
<WhatAreYourThoughts
onLoginClick={handleOpenLoginModal}
onSignupClick={onRedirectToSignup}
/>
}>
<Or>
{readOnly && (
<Message kind="blocked" title="Comments are not allowed">
{readOnlyReason}
</Message>
)}
{!isPaid && paywallEnabled && currentUser && (
<Message kind="error">
<P>
You won't be able to submit comments or proposals before
paying the paywall, please visit your{" "}
<Link to={`/user/${userid}?tab=credits`}>account</Link> page
to correct this problem.
</P>
</Message>
)}
{!readOnly && !!identityError && <IdentityMessageError />}
</Or>
{!isSingleThread &&
!readOnly &&
recordTokenFull &&
areAuthorUpdatesAllowed &&
isCurrentUserProposalAuthor && (
<CommentForm
persistKey={`commenting-on-${recordToken}`}
onSubmit={handleSubmitComment}
disableSubmit={!!identityError || paywallMissing}
isAuthorUpdate={
areAuthorUpdatesAllowed && isCurrentUserProposalAuthor
}
/>
)}
</LoggedInContent>
{error && (
<Message kind="error" className="margin-top-m">
{error.toString()}
</Message>
)}
</div>
className={classNames(
styles.commentAreaContainer,
className
)}>
<CommentsListAndActions
sortOption={sortOption}
setSortOption={setSortOption}
Expand Down Expand Up @@ -487,4 +394,4 @@ const Comments = ({
);
};

export default withRouter(Comments);
export default Comments;
5 changes: 3 additions & 2 deletions src/containers/Comments/Comments.module.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
div.commentAreaContainer {
padding-top: 2rem;
padding-bottom: 2rem;
margin-top: var(--spacing-medium);
margin-bottom: var(--spacing-medium);
}

div.commentsWrapper {
padding: 0 2.6rem 2rem 2.6rem;
padding: 0 2.6rem 0 2.6rem;
max-width: calc(100vw - 12rem);
}

Expand Down Expand Up @@ -83,7 +85,6 @@ span.flatModeActive {
max-width: 100vw;
}

.commentsHeaderWrapper,
.commentsHeader {
padding-left: 1.4rem;
padding-right: 1.4rem;
Expand Down
Loading