Skip to content
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
11,006 changes: 6,236 additions & 4,770 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.4",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"typescript": "^4.9.5"
}
}
19 changes: 0 additions & 19 deletions src/App.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";
import { Outlet } from "react-router-dom";

const App: React.FC = () => {
return <Outlet />;
};

export default App;
82 changes: 0 additions & 82 deletions src/api/product.js

This file was deleted.

71 changes: 0 additions & 71 deletions src/components/section/AllProductsSection.js

This file was deleted.

64 changes: 64 additions & 0 deletions src/components/section/AllProductsSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { fetchProducts } from "../../domains/product/index";
import { useCallback, useEffect, useState } from "react";
import { HttpException } from "../../utils/exceptions";
import ItemCard from "../ui/Item/ItemCard";
import "./AllProductsSection.css";
import { SortOption, Product } from "../../domains/product/index";
import { getPageLimit } from "../../utils/getPageLimit";
import { debounce } from "../../utils/debounce";

interface AllProductsSectionProps {
sortOption: SortOption;
}

function AllProductsSection({ sortOption }: AllProductsSectionProps) {
const [items, setItems] = useState<Product[]>([]);
const [pageSize, setPageSize] = useState(getPageLimit(window.innerWidth, "all"));
const [error, setError] = useState<string | null>(null);

const getProducts = async (limit: number, sort: SortOption): Promise<void> => {
try {
const { list } = await fetchProducts(sort, limit);
setItems(list);
} catch (error) {
console.error(error);
const message = error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다";
setError(message);
}
};
Comment on lines +19 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이정도로 예외처리 해도 충분하긴 해요!

아마 느끼셨겠지만 이런 부분들이 매우 많이 사용될꺼에요.
그래서 이걸 추상화하고 공통으로 묶어서 사용하려고 사람들이 많이 시도해왔는데, react-query라는 라이브러리를 한번 사용해보시면 좋을것같아요ㅎㅎ!

이거 같이 멘토링에서 해보시져...!


const handleResize = useCallback(() => {
const newPageSize = getPageLimit(window.innerWidth, "all");
if (newPageSize !== pageSize) {
setPageSize(newPageSize);
}
}, [pageSize]);

useEffect(() => {
const debounceResize = debounce(handleResize, 300);
window.addEventListener("resize", debounceResize);
return () => window.removeEventListener("resize", debounceResize);
}, [handleResize]);
Comment on lines +37 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resize 될때 처리한 부분도 나쁘지 않게 잘 된것같아요ㅎㅎ!
이부분떄문에 서버에 성능부하를 주진 않을꺼에요~

왜냐하면 값이 바뀌었을때만 요청이 날아갈꺼거든요!


useEffect(() => {
if (pageSize !== null) {
getProducts(pageSize, sortOption);
}
}, [sortOption, pageSize]);

if (error) {
return <div>오류: {error}</div>;
}

return (
<section className="all-products">
<div className="all-products-list">
{items.map((item) => (
<ItemCard key={item.id} item={item} />
))}
</div>
</section>
Comment on lines +54 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔하게 잘 구현하셨네요ㅋㅋ

);
}

export default AllProductsSection;
75 changes: 0 additions & 75 deletions src/components/section/BestProductsSection.js

This file was deleted.

Loading
Loading