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 all 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,29 @@
import type { Meta, StoryObj } from '@storybook/react';
import SeeMoreContentBox from '.';

const meta: Meta<typeof SeeMoreContentBox> = {
component: SeeMoreContentBox,
};

export default meta;

type Story = StoryObj<typeof SeeMoreContentBox>;

export const ShortContent: Story = {
args: {
maxHeight: '32px',
children: '안녕하세요',
},
};

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

export const Wrapper = styled.div<{ $hiddenOver: boolean; $maxHeight: string }>`
position: relative;
width: 100%;
height: ${({ $hiddenOver, $maxHeight }) => ($hiddenOver ? $maxHeight : 'max-content')};
`;

export const ContentBox = styled.div<{ $hiddenOver: boolean; $maxHeight: string }>`
overflow: hidden;
max-height: ${({ $hiddenOver, $maxHeight }) =>
$hiddenOver ? `calc(${$maxHeight} - 1.6rem)` : ''};
`;

export const SeeMoreButtonArea = styled.div`
position: absolute;
z-index: ${(props) => props.theme.zIndex.fixed};
bottom: 0;
display: flex;
justify-content: start;
width: 100%;
`;

export const SeeMoreButton = styled.button`
width: max-content;
height: 1.2rem;
font-size: 1.2rem;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState } from 'react';

type ShowState = 'NOT_OVER' | 'HIDDEN_OVER' | 'SHOW_OVER';

const useShowState = (maxHeight: `${number}px`) => {
const [showState, setShowState] = useState<ShowState>('NOT_OVER');

const wrapperRef = (instance: HTMLDivElement | null) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

C

해당 함수의 역할이 제가 이해하기로는 show의 상태를 HIDDEN_OVER를 시키는 함수 같은데 warpperRef라고 명명하신 이유가 있을까요?

Copy link
Member Author

@bassyu bassyu Sep 12, 2023

Choose a reason for hiding this comment

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

ref로 instance를 받아야만 해서 이렇게 작성하긴 했습니다!
setInitialShow도 고려해봤어요!

Copy link
Collaborator

Choose a reason for hiding this comment

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

instance로 받는 것이라면, 그 파라마터의 이름이 instanceRef와 같은 식으로 가고, 변수 명은 행동 위주로 가면 더 좋을것 같긴 하네요!

if (!instance) return;

const maxHeightNumber = Number(maxHeight.slice(0, -2));

if (showState === 'NOT_OVER' && instance.offsetHeight > maxHeightNumber) {
setShowState('HIDDEN_OVER');
}
};

const showOver = () => {
setShowState('SHOW_OVER');
};

Copy link
Member

Choose a reason for hiding this comment

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

C

SHOW_OVER일 때 다시 숨기는 기능을 추가하는 건 어떠신가요??

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 { showState, wrapperRef, showOver };
};

export default useShowState;
33 changes: 33 additions & 0 deletions frontend/src/components/@common/SeeMoreContentBox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Fragment } from 'react';
import { ContentBox, SeeMoreButton, SeeMoreButtonArea, Wrapper } from './SeeMoreContentBox.styles';
import useShowState from './hooks/useShowState';

interface SeeMoreContentBoxProps {
children: string;
Copy link
Member

Choose a reason for hiding this comment

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

오 이걸 PropsWithChildren을 안써도 children을 제대로 받아오네요 😲

Copy link
Member Author

Choose a reason for hiding this comment

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

맞아요! children 이라는 네이밍의 필드면 가져옵니다~

maxHeight?: `${number}px`;
}

const SeeMoreContentBox = ({ children: content, maxHeight = '64px' }: SeeMoreContentBoxProps) => {
const { showState, wrapperRef, showOver } = useShowState(maxHeight);
const paragraphList = content.trim().split(/(?:\r?\n)+/);

return (
<Wrapper ref={wrapperRef} $maxHeight={maxHeight} $hiddenOver={showState === 'HIDDEN_OVER'}>
<ContentBox $maxHeight={maxHeight} $hiddenOver={showState === 'HIDDEN_OVER'}>
{paragraphList.map((paragraph, index) => (
<Fragment key={paragraph}>
{index !== 0 && <br />}
<p>{paragraph}</p>
</Fragment>
))}
</ContentBox>
{showState === 'HIDDEN_OVER' && (
<SeeMoreButtonArea>
<SeeMoreButton onClick={showOver}>더보기</SeeMoreButton>
</SeeMoreButtonArea>
)}
</Wrapper>
);
};

export default SeeMoreContentBox;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PottedPlant from 'components/@common/Icons/PottedPlant';
import ThermometerSnow from 'components/@common/Icons/ThermometerSnow';
import ThermometerSun from 'components/@common/Icons/ThermometerSun';
import Warning from 'components/@common/Icons/Warning';
import SeeMoreContentBox from 'components/@common/SeeMoreContentBox';
import TagBox from 'components/dictionaryPlant/TagBox';
import TagSwitch from 'components/dictionaryPlant/TagSwitch';
import {
Expand Down Expand Up @@ -159,22 +160,9 @@ const DictionaryPlantContent = (props: DictionaryPlantExtendCycles) => {
<ManageInfoBox>
<p>특별 관리 정보</p>
<span>
{specialManageInfo !== NO_INFORMATION
? specialManageInfo
.trim()
.split(/(?:\r?\n)+/)
.map((paragraph, index) =>
index ? (
<>
<br />
<br />
{paragraph}
</>
) : (
paragraph
)
)
: '관련 정보가 없어요😇'}
<SeeMoreContentBox>
{specialManageInfo !== NO_INFORMATION ? specialManageInfo : '관련 정보가 없어요😇'}
</SeeMoreContentBox>
</span>
</ManageInfoBox>
</ContentBox>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Meta, StoryObj } from '@storybook/react';
import { ComponentProps } from 'react';
import GardenPostItem from '.';

const meta: Meta<typeof GardenPostItem> = {
component: GardenPostItem,
argTypes: {
createdAt: {
table: {
type: {
summary: 'DateFormat',
detail: 'YYYY-MM-DD 형식의 문자열',
},
},
control: 'text',
},
},
};

export default meta;

type Story = StoryObj<typeof GardenPostItem>;

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

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

export const LargeContent: Story = {
args: {
...defaultArgs,
dictionaryPlantName: '아스파라거스 풀루모수스',
content: `
제가 LA에 있을때는 말이죠 정말 제가 꿈에 무대인 메이저리그로 진출해서 가는 식당마다 싸인해달라 기자들은 항상 붙어다니며 취재하고 제가 그 머~ 어~ 대통령이 된 기분이였어요
그런데 17일만에 17일만에 마이너리그로 떨어졌어요 못던져서 그만두고 그냥 확 한국으로 가버리고 싶었어요
그래서 집에 가는길에 그 맥주6개 달린거 있잖아요 맥주6개 그걸 사가지고 집으로 갔어요
그전에는 술먹으면 야구 못하는줄 알았어요 그냥 한국으로
`,
petPlant: {
...defaultArgs.petPlant,
nickname: '박찬호의 길고길고길고길고길고길고길고긴 식물이름',
},
},
};
Loading