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

[FE][댓글모듈] 좋아요를 누른 유저 목록을 확인하는 기능 추가 (#309) #313

Merged
merged 5 commits into from
Jul 29, 2021
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
4 changes: 4 additions & 0 deletions frontend/reply-module/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { configure, addDecorator } from "@storybook/react";
import GlobalStyles from "../src/styles/GlobalStyles";
import "./preview.css";

const modalRoot = document.createElement("div");
modalRoot.setAttribute("id", "modal-root");
document.querySelector("body").appendChild(modalRoot);

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
layout: "centered",
Expand Down
1 change: 1 addition & 0 deletions frontend/reply-module/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</head>
<body>
<div id="root"></div>
<div id="modal-root"></div>
</body>
</html>
8 changes: 7 additions & 1 deletion frontend/reply-module/src/components/atoms/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export interface Props {

const Avatar = ({ imageURL, size = "MD", onClick, alt }: Props) => {
return (
<Container src={imageURL || defaultUserImage} size={size} onClick={onClick} alt={alt} data-testid="avatar-img" />
<Container
src={imageURL ? (imageURL === "guestProfileImageUrl" ? defaultUserImage : imageURL) : defaultUserImage}
size={size}
onClick={onClick}
alt={alt}
data-testid="avatar-img"
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Story } from "@storybook/react";
import LikeButton, { Props } from ".";
import LikingUsersButton, { Props } from ".";

export default {
title: "atoms/LikeButton",
component: LikeButton,
title: "atoms/LikingUsersButton",
component: LikingUsersButton,
argTypes: { children: { control: "text" } }
};

const Template: Story<Props> = args => <LikeButton {...args} />;
const Template: Story<Props> = args => <LikingUsersButton {...args} />;

export const Default = Template.bind({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Props {
onClick: () => void;
}

const LikeButton = ({ className, numOfLikes, isLiked, onClick }: Props) => {
const LikingUsersButton = ({ className, numOfLikes, isLiked, onClick }: Props) => {
return (
<Button className={className} onClick={onClick} isLiked={isLiked}>
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand All @@ -21,4 +21,4 @@ const LikeButton = ({ className, numOfLikes, isLiked, onClick }: Props) => {
);
};

export default LikeButton;
export default LikingUsersButton;
18 changes: 18 additions & 0 deletions frontend/reply-module/src/components/atoms/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Story } from "@storybook/react";
import Modal, { Props } from ".";

export default {
title: "atoms/Modal",
component: Modal,
argTypes: { children: { control: "text" } }
};

const Template: Story<Props> = args => <Modal {...args}>모달입니다.</Modal>;

export const Default = Template.bind({});

Default.args = {
onCloseModal: () => {
console.log("Dimmed click");
}
};
24 changes: 24 additions & 0 deletions frontend/reply-module/src/components/atoms/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ReactNode } from "react";
import ReactDOM from "react-dom";
import { Container, Dimmed } from "./styles";

export interface Props {
children: ReactNode;
onCloseModal: () => void;
}

const $modalRoot = document.getElementById("modal-root");

const Modal = ({ children, onCloseModal }: Props) => {
if (!$modalRoot) return null;

return ReactDOM.createPortal(
<>
<Dimmed onClick={onCloseModal}></Dimmed>
<Container>{children}</Container>
</>,
$modalRoot
);
};

export default Modal;
25 changes: 25 additions & 0 deletions frontend/reply-module/src/components/atoms/Modal/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styled from "styled-components";
import { PALETTE } from "../../../styles/palette";

export const Dimmed = styled.div`
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.5);
`;

export const Container = styled.div`
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 3rem 2rem;
background-color: ${PALETTE.WHITE};
border-radius: 10px;
box-shadow: rgba(50, 50, 93, 0.25) 0 6px 12px -2px, rgba(0, 0, 0, 0.3) 0 3px 7px -3px;
`;
37 changes: 30 additions & 7 deletions frontend/reply-module/src/components/molecules/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { postScrollHeightToParentWindow } from "../../../utils/iframePostMessage
import { getTimeDifference } from "../../../utils/time";
import Avatar from "../../atoms/Avatar";
import CommentTextBox from "../../atoms/CommentTextBox";
import LikingUsersModal from "../LikingUsersModal";
import {
Button,
LikeButton,
CancelButton,
CommentBottomWrapper,
CommentOption,
Expand All @@ -18,7 +20,7 @@ import {
Container,
PasswordForm,
PasswordInput,
LikeButton,
LikingUsersButton,
Time
} from "./styles";

Expand All @@ -35,13 +37,14 @@ type SubmitType = "Edit" | "Delete";

const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, thisCommentIsMine }: Props) => {
const [isEditing, setEditing] = useState(false);
const [isLikingUsersModalOpen, setLikingUsersModalOpen] = useState(false);
const [isPasswordSubmitted, setPasswordSubmitted] = useState(false);
const [shouldShowPasswordInput, setShouldShowPasswordInput] = useState(false);
const [submitType, setSubmitType] = useState<SubmitType | null>();
const { value: password, setValue: setPassword, onChange: onChangePassword } = useInput("");
const { editComment } = useEditComment();
const { deleteComment } = useDeleteComment();
const { likeComment, error } = useLikeComment();
const { likeComment } = useLikeComment();
const { getPasswordConfirmResult } = useConfirmGuestPassword({
guestUserId: comment.user.id,
guestUserPassword: password
Expand All @@ -56,7 +59,7 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th
setPassword("");
};

const canIControl = (iAmAdmin && thisCommentIsMine) || !iAmAdmin;
const canIEdit = (iAmAdmin && thisCommentIsMine) || !iAmAdmin;

const confirmGuestPassword = async () => {
try {
Expand Down Expand Up @@ -142,6 +145,14 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th
}
};

const onLikingUsersModalOpen = () => {
setLikingUsersModalOpen(true);
};

const onLikingUsersModalClose = () => {
setLikingUsersModalOpen(false);
};

useEffect(() => {
postScrollHeightToParentWindow();
}, [shouldShowPasswordInput]);
Expand All @@ -162,13 +173,22 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th
>
{comment.content}
</CommentTextBox>
<LikeButton numOfLikes={comment.likingUsers.length} isLiked={isLiked} onClick={onClickLikeButton} />
<CommentBottomWrapper>
<LikeButton isLiked={isLiked} onClick={onClickLikeButton}>
좋아요
</LikeButton>
<Time>{getTimeDifference(comment.createdDate)}</Time>
{shouldShowOption && !submitType && (
<CommentOption startEditing={canIControl ? startEditing : undefined} startDeleting={startDeleting} />
)}
</CommentBottomWrapper>
{shouldShowOption && !submitType && (
<CommentOption startEditing={canIEdit ? startEditing : undefined} startDeleting={startDeleting} />
)}
{comment.likingUsers.length > 0 && (
<LikingUsersButton
numOfLikes={comment.likingUsers.length}
isLiked={isLiked}
onClick={onLikingUsersModalOpen}
/>
)}
</CommentTextBoxWrapper>
</CommentWrapper>
{shouldShowPasswordInput && shouldShowOption && (
Expand All @@ -193,6 +213,9 @@ const Comment = ({ user, comment, align = "left", shouldShowOption, iAmAdmin, th
<Button data-testid="comment-guest-password-submit-button">입력</Button>
</PasswordForm>
)}
{isLikingUsersModalOpen && (
<LikingUsersModal users={comment.likingUsers} onCloseModal={onLikingUsersModalClose} />
)}
</Container>
);
};
Expand Down
24 changes: 20 additions & 4 deletions frontend/reply-module/src/components/molecules/Comment/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import { InputCSS } from "../../../styles/css";
import { PALETTE } from "../../../styles/palette";
import LikeButtonComponent from "../../atoms/Buttons/LikeButton";
import LikingUsersButtonComponent from "../../atoms/Buttons/LikingUsersButton";
import CommentOptionComponent from "../../atoms/CommentOption";

export const Container = styled.div<{ align: "left" | "right" }>`
Expand All @@ -21,7 +21,7 @@ export const CommentTextBoxWrapper = styled.div<{ align: "left" | "right" }>`
margin: ${props => (props.align === "left" ? "0 0 0 0.6rem" : "0 0.6rem 0 0")};
`;

export const LikeButton = styled(LikeButtonComponent)`
export const LikingUsersButton = styled(LikingUsersButtonComponent)`
position: absolute;
bottom: 0.5rem;
right: -1.5rem;
Expand All @@ -33,11 +33,27 @@ export const LikeButton = styled(LikeButtonComponent)`

export const CommentBottomWrapper = styled.div`
display: flex;
margin-top: 0.3rem;
align-items: center;
margin: 0.3rem 1rem 0 1rem;

& > *:not(:first-child):before {
content: "·";
color: ${PALETTE.BLACK_700};
margin: 0 0.3rem;
}
`;

export const LikeButton = styled.button<{ isLiked: boolean }>`
background-color: transparent;
color: ${props => (props.isLiked ? PALETTE.BLUE_700 : PALETTE.BLACK_700)};

&:hover {
color: ${props => (props.isLiked ? PALETTE.BLACK_700 : PALETTE.BLUE_700)};
}
`;

export const Time = styled.span`
margin: 0 1rem;
font-size: 0.8rem;
`;

export const CommentOption = styled(CommentOptionComponent)`
Expand Down
Loading