From 0a5a7577af68961b5f720afa071d4dca18a8dfa4 Mon Sep 17 00:00:00 2001 From: say-young516 Date: Thu, 21 Jul 2022 17:32:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[=20fix=20]=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=EC=84=B9=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/viewProduct/FilterDropdown.tsx | 2 +- components/viewProduct/ProductFilter.tsx | 2 +- core/atom.ts | 48 +++++++++++------------ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/components/viewProduct/FilterDropdown.tsx b/components/viewProduct/FilterDropdown.tsx index 3e20528..228b63a 100644 --- a/components/viewProduct/FilterDropdown.tsx +++ b/components/viewProduct/FilterDropdown.tsx @@ -64,7 +64,7 @@ export default function FilterDropdown(props: FilterDropdownProps) { isDrop ? 'slide-fade-in-dropdown' : 'slide-fade-out-dropdown' }`} > - {categoryKey === '장난감 종류' && toyKindList.length !== 0 + {categoryKey === '종류' && toyKindList.length !== 0 ? toyKindList.map((tagText: string, elementIdx: number) => { return ( Date: Thu, 21 Jul 2022 18:02:06 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[=20fix=20]=20=EB=A1=9C=EC=BB=AC=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=A7=80=20=EC=98=A4=EB=A5=98=20=EC=9E=A1?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/axios.ts | 10 ++++------ core/localStorage.ts | 9 +++++++-- pages/index.tsx | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/axios.ts b/core/axios.ts index f0e782e..117ac55 100644 --- a/core/axios.ts +++ b/core/axios.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import LocalStorage from './localStorage'; +console.log(process.env.NEXT_PUBLIC_BASE_URL); const baseInstance = axios.create({ baseURL: `${process.env.NEXT_PUBLIC_BASE_URL}`, headers: { @@ -26,13 +27,10 @@ baseInstance.interceptors.response.use( return res; }, async function (error: { config: any; response: { status: any } }) { - const { - config, - response: { status }, - } = error; - + const { config, response } = error; + console.log(error); const originalRequest = config; - if (status === 401) { + if (response?.status === 401) { // token refresh 요청 const { data } = await axios.post( `/auth/token/refresh`, // token refresh api diff --git a/core/localStorage.ts b/core/localStorage.ts index 10287ef..bc9d351 100644 --- a/core/localStorage.ts +++ b/core/localStorage.ts @@ -2,11 +2,16 @@ class LocalStorage { constructor() {} static setItem(key: string, item: string) { - localStorage.setItem(key, item); + if (typeof window !== 'undefined') { + localStorage.setItem(key, item); + } } static getItem(key: string) { - return localStorage.getItem(key) as string; + if (typeof window !== 'undefined') { + return localStorage.getItem(key) as string; + } + return ''; } static removeItem(key: string) { diff --git a/pages/index.tsx b/pages/index.tsx index 5ce95be..33c7181 100755 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -156,6 +156,7 @@ const StCollectionTitle = styled(StConceptTitle)` `; export const getStaticProps: GetStaticProps = async (context) => { const res = await getMainProduct(); + console.log(res); return { props: { mainData: res.data.data, From 624a31c9dff355ce76f467686642dcb4e73e2f57 Mon Sep 17 00:00:00 2001 From: seohee0112 Date: Thu, 21 Jul 2022 18:28:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[=20feat=20]=20=EC=83=81=ED=92=88=EB=B3=B4?= =?UTF-8?q?=EA=B8=B0=20api=20=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/viewProduct/ToyList.tsx | 8 +++---- components/viewProduct/ToyPreview.tsx | 4 +++- core/api/viewProduct.ts | 2 +- pages/viewProduct.tsx | 30 +++++++++++++++------------ types/toy.ts | 23 +++++++++++++------- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/components/viewProduct/ToyList.tsx b/components/viewProduct/ToyList.tsx index 017bdf5..bbddddc 100644 --- a/components/viewProduct/ToyList.tsx +++ b/components/viewProduct/ToyList.tsx @@ -11,15 +11,15 @@ export default function ToyList(props: ToyListProps) { return ( - {toyList.map(({ image, title, price, month, siteUrl }, idx) => ( + {toyList.map(({ image, title, price, month, link, toySite }, idx) => ( ))} diff --git a/components/viewProduct/ToyPreview.tsx b/components/viewProduct/ToyPreview.tsx index 05826f6..ad34a7c 100644 --- a/components/viewProduct/ToyPreview.tsx +++ b/components/viewProduct/ToyPreview.tsx @@ -29,7 +29,9 @@ export default function ToyPreview(props: ToyPreviewProps) { return ( - + {isMark && } diff --git a/core/api/viewProduct.ts b/core/api/viewProduct.ts index e0eb76e..b09c1e5 100644 --- a/core/api/viewProduct.ts +++ b/core/api/viewProduct.ts @@ -15,5 +15,5 @@ export const useGetBannerViewProduct = (params: { category: number }) => { }; }; export const getBannerViewProduct = () => { - return; + return baseInstance.get('/toy/list'); }; diff --git a/pages/viewProduct.tsx b/pages/viewProduct.tsx index 96945e4..291c76a 100644 --- a/pages/viewProduct.tsx +++ b/pages/viewProduct.tsx @@ -16,22 +16,27 @@ import { } from '../components/landing/viewProduct'; import { PriceFilter, PageNavigation } from '../components/common'; import { ToyData } from '../types/toy'; -import { toyMockData } from '../mocks/data/toyMockData'; import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import { useRecoilValue } from 'recoil'; import { FilterTagProps } from '../types/viewProduct'; import { filterTagState } from '../core/atom'; import { IcGrayEmpty } from '../public/assets/icons'; +import { + getBannerViewProduct, + useGetBannerViewProduct, +} from '../core/api/viewProduct'; const limit = 40; export default function viewProduct({ - data, + filterData, + result, }: InferGetServerSidePropsType) { + console.log(filterData, result); const [priceDesc, setPriceDesc] = useState(true); const [toyList, setToyList] = useState([]); const [currentPage, setCurrentPage] = useState(1); - console.log(data); + const handleClickPrice = (clickPrice: string) => { clickPrice === 'price-desc' ? setPriceDesc(true) : setPriceDesc(false); }; @@ -39,10 +44,7 @@ export default function viewProduct({ const handleCurrentPage = (nextPage: number) => { setCurrentPage(nextPage); }; - - const [selectPrice, setSelectPrice] = useState([true, false]); // useSWR로 로딩 판단할 것임 - const isLoading = false; const filterTagList = useRecoilValue(filterTagState); // let { productList, isLoading, isError } = priceDesc @@ -50,19 +52,19 @@ export default function viewProduct({ // : (useGetCollectionProduct('price-asc') as GetCollectionProduct); useEffect(() => { - if (data) { - const filterData = data.filter( + if (result) { + const filterData = result.filter( (_: any, idx: number) => (currentPage - 1) * 40 <= idx && idx < currentPage * 40, ); setToyList(filterData); window.scrollTo(0, 0); } - }, [data, currentPage]); + }, [result, currentPage]); return ( - {false ? ( + {!filterData ? ( <> @@ -113,7 +115,7 @@ export default function viewProduct({ @@ -155,10 +157,12 @@ const StEmptyView = styled.section` margin: 0 23.8rem; `; export const getServerSideProps: GetServerSideProps = async (context) => { - const data: ToyData[] = toyMockData; + const res = await getBannerViewProduct(); + console.log(res.data.data); return { props: { - data, + filterData: res.data.data.filterData, + result: res.data.data.result, }, }; }; diff --git a/types/toy.ts b/types/toy.ts index 0a3b045..aaa1493 100644 --- a/types/toy.ts +++ b/types/toy.ts @@ -1,13 +1,22 @@ export interface ToyData { - price: number; //가격 - priceCode?: number; - image: string; //이미지 - siteUrl: string; + id: number; title: string; + price: number; //가격 + priceCd?: number; month?: string; //연령 - playHow: number; - type: number; - siteName: string; + minMonth: number; + maxMonth: number; + link: string; + playHow: string; + playHowCd: number; + image: string; //이미지 + category: string; + categoryCd: number; + toySiteCd: number; + toySite: { + id: number; + toySite: string; + }; } export interface MainToyData {