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

게시글 목록에서 댓글 갯수와 이미지 갯수 볼 수 있도록 수정 #570

Merged
merged 5 commits into from
Sep 19, 2023
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
82 changes: 54 additions & 28 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/api/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const transformPostResponse = (post: PostInfoResponse): PostInfo => {
imageUrl: post.imageUrl,
postId: post.postId,
createTime: post.createdAt,
imageCount: post.imageCount,
commentCount: post.commentCount,
title: post.title,
voteInfo: {
allPeopleCount: post.voteInfo.totalVoteCount,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/assets/comment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/photo_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions frontend/src/components/PostForm/PostForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const MOCK_DATA: PostInfo = {
],
createTime: '2023-07-18 12:40',
deadline: '2023-08-15 12:40',
imageCount: 0,
commentCount: 1,
voteInfo: {
selectedOptionId: 1,
allPeopleCount: 0,
Expand Down
41 changes: 27 additions & 14 deletions frontend/src/components/common/Post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { POST } from '@constants/vote';
import { convertImageUrlToServerUrl } from '@utils/post/convertImageUrlToServerUrl';
import { checkClosedPost, convertTimeToWord } from '@utils/time';

import photoIcon from '@assets/photo_white.svg';
import commentIcon from '@assets/comment.svg';
import photoIcon from '@assets/photo_black.svg';

import Toast from '../Toast';

Expand All @@ -27,8 +28,19 @@ interface PostProps {
}

export default function Post({ postInfo, isPreview }: PostProps) {
const { postId, category, imageUrl, title, writer, createTime, deadline, content, voteInfo } =
postInfo;
const {
postId,
category,
imageUrl,
title,
writer,
createTime,
deadline,
content,
voteInfo,
imageCount,
commentCount,
} = postInfo;
const { loggedInfo } = useContext(AuthContext);
const { isToastOpen, openToast, toastMessage } = useToast();

Expand Down Expand Up @@ -93,12 +105,6 @@ export default function Post({ postInfo, isPreview }: PostProps) {
}
}, [isEditError, editError]);

const checkIncludeImage = () => {
if (imageUrl !== '') return true;

return voteInfo.options.map(option => option.imageUrl).some(url => url !== '');
};

const isPreviewTabIndex = isPreview ? undefined : 0;

return (
Expand All @@ -120,11 +126,6 @@ export default function Post({ postInfo, isPreview }: PostProps) {
>
{category.map(category => category.name).join(' | ')}
</S.Category>
{isPreview && checkIncludeImage() && (
<S.ImageIconWrapper>
<S.ImageIcon src={photoIcon} alt="해당 게시물은 사진을 포함하고 있습니다." />
</S.ImageIconWrapper>
)}
<S.ActivateState
tabIndex={isPreviewTabIndex}
role="status"
Expand Down Expand Up @@ -175,6 +176,18 @@ export default function Post({ postInfo, isPreview }: PostProps) {
isPreview={isPreview}
voteOptionList={voteInfo.options}
/>
{isPreview && (
<S.PreviewBottom>
<S.IconUint>
<S.Icon src={photoIcon} alt="사진 갯수" />
<span>{imageCount}</span>
</S.IconUint>
<S.IconUint>
<S.Icon src={commentIcon} alt="댓글 갯수" />
<span>{commentCount}</span>
</S.IconUint>
</S.PreviewBottom>
)}
{isToastOpen && (
<Toast size="md" position="bottom">
{toastMessage}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/common/Post/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const MOCK_NOT_VOTE_POST: PostInfo = {
],
createTime: '2023-07-12 12:40',
deadline: '2023-07-20 18:40',
imageCount: 2,
commentCount: 8,
voteInfo: {
selectedOptionId: 0,
allPeopleCount: 100,
Expand Down Expand Up @@ -90,6 +92,8 @@ export const MOCK_VOTE_POST: PostInfo = {
],
createTime: '2023-07-12 12:40',
deadline: '2023-07-21 18:40',
imageCount: 0,
commentCount: 1,
voteInfo: {
selectedOptionId: 12312,
allPeopleCount: 123,
Expand Down
Loading