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

페이지 기능: 홈페이지 쿼리훅 제작 #133

Merged
merged 7 commits into from
Jan 30, 2024
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
555 changes: 25 additions & 530 deletions src/app/page.tsx

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions src/components/shared/carousel/Banner.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

import { MOCK_BANNER_DATA } from '@mocks/homeHandler/mocks';

import Banner from './Banner';

const meta = {
Expand All @@ -20,17 +22,6 @@ type Story = StoryObj<typeof meta>;

export const AdBanner: Story = {
args: {
bannerData: [{
id: 1, link: '/', src: '/assets/banner.png', alt: '그림',
},
{
id: 2, link: '/', src: '/assets/banner.png', alt: '그림',
},
{
id: 3, link: '/', src: '/assets/banner.png', alt: '그림',
},
{
id: 4, link: '/', src: '/assets/banner.png', alt: '그림',
}],
bannerData: MOCK_BANNER_DATA,
},
};
8 changes: 5 additions & 3 deletions src/components/shared/carousel/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Image from 'next/image';
import Link from 'next/link';

import './Banner.scss';
import { IBannerData } from './types/carousel.type';
import { BannerType } from '@remote/api/types/home';

const settings = {
dots: true,
Expand All @@ -20,11 +20,13 @@ const settings = {
arrows: false,
};

function Banner({ bannerData }: { bannerData: IBannerData[] }) {
function Banner({ bannerData }: { bannerData: BannerType }) {
const bannerList = bannerData.value;

return (
<div className="container">
<Slider {...settings} dotsClass="dotsCustom">
{bannerData.map((slide) => {
{bannerList.map((slide) => {
return (
<Link href={slide.link} key={slide.id}>
<Image
Expand Down
54 changes: 3 additions & 51 deletions src/components/shared/carousel/RecommendList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

import { MOCK_RECOMMEND_PRODUCTS } from '@mocks/homeHandler/mocks';

import RecommendList from './RecommendList';

const meta = {
Expand All @@ -9,9 +11,6 @@ const meta = {
},
tags: ['autodocs'],
argTypes: {
recommendListData: {
control: 'object',
},
},
} satisfies Meta<typeof RecommendList>;

Expand All @@ -20,53 +19,6 @@ type Story = StoryObj<typeof meta>;

export const AdBanner: Story = {
args: {
recommendListData: [
{
id: 1,
link: '/',
src: '/assets/recommendItem1.png',
alt: '그림',
productName: '카샴푸',
},
{
id: 2,
link: '/',
src: '/assets/recommendItem2.png',
alt: '그림',
productName: '휠 클리너',
},
{
id: 3,
link: '/',
src: '/assets/recommendItem3.png',
alt: '그림',
productName: '타올',

},
{
id: 4,
link: '/',
src: '/assets/recommendItem4.png',
alt: '그림',
productName: '먼지털이개',

},
{
id: 5,
link: '/',
src: '/assets/recommendItem4.png',
alt: '그림',
productName: '먼지털이개',

},
{
id: 6,
link: '/',
src: '/assets/recommendItem4.png',
alt: '그림',
productName: '먼지털이개',

},
],
recommendProductsData: MOCK_RECOMMEND_PRODUCTS,
},
};
10 changes: 6 additions & 4 deletions src/components/shared/carousel/RecommendList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import Slider from 'react-slick';
import Image from 'next/image';
import Link from 'next/link';

import { RecommendProductsType } from '@remote/api/types/home';
import Flex from '@shared/flex/Flex';
import Text from '@shared/text/Text';

import { IRecommendList } from './types/carousel.type';

const settings = {
dots: false,
infinite: true,
Expand All @@ -22,10 +21,13 @@ const settings = {
arrows: false,
};

function RecommendList({ recommendListData }: { recommendListData: IRecommendList[] }) {
// eslint-disable-next-line max-len
function RecommendList({ recommendProductsData }: { recommendProductsData: RecommendProductsType }) {
const recommendList = recommendProductsData.value;

return (
<Slider {...settings}>
{recommendListData?.map((slide) => {
{recommendList?.map((slide) => {
return (
<Flex justify="center" align="center" direction="column" key={slide.id}>
<Link href={slide.link}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

import { MOCK_PRODUCT_LIST } from '@mocks/homeHandler/mocks';

import ProductArticle from './ProductArticle';

const meta: Meta = {
Expand All @@ -12,35 +14,21 @@ const meta: Meta = {
control: 'object',
},
},
}satisfies Meta<typeof ProductArticle>;
} satisfies Meta<typeof ProductArticle>;

export default meta;
type Story = StoryObj<typeof meta>;

export const MainPage: Story = {
args: {
isRow: false,
itemData: {
id: 1,
img: '/assets/profile.JPG',
name: '아머올 세차용품 스피드 왁스 스프레이 500ml스피드 왁스 스프레이 500ml',
brand: '카믹스',
category: '코팅제',
warningLevel: 'warning',
},
itemData: MOCK_PRODUCT_LIST,
},
};

export const SearchPage: Story = {
args: {
isRow: true,
itemData: {
id: 2,
img: '/assets/profile.JPG',
name: '아머올 세차용품 스피드 왁스 스프레이 500ml',
brand: '카믹스',
category: '코팅제',
warningLevel: 'safe',
},
itemData: MOCK_PRODUCT_LIST,
},
};
4 changes: 2 additions & 2 deletions src/components/shared/product-article/ProductArticle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import classNames from 'classnames/bind';
import Image from 'next/image';

import Heart from '@components/icons/Heart';
import { IProduct } from '@remote/api/types/home';
import Text from '@shared/text/Text';

import styles from './ProductArticle.module.scss';
import { IItemData } from './types/ProductArticleType';

interface ProductArticleProps {
isRow?: boolean;
itemData: IItemData
itemData: IProduct
}

const cx = classNames.bind(styles);
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { authHandlers } from './authHandler';
import { homeHandlers } from './homeHandler';

export const handlers = [
...authHandlers,
...homeHandlers,
];
23 changes: 23 additions & 0 deletions src/mocks/homeHandler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { http, HttpResponse } from 'msw';

import {
MOCK_BANNER_DATA, MOCK_PRODUCT_LIST, MOCK_RECOMMEND_PRODUCTS,
} from './mocks';

export const homeHandlers = [
/* ----- 배너 api ----- */
http.get(`${process.env.NEXT_PUBLIC_BASE_URL}/banner`, () => {
return HttpResponse.json(MOCK_BANNER_DATA);
}),

/* ----- 추천 제품 정보 api ----- */
http.get(`${process.env.NEXT_PUBLIC_BASE_URL}/recommend_products`, () => {
return HttpResponse.json(MOCK_RECOMMEND_PRODUCTS);
}),

/* ----- 제품 목록 정보 api ----- */
http.get(`${process.env.NEXT_PUBLIC_BASE_URL}/products?sortType=viewcnt_order`, () => {
return HttpResponse.json(MOCK_PRODUCT_LIST);
}),
];
Loading
Loading