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/#300 best piickle #301

Merged
merged 14 commits into from
Jul 16, 2023
Merged
53 changes: 53 additions & 0 deletions src/@components/@common/BestPiickleCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { LocationType } from "../../../types/cardCollection";
import { GTM_CLASS_NAME } from "../../../util/const/gtm";
import useNavigateCardCollection, { NavigateCardCollectionBestType } from "../hooks/useNavigateCardCollection";
import * as St from "./style";

interface BestPiickleCardProps {
bestPiickle: {
_id: string;
tags: string[];
content: string;
};
idx: number;
canNavigate: boolean;
isLast?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

(생각해보면 좋을 것 같아요)
last card에 대한 내용을 컴포넌트로 분리해서 LastBestPiickleCard로 하지 않고,
컴포넌트 내에서 last card에 대한 내용을 하는 것이 옳은 인터페이스일까요?
장단점이 뭘까요???

Copy link
Member Author

Choose a reason for hiding this comment

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

해놓고 리팩토링한다는 걸 깜빡했네요😅
단점은 아무래도 파일이 많아지면서 번들 크기가 증가한다는 것일거고, 경우에 따라 props drilling문제도 생길 것 같아요!
그런데 지금 LastCard는 필요로하는 props가 없으니까 말씀하신대로 컴포넌트를 분리하는 게 좋을 것 같아요:)

}

export default function BestPiickleCard(props: BestPiickleCardProps) {
Copy link
Member

Choose a reason for hiding this comment

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


파일 분리 + 피처 작업은 커밋을 분리해줘야 변경 사항을 확인하기 수월할 것 같아요 !!

Copy link
Member Author

Choose a reason for hiding this comment

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

생각없이 해버렸네요 🥲 주의하겠습니다

const { bestPiickle, idx, canNavigate, isLast } = props;
const { content, tags } = bestPiickle;
const GTM_IDX_KEY = `mainBestPiickle${idx + 1}`;

const navigateCardCollection = useNavigateCardCollection(LocationType.BEST) as NavigateCardCollectionBestType;

const onClickCard = () => {
if (!canNavigate) return;
navigateCardCollection(idx);
};
Comment on lines +24 to +27
Copy link
Member

Choose a reason for hiding this comment

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

(생각해보면 좋을 것 같아요)

  • 따로 빼준 이유가 있나요??
  • handle~이 아니라, on~ 인 이유가 있나요??

Copy link
Member Author

Choose a reason for hiding this comment

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

  • 두줄 이상이라면 따로 빼는게 가독성이 좋을 거라고 생각했습니다!
  • 앗 습관상 on으로 적어버렸네요 ! 다른 핸들러들은 handle인것 확인했습니다. 바꿀게요!


return (
<St.Container type="button" className={GTM_CLASS_NAME[GTM_IDX_KEY]} onClick={onClickCard}>
{isLast ? (
Copy link
Member

Choose a reason for hiding this comment

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

변수명이 요게 맞나요??? 바뀐 것 같은..!

Copy link
Member Author

Choose a reason for hiding this comment

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

isLast 말씀하시는거 맞나요? 바뀌었다는게 무슨 말이죠?!

<St.BestPiickleCard className={GTM_CLASS_NAME[GTM_IDX_KEY]}>
<St.TagsWrapper className={GTM_CLASS_NAME[GTM_IDX_KEY]}>
{tags.map((tag: string, i: number) => {
return <St.Tag key={i}>{tag.slice(1)}</St.Tag>;
})}
</St.TagsWrapper>
<St.Content className={GTM_CLASS_NAME[GTM_IDX_KEY]}>{content}</St.Content>
<St.PickButtonWrapper className={GTM_CLASS_NAME[GTM_IDX_KEY]}>카드 보기</St.PickButtonWrapper>
</St.BestPiickleCard>
) : (
<St.LastCard>
<St.Content>
나머지 주제들도
<br />
보고 싶다면?
</St.Content>
<St.LastCardButton>나머지 보기</St.LastCardButton>
</St.LastCard>
)}
</St.Container>
);
}
71 changes: 71 additions & 0 deletions src/@components/@common/BestPiickleCard/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import styled from "styled-components";

export const Container = styled.button``;

export const BestPiickleCard = styled.div`
position: relative;

width: 18rem;
height: 10.6rem;

padding: 0.8rem 1.2rem;

border-radius: 0.4rem;
background: ${({ theme }) => theme.newColors.lightgreen2};
`;

export const TagsWrapper = styled.ul`
display: flex;
gap: 0.8rem;
`;

export const Tag = styled.li`
${({ theme }) => theme.newFonts.caption1};
color: ${({ theme }) => theme.newColors.green};
`;

export const Content = styled.p`
margin-top: 0.4rem;

text-align: left;

white-space: normal;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;

${({ theme }) => theme.newFonts.btn1}
color: ${({ theme }) => theme.newColors.gray900};
`;

export const PickButtonWrapper = styled.div`
margin-top: 1.2rem;

${({ theme }) => theme.newFonts.btn2};
color: ${({ theme }) => theme.newColors.gray700};

text-align: right;
`;

export const LastCard = styled(BestPiickleCard)`
display: flex;
flex-direction: column;

padding-top: 2.1rem;
background: ${({ theme }) => theme.newColors.white};
`;

export const LastCardButton = styled.button`
margin-top: 1.2rem;
align-self: flex-end;

width: 6.9rem;
height: 2.5rem;

border-radius: 2.9rem;
background: ${({ theme }) => theme.newColors.green};

color: ${({ theme }) => theme.newColors.white};
${({ theme }) => theme.newFonts.btn2}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BestPiickleCard from "../../../@common/BestPiickleCard";
import useDraggingContainer from "../../../@common/hooks/useDraggingContainer";
import BestPiickleCard from "../../../MainPage/BestPiickle/BestPiickleCard";
import { useBestPiickle } from "../../../MainPage/hooks/useBestPiickle";
import * as St from "./style";

Expand All @@ -18,9 +18,15 @@ export default function RecommendItem(props: RecommendProps) {
{bestPiickle && (
<St.SliderWrapper {...scrollableContainerProps}>
{bestPiickle &&
bestPiickle.data.slice(0, 5).map((bestPiickle, idx) => {
bestPiickle.data.slice(0, 4).map((bestPiickle, idx) => {
return (
<BestPiickleCard key={bestPiickle._id} bestPiickle={bestPiickle} idx={idx} canNavigate={!isDragging} />
<BestPiickleCard
key={bestPiickle._id}
bestPiickle={bestPiickle}
idx={idx}
canNavigate={!isDragging}
isLast={idx !== 3}
/>
);
})}
</St.SliderWrapper>
Expand Down
44 changes: 0 additions & 44 deletions src/@components/MainPage/BestPiickle/BestPiickleCard/index.tsx

This file was deleted.

60 changes: 0 additions & 60 deletions src/@components/MainPage/BestPiickle/BestPiickleCard/style.ts

This file was deleted.

10 changes: 8 additions & 2 deletions src/@components/MainPage/BestPiickle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { routePaths } from "../../../core/routes/path";
import { headingTitles } from "../../../util/main/headingTitles";
import BestPiickleCard from "../../@common/BestPiickleCard";
import HeadingTitleContainer from "../../@common/HeadingTitleContainer";
import useDraggingContainer from "../../@common/hooks/useDraggingContainer";
import { useBestPiickle } from "../hooks/useBestPiickle";
import BestPiickleCard from "./BestPiickleCard";
import St from "./style";

export default function BestPiickle() {
Expand All @@ -23,7 +23,13 @@ export default function BestPiickle() {
{bestPiickle &&
bestPiickle.data.slice(0, 5).map((bestPiickle, idx) => {
return (
<BestPiickleCard key={bestPiickle._id} bestPiickle={bestPiickle} idx={idx} canNavigate={!isDragging} />
<BestPiickleCard
key={bestPiickle._id}
bestPiickle={bestPiickle}
idx={idx}
canNavigate={!isDragging}
isLast={idx !== 5}
Copy link
Member

@joohaem joohaem Jul 9, 2023

Choose a reason for hiding this comment

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

slice(0, 5) 면 idx가 0-4 아닌가요.>~!?

Copy link
Member Author

Choose a reason for hiding this comment

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

로직을 잘못 생각했었어요! isLast이면 기본카드가 나오게 해놨었네요 !isLast로 고쳤어요
알주셔서 감삼다 (_ _)

/>
);
})}
</St.SliderWrapper>
Expand Down