Skip to content

Commit

Permalink
Merge branch 'feature-community' into comment/#138
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Jul 21, 2022
2 parents 50464ee + 6960398 commit ae6044c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 60 deletions.
2 changes: 1 addition & 1 deletion components/viewProduct/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<StLabel
Expand Down
2 changes: 1 addition & 1 deletion components/viewProduct/ProductFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function ProductFilter() {
categoryInfo={filterListData[idx]}
categoryIdx={idx}
isExcept={
idx == 3 || (idx == 4 && toyKindList.length !== 0)
idx == 3 || (idx == 0 && toyKindList.length !== 0)
? true
: false
}
Expand Down
8 changes: 4 additions & 4 deletions components/viewProduct/ToyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default function ToyList(props: ToyListProps) {

return (
<StToyListWrapper>
{toyList.map(({ image, title, price, month, siteUrl }, idx) => (
{toyList.map(({ image, title, price, month, link, toySite }, idx) => (
<ToyPreview
key={idx}
src={image}
store="그린키드그린키드그린키드그린키드그린키드그린키드그린키드그린키드그린키드그린키드"
store={toySite.toySite}
title={title}
price={price}
age="36개월이상"
siteUrl={siteUrl}
age={month}
siteUrl={link}
/>
))}
</StToyListWrapper>
Expand Down
4 changes: 3 additions & 1 deletion components/viewProduct/ToyPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default function ToyPreview(props: ToyPreviewProps) {
return (
<StToyWrapper onClick={handleToySite}>
<StImgWrapper>
<StToyImg src="https://www.littlebaby.co.kr:14019/shop/data/goods/1632018070797m0.jpg" />
<StToyImg
src={`https://nori-image.s3.ap-northeast-2.amazonaws.com/${src}`}
/>
<StToyMarkWrapper onClick={handleToyMark}>
<StToyMark />
{isMark && <StFillToyMark />}
Expand Down
2 changes: 1 addition & 1 deletion core/api/viewProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export const useGetBannerViewProduct = (params: { category: number }) => {
};
};
export const getBannerViewProduct = () => {
return;
return baseInstance.get('/toy/list');
};
48 changes: 24 additions & 24 deletions core/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,7 @@ export const filterListState = atom({
key: 'filterListState',
default: {
filterList: {
스토어: [
'국민장난감',
'그린키드',
'러브로',
'리틀베이비',
'빌리바바',
'어텐션홈이벤트',
'장난감점빵',
'젤리바운스',
'해피장난감',
],
'사용 연령': [
'0~5개월',
'6~11개월',
'12~17개월',
'18~23개월',
'24~35개월',
'36~47개월',
'48~60개월',
'기타',
],
가격: ['1만원 미만', '1-3만원', '3-5만원', '5-8만원', '8만원이상'],
특성: ['타고 노는', '만지고 노는', '기타'],
'장난감 종류': [
종류: [
'아기체육관',
'모빌',
'바운서',
Expand All @@ -87,6 +64,29 @@ export const filterListState = atom({
'역할놀이',
'기타',
],
'사용 연령': [
'0~5개월',
'6~11개월',
'12~17개월',
'18~23개월',
'24~35개월',
'36~47개월',
'48~60개월',
'기타',
],
가격: ['1만원 미만', '1-3만원', '3-5만원', '5-8만원', '8만원이상'],
특성: ['타고 노는', '만지고 노는', '기타'],
스토어: [
'국민장난감',
'그린키드',
'러브로',
'리틀베이비',
'빌리바바',
'어텐션홈이벤트',
'장난감점빵',
'젤리바운스',
'해피장난감',
],
},
},
});
Expand Down
10 changes: 4 additions & 6 deletions core/axios.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions core/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 17 additions & 13 deletions pages/viewProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,55 @@ 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<typeof getServerSideProps>) {
console.log(filterData, result);
const [priceDesc, setPriceDesc] = useState<boolean>(true);
const [toyList, setToyList] = useState<ToyData[]>([]);
const [currentPage, setCurrentPage] = useState<number>(1);
console.log(data);

const handleClickPrice = (clickPrice: string) => {
clickPrice === 'price-desc' ? setPriceDesc(true) : setPriceDesc(false);
};

const handleCurrentPage = (nextPage: number) => {
setCurrentPage(nextPage);
};

const [selectPrice, setSelectPrice] = useState<boolean[]>([true, false]);
// useSWR로 로딩 판단할 것임
const isLoading = false;
const filterTagList = useRecoilValue<FilterTagProps[]>(filterTagState);

// let { productList, isLoading, isError } = priceDesc
// ? (useGetCollectionProduct('price-desc') as GetCollectionProduct)
// : (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 (
<StViewProductWrapper>
{false ? (
{!filterData ? (
<>
<LandingViewProductBanner />
<StFilterSectionWrapper>
Expand Down Expand Up @@ -113,7 +115,7 @@ export default function viewProduct({
</StFilterSectionWrapper>
<PageNavigation
currentPage={currentPage}
lastPage={Math.ceil(data.length / limit)}
lastPage={Math.ceil(result.length / limit)}
handleCurrentPage={handleCurrentPage}
/>
</>
Expand Down Expand Up @@ -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,
},
};
};
23 changes: 16 additions & 7 deletions types/toy.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit ae6044c

Please sign in to comment.