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 showPreview from CommentForm to Comments #10320

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export const defaultStory = () => (
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
/>
Expand Down Expand Up @@ -217,6 +219,8 @@ export const threadedComment = () => (
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
/>
Expand Down Expand Up @@ -245,6 +249,8 @@ export const threadedCommentWithShowMore = () => (
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
/>
Expand Down Expand Up @@ -273,6 +279,8 @@ export const threadedCommentWithLongUsernames = () => (
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
/>
Expand Down Expand Up @@ -301,6 +309,8 @@ export const threadedCommentWithLongUsernamesMobile = () => (
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={false}
setIsCommentFormActive={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('CommentContainer', () => {
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
/>,
Expand Down Expand Up @@ -105,6 +107,8 @@ describe('CommentContainer', () => {
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
/>,
Expand Down Expand Up @@ -143,6 +147,8 @@ describe('CommentContainer', () => {
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
/>,
Expand Down Expand Up @@ -182,6 +188,8 @@ describe('CommentContainer', () => {
mutes={[]}
toggleMuteStatus={() => {}}
onPermalinkClick={() => {}}
showPreview={false}
setShowPreview={() => {}}
isCommentFormActive={true}
setIsCommentFormActive={() => {}}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Props = {
parentCommentId: number,
) => Promise<CommentResponse>;
onPreview?: (body: string) => Promise<string>;
showPreview: boolean;
setShowPreview: (showPreview: boolean) => void;
isCommentFormActive: boolean;
setIsCommentFormActive: (isActive: boolean) => void;
};
Expand Down Expand Up @@ -87,6 +89,8 @@ export const CommentContainer = ({
onComment,
onReply,
onPreview,
showPreview,
setShowPreview,
isCommentFormActive,
setIsCommentFormActive,
}: Props) => {
Expand Down Expand Up @@ -226,6 +230,8 @@ export const CommentContainer = ({
onComment={onComment}
onReply={onReply}
onPreview={onPreview}
showPreview={showPreview}
setShowPreview={setShowPreview}
isActive={isCommentFormActive}
setIsActive={setIsCommentFormActive}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const Default = () => (
shortUrl={shortUrl}
user={aUser}
onAddComment={(comment) => {}}
showPreview={false}
setShowPreview={() => {}}
isActive={false}
setIsActive={() => {}}
/>
Expand All @@ -78,6 +80,8 @@ export const Error = () => (
shortUrl={'/p/g8g7v'}
user={aUser}
onAddComment={(comment) => {}}
showPreview={false}
setShowPreview={() => {}}
isActive={false}
setIsActive={() => {}}
/>
Expand All @@ -91,6 +95,8 @@ export const Active = () => (
user={aUser}
onAddComment={(comment) => {}}
commentBeingRepliedTo={aComment}
showPreview={false}
setShowPreview={() => {}}
isActive={true}
setIsActive={() => {}}
/>
Expand Down Expand Up @@ -124,6 +130,8 @@ export const Premoderated = () => (
}}
onAddComment={(comment) => {}}
commentBeingRepliedTo={aComment}
showPreview={false}
setShowPreview={() => {}}
isActive={true}
setIsActive={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Props = {
parentCommentId: number,
) => Promise<CommentResponse>;
onPreview?: (body: string) => Promise<string>;
showPreview: boolean;
setShowPreview: (showPreview: boolean) => void;
isActive: boolean;
setIsActive: (isActive: boolean) => void;
};
Expand Down Expand Up @@ -217,6 +219,8 @@ export const CommentForm = ({
onComment,
onReply,
onPreview,
showPreview,
setShowPreview,
isActive,
setIsActive,
}: Props) => {
Expand All @@ -225,7 +229,6 @@ export const CommentForm = ({
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);

useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions dotcom-rendering/src/components/Discussion/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const Comments = ({
useState<CommentType>();
const [numberOfCommentsToShow, setNumberOfCommentsToShow] = useState(10);
const [mutes, setMutes] = useState<string[]>(readMutes());
const [showPreview, setShowPreview] = useState<boolean>(false);
const [isCommentFormActive, setIsCommentFormActive] = useState<boolean>(
!!commentBeingRepliedTo,
);
Expand Down Expand Up @@ -292,6 +293,8 @@ export const Comments = ({
toggleMuteStatus={toggleMuteStatus}
onPermalinkClick={onPermalinkClick}
onRecommend={onRecommend}
showPreview={showPreview}
setShowPreview={setShowPreview}
isCommentFormActive={
isCommentFormActive
}
Expand Down Expand Up @@ -319,6 +322,8 @@ export const Comments = ({
onComment={onComment}
onReply={onReply}
onPreview={onPreview}
showPreview={showPreview}
setShowPreview={setShowPreview}
isActive={isCommentFormActive}
setIsActive={setIsCommentFormActive}
/>
Expand Down Expand Up @@ -373,6 +378,8 @@ export const Comments = ({
onPermalinkClick={onPermalinkClick}
onRecommend={onRecommend}
onReply={onReply}
showPreview={showPreview}
setShowPreview={setShowPreview}
isCommentFormActive={isCommentFormActive}
setIsCommentFormActive={
setIsCommentFormActive
Expand Down Expand Up @@ -402,6 +409,8 @@ export const Comments = ({
onComment={onComment}
onReply={onReply}
onPreview={onPreview}
showPreview={showPreview}
setShowPreview={setShowPreview}
isActive={isCommentFormActive}
setIsActive={setIsCommentFormActive}
/>
Expand Down
Loading