From 8abb2bc7baadebddcc0309f0d8069a7b0ab7f071 Mon Sep 17 00:00:00 2001 From: YIMSEBIN <82010185+YIMSEBIN@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:17:30 +0900 Subject: [PATCH 01/15] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index e69de29b..f47cf99c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,15 @@ +# 카카오 테크 캠퍼스 - 프론트엔드 카카오 선물하기 편 Week3 +[🔗 link](https://edu.nextstep.camp/s/hazAC9xa) + +## ✏ 기능 목록 + +### STEP1 +- [ ] 메인페이지 API 연결 + - [ ] Theme 카테고리 섹션 API 연결 : /api/v1/themes API 사용. + - [ ] 실시간 급상승 선물랭킹 섹션 API 연결 : /api/v1/ranking/products API 사용. + - [ ] 필터 조건을 선택하면 해당 조건에 맞게 API를 요청해서 보여지게 함. +- [ ] Theme 페이지 API 연결 + - [ ] Header API 연결 : url의 pathParams와 /api/v1/themes API 사용. + - [ ] themeKey가 잘못된 경우 메인페이지로 연결. + - [ ] 상품목록 섹션 API 연결 : /api/v1/themes/{themeKey}/products API 연결 + - [ ] API 요청 시 한 번에 20개 상품 보여지도록 함. From 435e984624344f57bfa2e9134a8ab28febc12a64 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Tue, 9 Jul 2024 19:24:06 +0900 Subject: [PATCH 02/15] =?UTF-8?q?docs:=20oas.yaml=20ThemeData=EC=97=90=20i?= =?UTF-8?q?mageUrl=20=EC=86=8D=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oas.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oas.yaml b/oas.yaml index e7cfd68e..c49656a2 100644 --- a/oas.yaml +++ b/oas.yaml @@ -506,6 +506,10 @@ components: type: string description: 선물 테마 카테고리 배경색 example: '#F5F5F5' + imageUrl: + type: string + description: 선물 테마 이미지 URL + example: 'https://img1.daumcdn.net/thumb/S104x104/?fname=https%3A%2F%2Ft1.daumcdn.net%2Fgift%2Fhome%2Ftheme%2F292020231106_MXMUB.png' required: - id - key From 9e3febed6bfe4613a434960333becf7c2fa52096 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Tue, 9 Jul 2024 19:38:51 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=97=90=20=ED=85=8C=EB=A7=88=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=EA=B8=B0=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../Home/ThemeCategorySection/index.tsx | 100 +++++------------- 2 files changed, 31 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index f47cf99c..949cabf5 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # 카카오 테크 캠퍼스 - 프론트엔드 카카오 선물하기 편 Week3 + [🔗 link](https://edu.nextstep.camp/s/hazAC9xa) ## ✏ 기능 목록 ### STEP1 + - [ ] 메인페이지 API 연결 - - [ ] Theme 카테고리 섹션 API 연결 : /api/v1/themes API 사용. + - [x] Theme 카테고리 섹션 API 연결 : /api/v1/themes API 사용. - [ ] 실시간 급상승 선물랭킹 섹션 API 연결 : /api/v1/ranking/products API 사용. - [ ] 필터 조건을 선택하면 해당 조건에 맞게 API를 요청해서 보여지게 함. - [ ] Theme 페이지 API 연결 diff --git a/src/components/features/Home/ThemeCategorySection/index.tsx b/src/components/features/Home/ThemeCategorySection/index.tsx index d82e3afe..e9ada01d 100644 --- a/src/components/features/Home/ThemeCategorySection/index.tsx +++ b/src/components/features/Home/ThemeCategorySection/index.tsx @@ -1,4 +1,6 @@ import styled from '@emotion/styled'; +import axios from 'axios'; +import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { Container } from '@/components/common/layouts/Container'; @@ -8,7 +10,27 @@ import { breakpoints } from '@/styles/variants'; import { ThemeCategoryItem } from './ThemeCategoryItem'; +type ThemeProps = { + id: number; + key: string; + label: string; + title: string; + description: string; + backgroundColor: string; + imageURL: string; +}; + export const ThemeCategorySection = () => { + const [themes, setThemes] = useState(); + const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; + + useEffect(() => { + axios.get(url).then((response) => { + setThemes(response.data.themes); + console.log(response.data.themes); + }); + }, []); + return ( @@ -18,78 +40,12 @@ export const ThemeCategorySection = () => { md: 6, }} > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {themes && + themes.map((theme) => ( + + + + ))} From 533d88931b431f9f8f4ccb930b2fd03f27e99d90 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Tue, 9 Jul 2024 19:39:03 +0900 Subject: [PATCH 04/15] =?UTF-8?q?chore:=20axios=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 29 ++++++++++++++++------------- package.json | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 89581c64..74216d7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", + "axios": "^1.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.22.1" @@ -11988,8 +11989,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/at-least-node": { "version": "1.0.0", @@ -12061,6 +12061,16 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -13498,7 +13508,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -15481,7 +15490,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -18405,10 +18413,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", - "dev": true, + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -18614,7 +18621,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -24744,7 +24750,6 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -24753,7 +24758,6 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -27576,8 +27580,7 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/psl": { "version": "1.9.0", diff --git a/package.json b/package.json index 0a6f0b8f..f1f65cfa 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "dependencies": { "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", + "axios": "^1.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.22.1" From 9fe5222a11c5f61c08b72e31c1e74645aefdf8e2 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 13:49:13 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=8B=A4=EC=8B=9C=EA=B0=84=20=EA=B8=89?= =?UTF-8?q?=EC=83=81=EC=8A=B9=20=EC=84=A0=EB=AC=BC=EB=9E=AD=ED=82=B9=20API?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++--- .../Home/GoodsRankingSection/index.tsx | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 949cabf5..e97f9d15 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ ### STEP1 -- [ ] 메인페이지 API 연결 +- [x] 메인페이지 API 연결 - [x] Theme 카테고리 섹션 API 연결 : /api/v1/themes API 사용. - - [ ] 실시간 급상승 선물랭킹 섹션 API 연결 : /api/v1/ranking/products API 사용. - - [ ] 필터 조건을 선택하면 해당 조건에 맞게 API를 요청해서 보여지게 함. + - [x] 실시간 급상승 선물랭킹 섹션 API 연결 : /api/v1/ranking/products API 사용. + - [x] 필터 조건을 선택하면 해당 조건에 맞게 API를 요청해서 보여지게 함. - [ ] Theme 페이지 API 연결 - [ ] Header API 연결 : url의 pathParams와 /api/v1/themes API 사용. - [ ] themeKey가 잘못된 경우 메인페이지로 연결. diff --git a/src/components/features/Home/GoodsRankingSection/index.tsx b/src/components/features/Home/GoodsRankingSection/index.tsx index 9464d67c..85bd7959 100644 --- a/src/components/features/Home/GoodsRankingSection/index.tsx +++ b/src/components/features/Home/GoodsRankingSection/index.tsx @@ -1,10 +1,10 @@ import styled from '@emotion/styled'; -import { useState } from 'react'; +import axios from 'axios'; +import { useEffect, useState } from 'react'; import { Container } from '@/components/common/layouts/Container'; import { breakpoints } from '@/styles/variants'; -import type { RankingFilterOption } from '@/types'; -import { GoodsMockList } from '@/types/mock'; +import { type GoodsData, type RankingFilterOption } from '@/types'; import { GoodsRankingFilter } from './Filter'; import { GoodsRankingList } from './List'; @@ -14,15 +14,25 @@ export const GoodsRankingSection = () => { targetType: 'ALL', rankType: 'MANY_WISH', }); - - // GoodsMockData를 21번 반복 생성 + const [goods, setGoods] = useState([]); + + const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/ranking/products'; + useEffect(() => { + axios({ + method: 'get', + url: url, + params: filterOption, + }).then((res) => { + setGoods(res.data.products); + }); + }, [filterOption]); return ( 실시간 급상승 선물랭킹 - + ); From 839a74d6adda536070baa98a28754ed2c4afd81b Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 15:39:50 +0900 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20Theme=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20API=20=EB=B0=9B=EC=95=84=EC=98=A4=EA=B8=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/ThemeCategorySection/index.tsx | 22 +++++----------- src/pages/Theme/index.tsx | 26 ++++++++++++++++--- src/types/index.ts | 1 + src/types/mock.ts | 2 ++ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/components/features/Home/ThemeCategorySection/index.tsx b/src/components/features/Home/ThemeCategorySection/index.tsx index e9ada01d..035f00ec 100644 --- a/src/components/features/Home/ThemeCategorySection/index.tsx +++ b/src/components/features/Home/ThemeCategorySection/index.tsx @@ -7,30 +7,20 @@ import { Container } from '@/components/common/layouts/Container'; import { Grid } from '@/components/common/layouts/Grid'; import { getDynamicPath } from '@/routes/path'; import { breakpoints } from '@/styles/variants'; +import { type ThemeData } from '@/types'; import { ThemeCategoryItem } from './ThemeCategoryItem'; -type ThemeProps = { - id: number; - key: string; - label: string; - title: string; - description: string; - backgroundColor: string; - imageURL: string; -}; - export const ThemeCategorySection = () => { - const [themes, setThemes] = useState(); - const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; + const [themes, setThemes] = useState(); + const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; useEffect(() => { - axios.get(url).then((response) => { - setThemes(response.data.themes); - console.log(response.data.themes); + axios.get(url).then((res) => { + setThemes(res.data.themes); }); }, []); - + // console.log(themes); return ( diff --git a/src/pages/Theme/index.tsx b/src/pages/Theme/index.tsx index 4d02e6c1..3c7882ea 100644 --- a/src/pages/Theme/index.tsx +++ b/src/pages/Theme/index.tsx @@ -1,18 +1,38 @@ +import axios from 'axios'; +import { useEffect, useState } from 'react'; import { Navigate, useParams } from 'react-router-dom'; import { ThemeGoodsSection } from '@/components/features/Theme/ThemeGoodsSection'; import { getCurrentTheme, ThemeHeroSection } from '@/components/features/Theme/ThemeHeroSection'; import { RouterPath } from '@/routes/path'; -import { ThemeMockList } from '@/types/mock'; +import { type ThemeData } from '@/types'; export const ThemePage = () => { const { themeKey = '' } = useParams<{ themeKey: string }>(); - const currentTheme = getCurrentTheme(themeKey, ThemeMockList); + const [themes, setThemes] = useState([]); + const [currentTheme, setCurrentTheme] = useState(); + + const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; + useEffect(() => { + axios.get(url).then((res) => { + setThemes(res.data.themes); + // console.log(res.data.themes); // API로부터 받은 실제 데이터 출력 + }); + }, []); // 의존성 배열을 빈 배열로 설정하여 마운트 시에만 실행되도록 함 + console.log(themes); // 첫 렌더링에서는 빈 배열, 업데이트 후에는 API 데이터를 출력 + + // 아래 방식으로 themes를 확인해봐도 빈 배열이 뜬다.. + useEffect(() => { + console.log(themes); + }, [themes]); + + useEffect(() => { + setCurrentTheme(getCurrentTheme(themeKey, themes)); + }, [themeKey, themes]); if (!currentTheme) { return ; } - return ( <> diff --git a/src/types/index.ts b/src/types/index.ts index 9d76b97b..fcf55803 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -5,6 +5,7 @@ export type ThemeData = { title: string; description?: string; backgroundColor: string; + imageURL: string; }; export type RankingFilterOption = { diff --git a/src/types/mock.ts b/src/types/mock.ts index cdd90cf7..d54d6016 100644 --- a/src/types/mock.ts +++ b/src/types/mock.ts @@ -7,6 +7,8 @@ export const ThemeMockData: ThemeData = { title: '예산은 가볍게, 감동은 무겁게❤️', description: '당신의 센스를 뽐내줄 부담 없는 선물', backgroundColor: '#4b4d50', + imageURL: + 'https://st.kakaocdn.net/product/gift/product/20231030175450_53e90ee9708f45ffa45b3f7b4bc01c7c.jpg', }; export const ThemeMockList = [ThemeMockData]; From ac769ab897f6c31369e09f0e369f413ae48f4b4b Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 16:50:58 +0900 Subject: [PATCH 07/15] =?UTF-8?q?feat:=20theme=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20API?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Theme/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pages/Theme/index.tsx b/src/pages/Theme/index.tsx index 3c7882ea..18a67496 100644 --- a/src/pages/Theme/index.tsx +++ b/src/pages/Theme/index.tsx @@ -1,6 +1,6 @@ import axios from 'axios'; import { useEffect, useState } from 'react'; -import { Navigate, useParams } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { ThemeGoodsSection } from '@/components/features/Theme/ThemeGoodsSection'; import { getCurrentTheme, ThemeHeroSection } from '@/components/features/Theme/ThemeHeroSection'; @@ -11,6 +11,7 @@ export const ThemePage = () => { const { themeKey = '' } = useParams<{ themeKey: string }>(); const [themes, setThemes] = useState([]); const [currentTheme, setCurrentTheme] = useState(); + const [loading, setLoading] = useState(true); const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; useEffect(() => { @@ -19,19 +20,19 @@ export const ThemePage = () => { // console.log(res.data.themes); // API로부터 받은 실제 데이터 출력 }); }, []); // 의존성 배열을 빈 배열로 설정하여 마운트 시에만 실행되도록 함 - console.log(themes); // 첫 렌더링에서는 빈 배열, 업데이트 후에는 API 데이터를 출력 - - // 아래 방식으로 themes를 확인해봐도 빈 배열이 뜬다.. - useEffect(() => { - console.log(themes); - }, [themes]); + // console.log(themes); // 첫 렌더링에서는 빈 배열, 업데이트 후에는 API 데이터를 출력 useEffect(() => { setCurrentTheme(getCurrentTheme(themeKey, themes)); }, [themeKey, themes]); - if (!currentTheme) { - return ; + useEffect(() => { + console.log(currentTheme); + setLoading(false); + }, [currentTheme]); + + if (!loading) { + if (!currentTheme) return ; } return ( <> From f016c05d0fb0378040288b2397c3b31ff21a3800 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 17:14:42 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20Theme=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=ED=97=A4=EB=8D=94=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/Theme/ThemeHeroSection/index.tsx | 55 +++++++++++++------ src/pages/Theme/index.tsx | 33 +---------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/components/features/Theme/ThemeHeroSection/index.tsx b/src/components/features/Theme/ThemeHeroSection/index.tsx index 36cfc038..06794d99 100644 --- a/src/components/features/Theme/ThemeHeroSection/index.tsx +++ b/src/components/features/Theme/ThemeHeroSection/index.tsx @@ -1,32 +1,55 @@ import styled from '@emotion/styled'; +import axios from 'axios'; +import { useEffect, useState } from 'react'; +import { Link } from 'react-router-dom'; import { Container } from '@/components/common/layouts/Container'; +import { RouterPath } from '@/routes/path'; import { breakpoints } from '@/styles/variants'; import type { ThemeData } from '@/types'; -import { ThemeMockList } from '@/types/mock'; type Props = { themeKey: string; }; export const ThemeHeroSection = ({ themeKey }: Props) => { - const currentTheme = getCurrentTheme(themeKey, ThemeMockList); + const [themes, setThemes] = useState([]); + const [currentTheme, setCurrentTheme] = useState(); + const [loading, setLoading] = useState(true); - if (!currentTheme) { - return null; - } + const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; + useEffect(() => { + axios.get(url).then((res) => { + setThemes(res.data.themes); + }); + }, []); + + useEffect(() => { + setCurrentTheme(getCurrentTheme(themeKey, themes)); + }, [themeKey, themes]); + + useEffect(() => { + setLoading(false); + }, [currentTheme]); - const { backgroundColor, label, title, description } = currentTheme; - - return ( - - - - {title} - {description && {description}} - - - ); + if (!loading) { + if (!currentTheme) return ; + else { + const { backgroundColor, label, title, description } = currentTheme; + + return ( + + + + {title} + {description && {description}} + + + ); + } + } else { + return
Loading..
; + } }; const Wrapper = styled.section<{ backgroundColor: string }>` diff --git a/src/pages/Theme/index.tsx b/src/pages/Theme/index.tsx index 18a67496..d3bc091b 100644 --- a/src/pages/Theme/index.tsx +++ b/src/pages/Theme/index.tsx @@ -1,39 +1,10 @@ -import axios from 'axios'; -import { useEffect, useState } from 'react'; -import { Link, useParams } from 'react-router-dom'; +import { useParams } from 'react-router-dom'; import { ThemeGoodsSection } from '@/components/features/Theme/ThemeGoodsSection'; -import { getCurrentTheme, ThemeHeroSection } from '@/components/features/Theme/ThemeHeroSection'; -import { RouterPath } from '@/routes/path'; -import { type ThemeData } from '@/types'; +import { ThemeHeroSection } from '@/components/features/Theme/ThemeHeroSection'; export const ThemePage = () => { const { themeKey = '' } = useParams<{ themeKey: string }>(); - const [themes, setThemes] = useState([]); - const [currentTheme, setCurrentTheme] = useState(); - const [loading, setLoading] = useState(true); - - const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; - useEffect(() => { - axios.get(url).then((res) => { - setThemes(res.data.themes); - // console.log(res.data.themes); // API로부터 받은 실제 데이터 출력 - }); - }, []); // 의존성 배열을 빈 배열로 설정하여 마운트 시에만 실행되도록 함 - // console.log(themes); // 첫 렌더링에서는 빈 배열, 업데이트 후에는 API 데이터를 출력 - - useEffect(() => { - setCurrentTheme(getCurrentTheme(themeKey, themes)); - }, [themeKey, themes]); - - useEffect(() => { - console.log(currentTheme); - setLoading(false); - }, [currentTheme]); - - if (!loading) { - if (!currentTheme) return ; - } return ( <> From f9fd1700544019099876067f3b3cc63968fe4f59 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 17:20:29 +0900 Subject: [PATCH 09/15] =?UTF-8?q?feat:=20Theme=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=83=81=ED=92=88=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/Theme/ThemeGoodsSection/index.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/features/Theme/ThemeGoodsSection/index.tsx b/src/components/features/Theme/ThemeGoodsSection/index.tsx index 8edbf70e..7db2cab6 100644 --- a/src/components/features/Theme/ThemeGoodsSection/index.tsx +++ b/src/components/features/Theme/ThemeGoodsSection/index.tsx @@ -1,16 +1,27 @@ import styled from '@emotion/styled'; +import axios from 'axios'; +import { useEffect, useState } from 'react'; import { DefaultGoodsItems } from '@/components/common/GoodsItem/Default'; import { Container } from '@/components/common/layouts/Container'; import { Grid } from '@/components/common/layouts/Grid'; import { breakpoints } from '@/styles/variants'; -import { GoodsMockList } from '@/types/mock'; +import { GoodsData } from '@/types'; type Props = { themeKey: string; }; -export const ThemeGoodsSection = ({}: Props) => { +export const ThemeGoodsSection = ({ themeKey }: Props) => { + const [products, setProducts] = useState([]); + + const url = `https://react-gift-mock-api-two.vercel.app/api/v1/themes/${themeKey}/products`; + useEffect(() => { + axios.get(url).then((res) => { + setProducts(res.data.products); + }); + }, [url]); + return ( @@ -21,7 +32,7 @@ export const ThemeGoodsSection = ({}: Props) => { }} gap={16} > - {GoodsMockList.map(({ id, imageURL, name, price, brandInfo }) => ( + {products.map(({ id, imageURL, name, price, brandInfo }) => ( Date: Wed, 10 Jul 2024 17:29:07 +0900 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20Theme=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20API=EC=9A=94=EC=B2=AD=20=EC=8B=9C=20=ED=95=9C=EB=B2=88?= =?UTF-8?q?=EC=97=90=20=EC=83=81=ED=92=88=2020=EA=B0=9C=20=EC=A0=9C?= =?UTF-8?q?=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/features/Theme/ThemeGoodsSection/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/features/Theme/ThemeGoodsSection/index.tsx b/src/components/features/Theme/ThemeGoodsSection/index.tsx index 7db2cab6..cd5841aa 100644 --- a/src/components/features/Theme/ThemeGoodsSection/index.tsx +++ b/src/components/features/Theme/ThemeGoodsSection/index.tsx @@ -6,7 +6,7 @@ import { DefaultGoodsItems } from '@/components/common/GoodsItem/Default'; import { Container } from '@/components/common/layouts/Container'; import { Grid } from '@/components/common/layouts/Grid'; import { breakpoints } from '@/styles/variants'; -import { GoodsData } from '@/types'; +import type { GoodsData } from '@/types'; type Props = { themeKey: string; @@ -18,7 +18,7 @@ export const ThemeGoodsSection = ({ themeKey }: Props) => { const url = `https://react-gift-mock-api-two.vercel.app/api/v1/themes/${themeKey}/products`; useEffect(() => { axios.get(url).then((res) => { - setProducts(res.data.products); + setProducts(res.data.products.slice(0, 20)); }); }, [url]); From 8134c77d4d85c575d24923916cd96acb9d85d4bf Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 17:56:19 +0900 Subject: [PATCH 11/15] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20theme=20=EC=84=B9=EC=85=98=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/ThemeCategorySection/index.tsx | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/components/features/Home/ThemeCategorySection/index.tsx b/src/components/features/Home/ThemeCategorySection/index.tsx index 035f00ec..55177258 100644 --- a/src/components/features/Home/ThemeCategorySection/index.tsx +++ b/src/components/features/Home/ThemeCategorySection/index.tsx @@ -12,15 +12,46 @@ import { type ThemeData } from '@/types'; import { ThemeCategoryItem } from './ThemeCategoryItem'; export const ThemeCategorySection = () => { - const [themes, setThemes] = useState(); + const [themes, setThemes] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(); const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; useEffect(() => { - axios.get(url).then((res) => { - setThemes(res.data.themes); - }); + axios + .get(url) + .then((res) => { + setThemes(res.data.themes); + setError(null); + }) + .catch((err) => { + console.error('Error fetching themes:', err); + setError(err); // 에러 메시지 설정 + }) + .finally(() => { + setLoading(false); // 로딩 상태 해제 + }); }, []); - // console.log(themes); + + if (loading) + return ( + +
데이터를 로딩중입니다.
+
+ ); + if (error) + return ( + +
Error: {error}
+
+ ); + if (themes.length === 0) + return ( + +
데이터가 존재하지 않습니다.
+
+ ); + return ( From d75d7691b75338951b41c4a3c9ac3f256b605ac9 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 17:58:18 +0900 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=8B=A4=EC=8B=9C=EA=B0=84=EA=B8=89?= =?UTF-8?q?=EC=83=81=EC=8A=B9=20=EC=84=B9=EC=85=98=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/GoodsRankingSection/index.tsx | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/components/features/Home/GoodsRankingSection/index.tsx b/src/components/features/Home/GoodsRankingSection/index.tsx index 85bd7959..f2a365b1 100644 --- a/src/components/features/Home/GoodsRankingSection/index.tsx +++ b/src/components/features/Home/GoodsRankingSection/index.tsx @@ -15,6 +15,8 @@ export const GoodsRankingSection = () => { rankType: 'MANY_WISH', }); const [goods, setGoods] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(); const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/ranking/products'; useEffect(() => { @@ -22,11 +24,38 @@ export const GoodsRankingSection = () => { method: 'get', url: url, params: filterOption, - }).then((res) => { - setGoods(res.data.products); - }); + }) + .then((res) => { + setGoods(res.data.products); + }) + .catch((err) => { + console.error('Error fetching themes:', err); + setError(err); // 에러 메시지 설정 + }) + .finally(() => { + setLoading(false); // 로딩 상태 해제 + }); }, [filterOption]); + if (loading) + return ( + +
데이터를 로딩중입니다.
+
+ ); + if (error) + return ( + +
Error: {error}
+
+ ); + if (goods.length === 0) + return ( + +
데이터가 존재하지 않습니다.
+
+ ); + return ( From 2e0f982caa62e7d75bdc4c293a57440a9d03db74 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 17:59:12 +0900 Subject: [PATCH 13/15] =?UTF-8?q?docs:=20README.md=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e97f9d15..123d36e3 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,15 @@ - [x] Theme 카테고리 섹션 API 연결 : /api/v1/themes API 사용. - [x] 실시간 급상승 선물랭킹 섹션 API 연결 : /api/v1/ranking/products API 사용. - [x] 필터 조건을 선택하면 해당 조건에 맞게 API를 요청해서 보여지게 함. -- [ ] Theme 페이지 API 연결 - - [ ] Header API 연결 : url의 pathParams와 /api/v1/themes API 사용. - - [ ] themeKey가 잘못된 경우 메인페이지로 연결. - - [ ] 상품목록 섹션 API 연결 : /api/v1/themes/{themeKey}/products API 연결 - - [ ] API 요청 시 한 번에 20개 상품 보여지도록 함. +- [x] Theme 페이지 API 연결 + - [x] Header API 연결 : url의 pathParams와 /api/v1/themes API 사용. + - [x] themeKey가 잘못된 경우 메인페이지로 연결. + - [x] 상품목록 섹션 API 연결 : /api/v1/themes/{themeKey}/products API 연결 + - [x] API 요청 시 한 번에 20개 상품 보여지도록 함. + +### STEP2 + +- [x] 메인페이지 ThemeCategorySection 에러처리 +- [x] 메인페이지 실시간 급상승 Section 에러처리 +- [ ] Theme페이지 헤더부분 에러처리 +- [ ] Tehme페이지 상품부분 에러처리 From d162617a511aac769e75da50e8d12206abb6ff72 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 18:01:47 +0900 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20Theme=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=ED=97=A4=EB=8D=94=20=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/Theme/ThemeHeroSection/index.tsx | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/components/features/Theme/ThemeHeroSection/index.tsx b/src/components/features/Theme/ThemeHeroSection/index.tsx index 06794d99..196837e1 100644 --- a/src/components/features/Theme/ThemeHeroSection/index.tsx +++ b/src/components/features/Theme/ThemeHeroSection/index.tsx @@ -16,12 +16,19 @@ export const ThemeHeroSection = ({ themeKey }: Props) => { const [themes, setThemes] = useState([]); const [currentTheme, setCurrentTheme] = useState(); const [loading, setLoading] = useState(true); + const [error, setError] = useState(); const url = 'https://react-gift-mock-api-two.vercel.app/api/v1/themes'; useEffect(() => { - axios.get(url).then((res) => { - setThemes(res.data.themes); - }); + axios + .get(url) + .then((res) => { + setThemes(res.data.themes); + }) + .catch((err) => { + console.error('Error fetching themes:', err); + setError(err); // 에러 메시지 설정 + }); }, []); useEffect(() => { @@ -31,24 +38,31 @@ export const ThemeHeroSection = ({ themeKey }: Props) => { useEffect(() => { setLoading(false); }, [currentTheme]); - - if (!loading) { - if (!currentTheme) return ; - else { - const { backgroundColor, label, title, description } = currentTheme; - - return ( - - - - {title} - {description && {description}} - - - ); - } - } else { - return
Loading..
; + if (loading) + return ( + +
데이터를 로딩중입니다.
+
+ ); + if (error) + return ( + +
Error: {error}
+
+ ); + if (!currentTheme) return ; + else { + const { backgroundColor, label, title, description } = currentTheme; + + return ( + + + + {title} + {description && {description}} + + + ); } }; From daf0c7ce6e7b48de92afb395735d4228595b4b92 Mon Sep 17 00:00:00 2001 From: YIMSEBIN Date: Wed, 10 Jul 2024 18:02:43 +0900 Subject: [PATCH 15/15] =?UTF-8?q?feat:=20Theme=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EC=83=81=ED=92=88=EB=AA=A9=EB=A1=9D=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Theme/ThemeGoodsSection/index.tsx | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/features/Theme/ThemeGoodsSection/index.tsx b/src/components/features/Theme/ThemeGoodsSection/index.tsx index cd5841aa..a55cd603 100644 --- a/src/components/features/Theme/ThemeGoodsSection/index.tsx +++ b/src/components/features/Theme/ThemeGoodsSection/index.tsx @@ -14,14 +14,44 @@ type Props = { export const ThemeGoodsSection = ({ themeKey }: Props) => { const [products, setProducts] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(); const url = `https://react-gift-mock-api-two.vercel.app/api/v1/themes/${themeKey}/products`; useEffect(() => { - axios.get(url).then((res) => { - setProducts(res.data.products.slice(0, 20)); - }); + axios + .get(url) + .then((res) => { + setProducts(res.data.products.slice(0, 20)); + }) + .catch((err) => { + console.error('Error fetching themes:', err); + setError(err); // 에러 메시지 설정 + }) + .finally(() => { + setLoading(false); // 로딩 상태 해제 + }); }, [url]); + if (loading) + return ( + +
데이터를 로딩중입니다.
+
+ ); + if (error) + return ( + +
Error: {error}
+
+ ); + if (products.length === 0) + return ( + +
데이터가 존재하지 않습니다.
+
+ ); + return (