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

[Feature] 모집 게시글 상세보기 페이지 마크업 #61

Merged
merged 11 commits into from
Nov 24, 2022
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
2 changes: 1 addition & 1 deletion frontend/src/components/ArticleTag/ArticleTag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const Template: ComponentStory<typeof ArticleTag> = (args) => <ArticleTag {...ar

export const _ArticleTag = Template.bind({});
_ArticleTag.args = {
id: 2,
color: 'lime',
content: '제주',
};
17 changes: 5 additions & 12 deletions frontend/src/components/ArticleTag/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { Badge } from '@mantine/core';
import styled from '@emotion/styled';
import { BADGE_COLORS } from '@constants/color';

interface Props {
/**
* 카테고리 id, 지역 id 등 뱃지 옵션의 id를 입력합니다.
* id를 통해 색상이 결정됩니다.
* 뱃지의 색상을 결정합니다. 존재하지 않는 색상을 입력할 경우, indigo로 설정됩니다.
*/
id: number;
color: string;
/**
* 뱃지에 들어갈 내용이 입력됩니다.
*/
content: string;
size?: 'sm' | 'lg';
}

const ArticleTag = ({ id, content }: Props) => {
// TODO 이 함수를 util로 분리하는게 좋을지 고민
const getBadgeColor = (id: number) => {
const colorCount = BADGE_COLORS.length;
return BADGE_COLORS[id % colorCount];
};

const ArticleTag = ({ color, content, size = 'sm' }: Props) => {
return (
<BadgeWrapper>
<Badge color={getBadgeColor(id)} size="sm">
<Badge color={color} size={size} radius="sm">
{content}
</Badge>
</BadgeWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import GroupArticleCard from '.';
import { dummyArticle } from '@constants/dummy';
import { dummyArticlePreview } from '@constants/dummy';
import { ArticleStatus } from '@constants/article';

export default {
Expand All @@ -11,14 +11,14 @@ export default {
const Template: ComponentStory<typeof GroupArticleCard> = (args) => <GroupArticleCard {...args} />;

export const NormalCard = Template.bind({});
NormalCard.args = { article: dummyArticle };
NormalCard.args = { article: dummyArticlePreview };

export const LongTitleCard = Template.bind({});
LongTitleCard.args = {
article: { ...dummyArticle, title: '길어지는 제목입니다. 제목이 길어서 잘려요.' },
article: { ...dummyArticlePreview, title: '길어지는 제목입니다. 제목이 길어서 잘려요.' },
};

export const ClosedCard = Template.bind({});
ClosedCard.args = {
article: { ...dummyArticle, status: ArticleStatus.SUCCEED },
article: { ...dummyArticlePreview, status: ArticleStatus.SUCCEED },
};
21 changes: 16 additions & 5 deletions frontend/src/components/GroupArticleCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Image } from '@mantine/core';
import { ArticleType } from '@typings/types';
import { ArticlePreviewType } from '@typings/types';
import ArticleTag from '@components/ArticleTag';
import StatCounter from '@components/StatCounter';
import { ArticleStatus } from '@constants/article';
import { ArticleStatus, ArticleStatusKr } from '@constants/article';
import {
CapacityText,
CardWrapper,
Expand All @@ -12,9 +12,10 @@ import {
TitleText,
ClosedText,
} from '@components/GroupArticleCard/styles';
import { getCommonBadgeColor, getStatusBadgeColor } from '../../utils/colors';

interface Props {
article: ArticleType;
article: ArticlePreviewType;
}

const GroupArticleCard = ({ article }: Props) => {
Expand All @@ -28,8 +29,18 @@ const GroupArticleCard = ({ article }: Props) => {
<Image src={article.thumbnail} alt={'thumbnail-image'} height={200} />
<InfoWrapper>
<TagWrapper>
<ArticleTag id={article.category.id} content={article.category.name} />
<ArticleTag id={article.location.id} content={article.location.name} />
<ArticleTag
color={getStatusBadgeColor(article.status)}
content={ArticleStatusKr[article.status]}
/>
<ArticleTag
color={getCommonBadgeColor(article.category.id)}
content={article.category.name}
/>
<ArticleTag
color={getCommonBadgeColor(article.location.id)}
content={article.location.name}
/>
</TagWrapper>
<TitleText>{article.title}</TitleText>
<CapacityText>
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/constants/article.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
enum ArticleStatus {
PROGRESS = 'PROGRESS',
SUCCEED = 'SUCCEED',
FAIL = 'FAIL',
}

enum ArticleStatusKr {
PROGRESS = '모집중',
SUCCEED = '모집성공',
FAIL = '모집중단',
SUCCEED = '모집완료',
FAIL = '모집증단',
}

export { ArticleStatus };
export { ArticleStatus, ArticleStatusKr };
17 changes: 17 additions & 0 deletions frontend/src/constants/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
enum Category {
STUDY = 'STUDY',
PROJECT = 'PROJECT',
COMPETITION = 'COMPETITION',
MEAL = 'MEAL',
ETC = 'ETC',
}

enum CategoryKr {
STUDY = '스터디',
PROJECT = '프로젝트',
COMPETITION = '공모전',
MEAL = '식사',
ETC = '기타',
}

export { Category, CategoryKr };
23 changes: 10 additions & 13 deletions frontend/src/constants/color.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const BADGE_COLORS = [
'cyan',
'green',
'yellow',
'orange',
'grape',
'red',
'indigo',
'violet',
'lime',
'teal',
];
import { ArticleStatus } from '@constants/article';

export { BADGE_COLORS };
const BADGE_COLORS = ['cyan', 'green', 'yellow', 'orange', 'grape', 'violet', 'teal', 'pink'];

const STATUS_COLOR = {
[ArticleStatus.PROGRESS]: 'lime',
[ArticleStatus.SUCCEED]: 'indigo',
[ArticleStatus.FAIL]: 'red',
};

export { BADGE_COLORS, STATUS_COLOR };
31 changes: 28 additions & 3 deletions frontend/src/constants/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { ArticleType } from '@typings/types';
import { ArticlePreviewType, ArticleType } from '@typings/types';
import { Location } from '@constants/location';
import { ArticleStatus } from '@constants/article';
import { Category } from '@constants/category';

// TODO 개발용 dummy data, 추후 삭제
const dummyArticlePreview: ArticlePreviewType = {
id: 1,
title: '모집 테스트1',
location: {
id: 2,
name: Location.BUSAN,
},
category: {
id: 1,
name: Category.STUDY,
},
commentCount: 31,
scrapCount: 12,
thumbnail: 'https://avatars.githubusercontent.com/u/90585081?v=4',
maxCapacity: 5,
currentCapacity: 3,
status: ArticleStatus.PROGRESS,
createdAt: '2021-04-03T18:45:19Z',
};

Comment on lines +7 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더미 데이터는 constants 폴더에 정의해놓고 사용하고 계시군요~ 좋은 것 같습니다

const dummyArticle: ArticleType = {
id: 1,
title: '모집 테스트1',
Expand All @@ -12,8 +33,12 @@ const dummyArticle: ArticleType = {
},
category: {
id: 1,
name: '스터디',
name: Category.STUDY,
},
contents: '<div>test</div>',
authorId: 1,
authorName: 'JHPark_GOD',
authorThumbnail: 'https://avatars.githubusercontent.com/u/90585081?v=4',
commentCount: 31,
scrapCount: 12,
thumbnail: 'https://avatars.githubusercontent.com/u/90585081?v=4',
Expand All @@ -23,4 +48,4 @@ const dummyArticle: ArticleType = {
createdAt: '2021-04-03T18:45:19Z',
};

export { dummyArticle };
export { dummyArticlePreview, dummyArticle };
22 changes: 21 additions & 1 deletion frontend/src/constants/location.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
enum Location {
SEOUL = 'SEOUL',
INCHEON = 'INCHEON',
BUSAN = 'BUSAN',
DAEGU = 'DAEGU',
GWANGJU = 'GWANGJU',
DAEJEON = 'DAEJEON',
ULSAN = 'ULSAN',
SEJONG = 'SEJONG',
GYEONGGI = 'GYEONGGI',
GANGWON = 'GANGWON',
CHUNGBUK = 'CHUNGBUK',
CHUNGNAM = 'CHUNGNAM',
JEONBUK = 'JEONBUK',
JEONNAM = 'JEONNAM',
GYEONGBUK = 'GYEONGBUK',
GYEONGNAM = 'GYEONGNAM',
JEJU = 'JEJU',
}

enum LocationKr {
SEOUL = '서울',
INCHEON = '인천',
BUSAN = '부산',
Expand All @@ -18,4 +38,4 @@ enum Location {
JEJU = '제주',
}

export { Location };
export { Location, LocationKr };
Loading