-
Notifications
You must be signed in to change notification settings - Fork 39
[김진선] refactor/sprint5 #173
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
Merged
addiescode-sj
merged 8 commits into
codeit-bootcamp-frontend:React-김진선
from
jinsunkimdev:refactor/sprint5
Jun 18, 2025
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d10e9c7
chore: move Items-related components and hooks into pages/Items direc…
jinsunkimdev 451d2c1
chore(env): initialize .env file and rename API-related variables
jinsunkimdev 78d55d1
refactor: remove useBestProducts and create useProductsPagination for…
jinsunkimdev f6a7d62
refactor: extract max page button count as a named constant
jinsunkimdev 4719893
style: define z-index variables and apply to SortSelect dropdown
jinsunkimdev 272dc69
refactor: improve useResponsiveLimit with SSR fallback and device-awa…
jinsunkimdev 451995e
chore: remove .env from version control
jinsunkimdev 70602dd
Merge branch 'React-김진선' into refactor/sprint5
jinsunkimdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| # misc | ||
| .DS_Store | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| export const BASE_URL = "https://panda-market-api.vercel.app"; | ||
|
|
||
| export const BASE_API_URL = process.env.REACT_APP_BASE_API_URL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import style from "./Items.module.css" | ||
| import BestProducts from "../components/BestProducts/BestProducts"; | ||
| import AllProducts from "../components/AllProducts/AllProducts"; | ||
| import { BEST_PRODUCTS_PER_DEVICE,ALL_PRODUCTS_PER_DEVICE } from "../constants/products"; | ||
| import { TITLE_ALL_PRODUCTS_COMP,TITLE_BEST_PRODUCTS_COMP } from "../constants/titles"; | ||
| import BestProducts from "./components/BestProducts/BestProducts"; | ||
| import AllProducts from "./components/AllProducts/AllProducts"; | ||
| import { BEST_PRODUCTS_PER_DEVICE,ALL_PRODUCTS_PER_DEVICE } from "../../constants/products"; | ||
| import { TITLE_ALL_PRODUCTS_COMP,TITLE_BEST_PRODUCTS_COMP } from "../../constants/titles"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5,6 번 라인 사이 공백 한칸 띄워줄까요? |
||
| function Items() { | ||
| return ( | ||
| <div className={style.container}> | ||
|
|
||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import styles from "./AllProducts.module.css"; | ||
| import useProductsPagination from "../../hooks/useProductsPagination"; | ||
| import ProductSection from "../ProductSection/ProductSection"; | ||
| import Pagination from "../Pagination/Pagination"; | ||
|
|
||
| function AllProducts({ title, itemsPerDevice }) { | ||
| const { products, totalPages, page, changePage, sort, handleSortChange, } = | ||
| useProductsPagination(itemsPerDevice); | ||
|
|
||
| return ( | ||
| <> | ||
| <ProductSection | ||
| title={title} | ||
| products={products} | ||
| sort={sort} | ||
| showSearch={true} | ||
| showRegisterButton={true} | ||
| onChangeSort={handleSortChange} | ||
| /> | ||
| <div className={styles.paginationWrapper}> | ||
| <Pagination | ||
| currentPage={page} | ||
| totalPages={totalPages} | ||
| onPageChange={changePage} | ||
| /> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default AllProducts; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions
7
src/components/ProductCard/ProductCard.js → ...ems/components/ProductCard/ProductCard.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // ✅ useProductsPagination.js | ||
| import { useState, useEffect, useCallback } from "react"; | ||
| import { fetchPaginatedProducts } from "../../../api/products"; | ||
| import useResponsiveLimit from "./useResponsiveLimit"; | ||
| import usePaginationState from "./usePaginationState"; | ||
|
|
||
| export default function useProductsPagination(itemsPerDevice) { | ||
|
|
||
| const limit = useResponsiveLimit(itemsPerDevice); | ||
| const [page, changePage] = usePaginationState(limit); | ||
| const [sort, setSort] = useState("latest"); | ||
| const [products, setProducts] = useState([]); | ||
| const [totalPages, setTotalPages] = useState(1); | ||
|
|
||
| const handleSortChange = useCallback( | ||
| (newSort) => { | ||
| setSort(newSort); | ||
| changePage(1); | ||
| }, | ||
| [changePage] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const load = async () => { | ||
| const res = await fetchPaginatedProducts({ page, pageSize: limit }); | ||
| let data = res.list || []; | ||
|
|
||
| if (sort === "likes") { | ||
| data.sort((a, b) => b.favoriteCount - a.favoriteCount); | ||
| } else { | ||
| data.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); | ||
| } | ||
|
|
||
| setProducts(data); | ||
| setTotalPages(Math.ceil(res.totalCount / limit)); | ||
| }; | ||
|
|
||
| if (page && limit) load(); | ||
| }, [page, limit, sort]); | ||
|
|
||
| return { | ||
| products, | ||
| totalPages, | ||
| page, | ||
| changePage, | ||
| sort, | ||
| handleSortChange, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { getLimitFromWindowWidth } from "../../../utils/getLimitFromWindowWidth"; | ||
|
|
||
| export default function useResponsiveLimit(itemsPerDevice) { | ||
| const DEFAULT_RESPONSIVE_LIMIT = itemsPerDevice?.tablet || 6; | ||
| // 아주 최소 연산으로만 초기limit값 처리 | ||
| const [limit, setLimit] = useState(() => { | ||
| // 아주 최소 연산만 처리 | ||
| // SSR 대응 | ||
| return typeof window === "undefined" | ||
| ? DEFAULT_RESPONSIVE_LIMIT // 아주 보수적인 default | ||
| : null; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| //window 접근 못 할 경우 return; | ||
| if (typeof window === "undefined") return; | ||
|
|
||
| let timeoutId; | ||
|
|
||
| const update = () => { | ||
| // 디바운싱 추가 | ||
| clearTimeout(timeoutId); | ||
| timeoutId = setTimeout(() => { | ||
| const newLimit = getLimitFromWindowWidth( | ||
| itemsPerDevice.desktop, | ||
| itemsPerDevice.tablet, | ||
| itemsPerDevice.mobile | ||
| ); | ||
| setLimit((prev) => (prev !== newLimit ? newLimit : prev)); | ||
| }, 120); // 리사이즈 멈춘 뒤 120ms 후에만 실행 | ||
| }; | ||
|
|
||
| update(); // mount 시 1회 실행 | ||
| window.addEventListener("resize", update); | ||
|
|
||
| return () => { | ||
| clearTimeout(timeoutId); | ||
| window.removeEventListener("resize", update); | ||
| }; | ||
| }, [itemsPerDevice]); | ||
|
|
||
| return limit; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URLSearchParams 객체 사용해서 여러개의 파라미터를 관리해보는 방법으로 바꾸면, 쿼리 스트링의 파싱, 조작, 인코딩 등의 작업을 간편하게 처리할 수 있으면서도 실수를 줄일 수 있겠죠? :)
아래 아티클 참고해보세요!
참고