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
17 changes: 17 additions & 0 deletions public/panda-empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Routes, Route, Navigate } from "react-router-dom";
import Header from "./components/Header/Header.jsx";
import Items from "./pages/Items/Items.jsx";
import AddItem from "./pages/AddItem/AddItem.jsx";
import ProductDetail from "./pages/ProductDetail/ProductDetail.jsx";
import "./assets/styles/base.css";

function App() {
Expand All @@ -12,6 +13,7 @@ function App() {
<Route path="/" element={<Navigate to="/" replace />} />
<Route path="/items" element={<Items />} />
<Route path="/additem" element={<AddItem />} />
<Route path="/items/:productId" element={<ProductDetail />} />
</Routes>
</>
);
Expand Down
24 changes: 24 additions & 0 deletions src/api/getProductComments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const getProductComments = async (productId, limit = 10, cursor = null) => {
try {
const params = new URLSearchParams();
params.append("limit", limit);
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

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

💊 제안
URLSearchParams 함수를 사용하신 것 좋아요! 아래처럼 초기값으로 limit를 넘겨주셔도 됩니다.

Suggested change
const params = new URLSearchParams();
params.append("limit", limit);
const params = new URLSearchParams({ limit });

if (cursor !== null) {
params.append("cursor", cursor);
}

const res = await fetch(
`https://panda-market-api.vercel.app/products/${productId}/comments?${params.toString()}`
);

if (!res.ok) {
throw new Error("댓글 정보를 불러오지 못했습니다.");
}

return await res.json();
} catch (error) {
console.error(error);
throw error;
}
};

export default getProductComments;
18 changes: 18 additions & 0 deletions src/api/getProductDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const getProductDetail = async (productId) => {
try {
const res = await fetch(
`https://panda-market-api.vercel.app/products/${productId}`
);

if (!res.ok) {
throw new Error("상품 상세 정보를 불러오지 못했습니다.");
}

return await res.json();
} catch (error) {
console.error(error);
throw error;
}
};

export default getProductDetail;
Binary file added src/assets/icon/back-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icon/kebab-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/AllProducts/AllProducts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const AllProducts = () => {
{products.map(({ id, images, name, price, favoriteCount }) => (
<ProductCard
key={id}
id={id}
imageUrl={images?.[0]}
title={name}
price={price}
Expand Down
1 change: 1 addition & 0 deletions src/components/BestProducts/BestProducts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const BestProducts = () => {
{products.slice(0, visibleCount).map((item) => (
<ProductCard
key={item.id}
id={item.id}
imageUrl={item.images?.[0]}
title={item.name}
price={item.price}
Expand Down
39 changes: 21 additions & 18 deletions src/components/ProductCard/ProductCard.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { Link } from "react-router-dom";
import styles from "./ProductCard.module.css";
import heartIcon from "../../assets/icon/heart-icon.svg";

const ProductCard = ({ imageUrl, title, price, likes, variant }) => {
const ProductCard = ({ id, imageUrl, title, price, likes, variant }) => {
return (
<div className={styles.card}>
<img
src={imageUrl || "/no-img.svg"}
alt={title}
className={variant === "best" ? styles.bestImg : styles.allImg}
onError={(e) => {
e.currentTarget.src = "/no-img.svg";
}}
/>
<div className={styles.info}>
<p className={styles.title}>{title}</p>
<p className={styles.price}>{price.toLocaleString()}원</p>
<p className={styles.likes}>
<img src={heartIcon} alt="좋아요" className={styles.icon} />
<span className={styles.count}>{likes}</span>
</p>
<Link to={`/items/${id}`} className={styles.cardLink}>
<div className={styles.card}>
<img
src={imageUrl || "/no-img.svg"}
alt={title}
className={variant === "best" ? styles.bestImg : styles.allImg}
onError={(e) => {
e.currentTarget.src = "/no-img.svg";
}}
/>
<div className={styles.info}>
<p className={styles.title}>{title}</p>
<p className={styles.price}>{price.toLocaleString()}원</p>
<p className={styles.likes}>
<img src={heartIcon} alt="좋아요" className={styles.icon} />
<span className={styles.count}>{likes}</span>
</p>
</div>
</div>
</div>
</Link>
);
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/ProductCard/ProductCard.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.cardLink {
text-decoration: none;
}

.card {
display: flex;
flex-direction: column;
Expand Down
Loading
Loading