-
Notifications
You must be signed in to change notification settings - Fork 35
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
[염정훈] Sprint7 #219
The head ref may contain hidden characters: "React-\uC5FC\uC815\uD6C8-sprint7"
[염정훈] Sprint7 #219
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
export async function getProducts({ page, pageSize, order }) { | ||
const apiUrl = process.env.REACT_APP_API_URL; | ||
// 상품 API | ||
export async function getProducts({ | ||
page = 1, | ||
pageSize = 20, | ||
order = "recent", | ||
}) { | ||
const apiUrl = process.env.REACT_APP_BASE_URL; | ||
const query = `page=${page}&pageSize=${pageSize}&orderBy=${order}`; | ||
const response = await fetch(`${apiUrl}.vercel.app/products?${query}`); | ||
const body = await response.json(); | ||
return body; | ||
} | ||
|
||
// 댓글 API | ||
export async function getComments({ productId, limit = 3 }) { | ||
const apiUrl = process.env.REACT_APP_BASE_URL; | ||
const query = `${productId}/comments?limit=${limit}`; | ||
const response = await fetch(`${apiUrl}.vercel.app/products/${query}`); | ||
const body = await response.json(); | ||
return body; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,25 +36,29 @@ function AddItem() { | |
setInputFileUrl(null); | ||
}; | ||
|
||
const validAddItem = () => { | ||
const validAddItemVal = () => { | ||
// 유효성 검사 | ||
if ( | ||
formData.name !== "" && | ||
formData.info !== "" && | ||
formData.price !== "" && | ||
formData.tag !== "" | ||
formData.name.trim() !== "" && | ||
formData.info.trim() !== "" && | ||
formData.price.trim() !== "" && | ||
formData.tag.trim() !== "" | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
Comment on lines
+39
to
+51
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. 이런 로직은
이런식으로도 작성 가능합니다! |
||
|
||
useEffect(() => { | ||
// input 데이터 변경 될때마다 유효성 검사 실행 | ||
if (validAddItemVal()) { | ||
setAddItemBtn("on"); | ||
setBtnDisabled(false); | ||
} else { | ||
setAddItemBtn(""); | ||
setBtnDisabled(true); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
// input 데이터 변경 될때마다 유효성 검사 실행 | ||
validAddItem(); | ||
}, [formData]); | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,14 @@ const responsivePageSize = () => { | |
} | ||
}; | ||
|
||
const recent = "recent"; | ||
const favorite = "favorite"; | ||
const RECENT = "recent"; | ||
const FAVORITE = "favorite"; | ||
Comment on lines
+19
to
+20
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. 변수명을 수정해서 상수로 확실하게 표현해주신점 좋네요! |
||
|
||
function AllProduct() { | ||
const [products, setProducts] = useState([]); | ||
const [page, setPage] = useState(1); | ||
const [pageSize, setPageSize] = useState(10); | ||
const [order, setOrder] = useState(recent); | ||
const [order, setOrder] = useState(RECENT); | ||
const [dropArrow, setDropArrow] = useState(""); | ||
const [dropDisplay, setDropDisplay] = useState("none"); | ||
const [orderTxt, setOrderTxt] = useState("최신순"); | ||
|
@@ -44,15 +44,15 @@ function AllProduct() { | |
setOrderTxt(menuTxt); | ||
setDropArrow(""); | ||
setDropDisplay("none"); | ||
setOrder(recent); | ||
setOrder(RECENT); | ||
}; | ||
|
||
const handleBestOrder = (e) => { | ||
const menuTxt = e.target.textContent; | ||
setOrderTxt(menuTxt); | ||
setDropArrow(""); | ||
setDropDisplay("none"); | ||
setOrder(favorite); | ||
setOrder(FAVORITE); | ||
}; | ||
|
||
const pageNumClick = (page) => { | ||
|
@@ -116,22 +116,26 @@ function AllProduct() { | |
|
||
return ( | ||
<li key={product.id}> | ||
<div className="product-img"> | ||
<img | ||
src={imgChk ? product.images : "/images/card01-small.png"} // 이미지 경로에 jpeg가 없으면 기본 이미지 있으면 정상적인 이미지 | ||
alt={product.name} | ||
/> | ||
</div> | ||
<div> | ||
<p className="product-name">{product.name}</p> | ||
<p className="product-price">{productPrice}원</p> | ||
<div className="product-favoriteCount"> | ||
<button type="button"> | ||
<img src="/images/i-like.png" alt="하트 아이콘" /> | ||
</button> | ||
<span>{product.favoriteCount}</span> | ||
<Link to={`/Items/${product.id}`}> | ||
<div className="product-img"> | ||
<img | ||
src={ | ||
imgChk ? product.images : "/images/card01-small.png" | ||
} // 이미지 경로에 jpeg가 없으면 기본 이미지 있으면 정상적인 이미지 | ||
alt={product.name} | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<p className="product-name">{product.name}</p> | ||
<p className="product-price">{productPrice}원</p> | ||
<div className="product-favoriteCount"> | ||
<button type="button"> | ||
<img src="/images/i-like.png" alt="하트 아이콘" /> | ||
</button> | ||
<span>{product.favoriteCount}</span> | ||
</div> | ||
</div> | ||
</Link> | ||
</li> | ||
); | ||
})} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import "../css/reset.css"; | |
import "../css/style.css"; | ||
import { BrowserRouter, Route, Routes } from "react-router-dom"; | ||
import NotFoundPage from "./NotFoundPage"; | ||
import ProductDetail from "./ProductDetail"; | ||
|
||
function App() { | ||
return ( | ||
|
@@ -20,7 +21,10 @@ function App() { | |
<Route path="/" element={<Home />} /> | ||
<Route path="/Login" element={<Login />} /> | ||
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. path명은 대문자는 잘 사용하지 않습니다. 소문자로만 작성하시는 것을 추천드려요! |
||
<Route path="/Signup" element={<Signup />} /> | ||
<Route path="/Items" element={<Items />} /> | ||
<Route path="/Items"> | ||
<Route index element={<Items />} /> | ||
<Route path=":productId" element={<ProductDetail />} /> | ||
</Route> | ||
<Route path="/AddItem" element={<AddItem />} /> | ||
<Route path="*" element={<NotFoundPage />} /> | ||
</Routes> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ function Header() { | |
<Link | ||
to="/Items" | ||
className={ | ||
location.pathname === "/Items" || | ||
location.pathname === "/AddItem" | ||
location.pathname.startsWith("/Items") || | ||
location.pathname.startsWith("/AddItem") | ||
Comment on lines
+27
to
+28
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. startsWith로 조건 수정해주신점 좋네요! |
||
? "on" | ||
: "" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
import { useEffect, useState } from "react"; | ||
import AllProduct from "./AllProduct"; | ||
import BestProduct from "./BestProduct"; | ||
import { getProducts } from "../api.js"; | ||
import { Outlet } from "react-router-dom"; | ||
|
||
function Items() { | ||
const [products, setProducts] = useState([]); | ||
const [pageSize, setPageSize] = useState(4); | ||
const [order, setOrder] = useState("favorite"); | ||
|
||
const handleLoad = async (options) => { | ||
let { list } = await getProducts(options); | ||
setProducts(list); | ||
}; | ||
|
||
useEffect(() => { | ||
handleLoad({ pageSize, order }); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<div className="main-wrap"> | ||
<BestProduct products={products}></BestProduct> | ||
<AllProduct products={products}></AllProduct> | ||
<BestProduct /> | ||
<AllProduct /> | ||
<Outlet /> | ||
</div> | ||
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. 저도 처음 알게됐는데, 잘 활용해주셨네요! |
||
</> | ||
); | ||
|
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.
baseURL은 뒤에 .vercel.app까지 넣어주시면 좋을 것 같아요!