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

feat: 모두의 정원 게시글 아이템 구현 #340

Merged
merged 22 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
442c1ef
refactor: queryClient 데코레이터 리팩터링
bassyu Sep 6, 2023
1c7565e
feat: 모두의 정원 게시글 아이템 구현
bassyu Sep 6, 2023
ab9c71d
design: 식물 이름 길이 최대 192px로 제한
bassyu Sep 6, 2023
ec3d7fe
chore: alt 추가
bassyu Sep 6, 2023
4b75101
chore: as const 대신 ComponentProps 적용
bassyu Sep 6, 2023
74ea124
chore: 날짜 타입에 DateFormat 적용
bassyu Sep 6, 2023
0d3dcf8
fix: createdAt의 Description, control 에서 7만개의 타입 가져오는 이슈 해결
bassyu Sep 6, 2023
be96a7d
feat: 더보기, 줄바꿈 기능이 있는 박스 컴포넌트 추가
bassyu Sep 11, 2023
7389b07
design: 더보기 영역과 내용 영역 분리
bassyu Sep 11, 2023
74d93e9
design: 더보기 영역과 내용 영역 분리
bassyu Sep 11, 2023
c650f52
feat: 모두의 정원 아이템과 사전 식물 상세 페이지에 더보기 컴포넌트 적용
bassyu Sep 11, 2023
019ec68
design: 날짜 폰트 변경
bassyu Sep 11, 2023
b158ffe
refactor: 내용 영역 크기 줄임
bassyu Sep 11, 2023
7fb2a53
refactor: showState 상태 관련 로직 훅으로 분리
bassyu Sep 11, 2023
6557da4
Merge branch 'develop' into feature/337-모두의_정원_게시글
bassyu Sep 11, 2023
c428062
chore: Fragment에 key 추가
bassyu Sep 11, 2023
a900a88
chore: transient props 적용
bassyu Sep 11, 2023
14106a7
chore: 사전 식물 이름 추가
bassyu Sep 12, 2023
66a2b5c
feat: 태그 위치 변경 및 사전 식물 태그 추가
bassyu Sep 12, 2023
5185e86
chore: p 태그 추가
bassyu Sep 12, 2023
7ea5eef
design: 더보기와의 간격 추가
bassyu Sep 12, 2023
3013330
chore: <br /> 한줄 제거
bassyu Sep 12, 2023
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
16 changes: 10 additions & 6 deletions frontend/.storybook/decorators.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Decorator } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import { RecoilRoot } from 'recoil';
import { ThemeProvider } from 'styled-components';
Expand All @@ -14,9 +15,12 @@ export const decorateGlobalStyle: Decorator = (Story) => (
</ThemeProvider>
);

export const decorateToastRoot: Decorator = (Story) => (
<>
<div id="toast-root"></div>
<Story />
</>
);
export const decorateQueryClient: Decorator = (Story) => {
const queryClient = new QueryClient();

return (
<QueryClientProvider client={queryClient}>
<Story />
</QueryClientProvider>
);
};
16 changes: 2 additions & 14 deletions frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import type { Preview } from '@storybook/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { initialize, mswLoader } from 'msw-storybook-addon';
import React from 'react';
import { withRouter } from 'storybook-addon-react-router-v6';
import { storybookHandlers } from '../src/mocks/storybookHandlers';
import { decorateGlobalStyle } from './decorators';
import { decorateGlobalStyle, decorateQueryClient } from './decorators';

initialize({
serviceWorker: {
Expand All @@ -24,18 +22,8 @@ const customViewPort = {
},
};

const queryClient = new QueryClient();

const preview: Preview = {
decorators: [
decorateGlobalStyle,
(Story) => (
<QueryClientProvider client={queryClient}>
<Story />
</QueryClientProvider>
),
withRouter,
],
decorators: [decorateGlobalStyle, decorateQueryClient, withRouter],
parameters: {
viewport: {
viewports: { ...INITIAL_VIEWPORTS, ...customViewPort },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { Meta, StoryObj } from '@storybook/react';
import GardenPostItem from '.';

const meta: Meta<typeof GardenPostItem> = {
component: GardenPostItem,
};
WaiNaat marked this conversation as resolved.
Show resolved Hide resolved

export default meta;

type Story = StoryObj<typeof GardenPostItem>;

const defaultArgs = {
createdAt: '1999-12-16',
updatedAt: '1999-12-16',
WaiNaat marked this conversation as resolved.
Show resolved Hide resolved
content: '한달차인데 저는 이거 이렇게 키우고있어요',
manageLevel: '초보자',
petPlant: {
imageUrl: 'https://images.unsplash.com/photo-1667342608690-828e1a839ead',
nickname: '초퍼',
location: '거실',
flowerpot: '플라스틱/유리/캔',
light: '창문 밖에서 해를 받아요',
wind: '창문이 없지만 바람이 통해요',
daySince: 32,
waterCycle: 7,
},
} as const;
WaiNaat marked this conversation as resolved.
Show resolved Hide resolved

export const Default: Story = {
args: defaultArgs,
};

export const LargeContent: Story = {
args: {
...defaultArgs,
content: `
제가 LA에 있을때는 말이죠 정말 제가 꿈에 무대인 메이저리그로 진출해서 가는 식당마다 싸인해달라 기자들은 항상 붙어다니며 취재하고 제가 그 머~ 어~ 대통령이 된 기분이였어요
그런데 17일만에 17일만에 마이너리그로 떨어졌어요 못던져서 그만두고 그냥 확 한국으로 가버리고 싶었어요
그래서 집에 가는길에 그 맥주6개 달린거 있잖아요 맥주6개 그걸 사가지고 집으로 갔어요
그전에는 술먹으면 야구 못하는줄 알았어요 그냥 한국으로
`,
petPlant: {
...defaultArgs.petPlant,
nickname: '박찬호의 길고길고길고길고길고길고길고긴 식물이름',
},
},
};
133 changes: 133 additions & 0 deletions frontend/src/components/garden/GardenPostItem/GardenPostItem.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { styled } from 'styled-components';

export const Wrapper = styled.li`
display: flex;
flex-direction: column;
align-items: center;

width: 100%;
padding: 0 16px;

list-style: none;
`;

export const Header = styled.div`
display: flex;
justify-content: space-between;
width: 100%;
height: 40px;
`;

export const PetPlantImage = styled.img`
width: 40px;
height: 40px;
border-radius: 8px;
`;

export const HeaderContent = styled.div`
display: flex;
flex-direction: column;
justify-content: space-between;

width: 192px;
height: 100%;
margin-right: auto;
margin-left: 16px;
`;

export const PetPlantNickname = styled.p`
overflow: hidden;

font-size: 1.8rem;
font-weight: 500;
text-overflow: ellipsis;
white-space: nowrap;
`;

export const DaySince = styled.p`
font-size: 1.4rem;
font-weight: 500;
color: ${(props) => props.theme.color.sub};
`;

export const PostingDate = styled.p`
width: max-content;
margin-top: 4px;
font-size: 1.2rem;
color: ${(props) => props.theme.color.sub};
`;

export const Environment = styled.section`
display: flex;
flex-direction: column;
row-gap: 8px;
align-items: center;

width: 100%;
margin-top: 16px;
padding: 16px;

background-color: ${({ theme }) => theme.color.primary}13;
border-radius: 8px;
`;

export const EnvironmentItem = styled.p`
display: flex;
column-gap: 8px;
align-items: center;

width: 100%;

font-size: 1.4rem;
`;

export const EnvironmentTitle = styled.span`
display: inline-flex;
align-items: center;
justify-content: center;

width: 24px;
height: 24px;

color: ${({ theme }) => theme.color.primary};

background: ${({ theme }) => theme.color.background};
border-radius: 50%;
`;

export const TagArea = styled.div`
display: flex;
width: 100%;
margin-top: 24px;

& > div + div {
margin-left: 8px;
}
`;

export const Tag = styled.div`
width: max-content;
padding: 8px 12px;

font-size: 1.2rem;
font-weight: 700;
color: ${(props) => props.theme.color.sub};

border: solid 1.6px;
border-radius: 16px;
`;

export const WaterCycleTag = styled(Tag)`
border-color: ${({ theme }) => theme.color.water};
`;

export const ManageLevelTag = styled(Tag)`
border-color: ${({ theme }) => theme.color.primary};
`;

export const Content = styled.div`
width: 100%;
margin-top: 24px;
font-size: 1.6rem;
color: ${(props) => props.theme.color.sub};
`;
116 changes: 116 additions & 0 deletions frontend/src/components/garden/GardenPostItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import type { GardenPostItem as GardenPostItemType } from 'types/garden';
import Flowerpot from 'components/@common/Icons/Flowerpot';
import House from 'components/@common/Icons/House';
import Sun from 'components/@common/Icons/Sun';
import Wind from 'components/@common/Icons/Wind';
import { convertDateKorYear } from 'utils/date';
import theme from 'style/theme.style';
import {
Content,
DaySince,
Environment,
EnvironmentItem,
EnvironmentTitle,
Header,
HeaderContent,
ManageLevelTag,
PetPlantImage,
PetPlantNickname,
PostingDate,
TagArea,
WaterCycleTag,
Wrapper,
} from './GardenPostItem.styles';

type GardenPostItemProps = Omit<GardenPostItemType, 'id' | 'updatedAt'>;
WaiNaat marked this conversation as resolved.
Show resolved Hide resolved

const GardenPostItem = ({ content, createdAt, manageLevel, petPlant }: GardenPostItemProps) => {
const postingDate = convertDateKorYear(createdAt).slice(5);
Copy link
Collaborator

Choose a reason for hiding this comment

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

C

저는 년/월/일을 보여주는게 훨씬 낫다고 생각해요! 데이터가 쌓일수록 년도에 혼란이 올 수도 있는데, 명확하게 넣는게 좋을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

좋아요! 년/월/일로 적용하겠습니다~


return (
<Wrapper>
<Header>
<PetPlantImage src={petPlant.imageUrl} />
WaiNaat marked this conversation as resolved.
Show resolved Hide resolved
<HeaderContent>
<PetPlantNickname>{petPlant.nickname}</PetPlantNickname>
Copy link
Member

Choose a reason for hiding this comment

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

C

화면이 길쭉할 때는 좀더 길었으면 좋겠어요!
image

<DaySince>
함께한지 <span>{petPlant.daySince}</span>일째
</DaySince>
</HeaderContent>
<PostingDate>{postingDate}</PostingDate>
</Header>
<Environment>
<EnvironmentItem>
<EnvironmentTitle>
<House
color={theme.color.primary}
aria-label="장소"
aria-describedby="반려 식물이 놓인 공간"
width="20px"
height="20px"
/>
</EnvironmentTitle>
{petPlant.location}
</EnvironmentItem>
<EnvironmentItem>
<EnvironmentTitle>
<Flowerpot
color={theme.color.primary}
aria-label="화분"
aria-describedby="반려 식물이 담긴 화분의 재질"
width="20px"
height="20px"
/>
</EnvironmentTitle>
{petPlant.flowerpot}
</EnvironmentItem>
<EnvironmentItem>
<EnvironmentTitle>
<Sun
color={theme.color.primary}
aria-label="채광"
aria-describedby="반려 식물이 빛을 얼마나 받고 있는지"
width="20px"
height="20px"
/>
</EnvironmentTitle>
{petPlant.light}
</EnvironmentItem>
<EnvironmentItem>
<EnvironmentTitle>
<Wind
color={theme.color.primary}
aria-label="바람"
aria-describedby="반려 식물이 통풍이 잘 되는 위치인지"
width="20px"
height="20px"
/>
</EnvironmentTitle>
{petPlant.wind}
</EnvironmentItem>
</Environment>
<TagArea>
<WaterCycleTag>물 주기: {petPlant.waterCycle}일</WaterCycleTag>
<ManageLevelTag>{manageLevel}에게 추천해요</ManageLevelTag>
</TagArea>
<Content>
{content
Copy link
Collaborator

Choose a reason for hiding this comment

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

C

문단을 나누는 메서드가 2군데에서 사용되는데 분리하는 것에 동의합니다!

.trim()
.split(/(?:\r?\n)+/)
.map((paragraph, index) =>
index ? (
<>
<br />
<br />
{paragraph}
</>
) : (
paragraph
)
)}
</Content>
</Wrapper>
);
};

export default GardenPostItem;
21 changes: 21 additions & 0 deletions frontend/src/types/garden.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ManageLevel } from './dictionaryPlant';
import type { PetPlantDetails } from './petPlant';

export interface GardenPostItem {
id: number;
content: string;
createdAt: string;
updatedAt: string;
manageLevel: Exclude<ManageLevel, '정보없음'>;
petPlant: Pick<
PetPlantDetails,
| 'imageUrl'
| 'nickname'
| 'location'
| 'flowerpot'
| 'light'
| 'wind'
| 'daySince'
| 'waterCycle'
>;
}