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

Lift state for error to Comments #10341

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
36 changes: 36 additions & 0 deletions dotcom-rendering/src/components/Discussion/Comment.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export const Root = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
Root.storyName = 'A root comment on desktop view';
Expand All @@ -175,6 +177,8 @@ export const RootMobile = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
RootMobile.storyName = 'A root comment on mobile view';
Expand Down Expand Up @@ -205,6 +209,8 @@ export const ReplyComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
ReplyComment.storyName = 'A reply on desktop view';
Expand Down Expand Up @@ -235,6 +241,8 @@ export const MobileReply = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
MobileReply.storyName = 'A reply on mobile view';
Expand Down Expand Up @@ -265,6 +273,8 @@ export const LongMobileReply = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
LongMobileReply.storyName = 'A long username reply on mobile view';
Expand Down Expand Up @@ -295,6 +305,8 @@ export const LongBothMobileReply = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
LongBothMobileReply.storyName = 'Both long usernames replying on mobile view';
Expand Down Expand Up @@ -328,6 +340,8 @@ export const PickedComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
PickedComment.storyName = 'Picked Comment';
Expand All @@ -352,6 +366,8 @@ export const StaffUserComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
StaffUserComment.storyName = 'Staff User Comment';
Expand All @@ -376,6 +392,8 @@ export const ContributorUserComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
ContributorUserComment.storyName = 'Contributor User Comment';
Expand Down Expand Up @@ -403,6 +421,8 @@ export const PickedStaffUserComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
PickedStaffUserComment.storyName = 'with staff and picked badges on desktop';
Expand All @@ -428,6 +448,8 @@ export const PickedStaffUserCommentMobile = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
PickedStaffUserCommentMobile.storyName =
Expand Down Expand Up @@ -462,6 +484,8 @@ export const ContributorUserCommentDesktop = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
ContributorUserCommentDesktop.storyName =
Expand All @@ -488,6 +512,8 @@ export const ContributorUserCommentMobile = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
ContributorUserCommentMobile.storyName =
Expand Down Expand Up @@ -520,6 +546,8 @@ export const LoggedInAsModerator = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
LoggedInAsModerator.storyName = 'Logged in as moderator';
Expand All @@ -545,6 +573,8 @@ export const LoggedInAsUser = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
LoggedInAsUser.storyName = 'Logged in as normal user';
Expand All @@ -569,6 +599,8 @@ export const BlockedComment = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
BlockedComment.storyName = 'Blocked comment';
Expand All @@ -593,6 +625,8 @@ export const MutedComment = () => (
isMuted={true}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
MutedComment.storyName = 'Muted comment';
Expand All @@ -617,6 +651,8 @@ export const ClosedForComments = () => (
isMuted={false}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
error={''}
setError={() => {}}
/>
);
ClosedForComments.storyName = 'A closed comment on desktop view';
Expand Down
5 changes: 4 additions & 1 deletion dotcom-rendering/src/components/Discussion/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Props = {
toggleMuteStatus: (userId: string) => void;
onPermalinkClick: (commentId: number) => void;
onRecommend?: (commentId: number) => Promise<boolean>;
error: string;
setError: (error: string) => void;
};

const commentControlsLink = css`
Expand Down Expand Up @@ -301,11 +303,12 @@ export const Comment = ({
toggleMuteStatus,
onPermalinkClick,
onRecommend,
error,
setError,
}: Props) => {
const [isHighlighted, setIsHighlighted] = useState<boolean>(
comment.isHighlighted,
);
const [error, setError] = useState<string>();

const [showAbuseReportForm, setAbuseReportForm] = useState(false);
const toggleSetShowForm = () => setAbuseReportForm(!showAbuseReportForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export const defaultStory = () => (
onPermalinkClick={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>
);
defaultStory.storyName = 'default';
Expand Down Expand Up @@ -219,6 +221,8 @@ export const threadedComment = () => (
onPermalinkClick={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>
);
threadedComment.storyName = 'threaded';
Expand Down Expand Up @@ -247,6 +251,8 @@ export const threadedCommentWithShowMore = () => (
onPermalinkClick={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>
);
threadedCommentWithShowMore.storyName = 'threaded with show more button';
Expand Down Expand Up @@ -275,6 +281,8 @@ export const threadedCommentWithLongUsernames = () => (
onPermalinkClick={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>
);
threadedCommentWithLongUsernames.storyName = 'threaded with long usernames';
Expand Down Expand Up @@ -303,6 +311,8 @@ export const threadedCommentWithLongUsernamesMobile = () => (
onPermalinkClick={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>
);
threadedCommentWithLongUsernamesMobile.storyName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe('CommentContainer', () => {
onPermalinkClick={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>,
);

Expand Down Expand Up @@ -107,6 +109,8 @@ describe('CommentContainer', () => {
onPermalinkClick={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>,
);

Expand Down Expand Up @@ -145,6 +149,8 @@ describe('CommentContainer', () => {
onPermalinkClick={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>,
);

Expand Down Expand Up @@ -184,6 +190,8 @@ describe('CommentContainer', () => {
onPermalinkClick={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
error={''}
setError={() => {}}
/>,
);

Expand Down
10 changes: 10 additions & 0 deletions dotcom-rendering/src/components/Discussion/CommentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Props = {
onPreview?: (body: string) => Promise<string>;
isCommentFormActive: boolean;
setIsCommentFormActive: (isActive: boolean) => void;
error: string;
setError: (error: string) => void;
};

const nestingStyles = css`
Expand Down Expand Up @@ -89,6 +91,8 @@ export const CommentContainer = ({
onPreview,
isCommentFormActive,
setIsCommentFormActive,
error,
setError,
}: Props) => {
// Filter logic
const [expanded, setExpanded] = useState<boolean>(threads === 'expanded');
Expand Down Expand Up @@ -138,6 +142,8 @@ export const CommentContainer = ({
toggleMuteStatus={toggleMuteStatus}
onPermalinkClick={onPermalinkClick}
onRecommend={onRecommend}
error={error}
setError={setError}
/>

<>
Expand Down Expand Up @@ -165,6 +171,8 @@ export const CommentContainer = ({
)}
toggleMuteStatus={toggleMuteStatus}
onPermalinkClick={onPermalinkClick}
error={error}
setError={setError}
/>
</li>
))}
Expand Down Expand Up @@ -228,6 +236,8 @@ export const CommentContainer = ({
onPreview={onPreview}
isActive={isCommentFormActive}
setIsActive={setIsCommentFormActive}
error={error}
setError={setError}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const Default = () => (
onAddComment={(comment) => {}}
isActive={false}
setIsActive={() => {}}
error={''}
setError={() => {}}
/>
);
Default.storyName = 'default';
Expand All @@ -80,6 +82,8 @@ export const Error = () => (
onAddComment={(comment) => {}}
isActive={false}
setIsActive={() => {}}
error={''}
setError={() => {}}
/>
);
Error.storyName = 'form with errors';
Expand All @@ -93,6 +97,8 @@ export const Active = () => (
commentBeingRepliedTo={aComment}
isActive={true}
setIsActive={() => {}}
error={''}
setError={() => {}}
/>
);
Active.storyName = 'form is active';
Expand Down Expand Up @@ -126,6 +132,8 @@ export const Premoderated = () => (
commentBeingRepliedTo={aComment}
isActive={true}
setIsActive={() => {}}
error={''}
setError={() => {}}
/>
);
Premoderated.storyName = 'user is premoderated';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Props = {
onPreview?: (body: string) => Promise<string>;
isActive: boolean;
setIsActive: (isActive: boolean) => void;
error: string;
setError: (error: string) => void;
};

const boldString = (str: string) => `<b>${str}</b>`;
Expand Down Expand Up @@ -219,11 +221,12 @@ export const CommentForm = ({
onPreview,
isActive,
setIsActive,
error,
setError,
}: Props) => {
const [userNameMissing, setUserNameMissing] = useState<boolean>(false);
const [body, setBody] = useState<string>('');
const [previewBody, setPreviewBody] = useState<string>('');
const [error, setError] = useState<string>('');
const [info, setInfo] = useState<string>('');
const [showPreview, setShowPreview] = useState<boolean>(false);
const textAreaRef = useRef<HTMLTextAreaElement>(null);
Expand Down
Loading
Loading