-
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
[염정훈] Sprint8 #244
The head ref may contain hidden characters: "React-\uC5FC\uC815\uD6C8-sprint8"
[염정훈] Sprint8 #244
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
import { ChangeEvent, useEffect, useRef, useState } from "react"; | ||
|
||
interface FormData { | ||
name: string; | ||
info: string; | ||
price: string; | ||
tag: string; | ||
} | ||
|
||
Comment on lines
+3
to
+8
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 AddItem() { | ||
const [formData, setFormDate] = useState({ | ||
const [formData, setFormDate] = useState<FormData>({ | ||
name: "", | ||
info: "", | ||
price: "", | ||
tag: "", | ||
}); | ||
const [addItemBtn, setAddItemBtn] = useState(""); | ||
const [btnDisabled, setBtnDisabled] = useState(true); | ||
const [inputFileUrl, setInputFileUrl] = useState(null); | ||
const inputFileImg = useRef(null); | ||
const [addItemBtn, setAddItemBtn] = useState<string>(""); | ||
const [btnDisabled, setBtnDisabled] = useState<boolean>(true); | ||
const [inputFileUrl, setInputFileUrl] = useState<string | null>(null); | ||
const inputFileImg = useRef<HTMLInputElement>(null); | ||
const imgAccept = ".jpg, .jpeg, .png"; | ||
|
||
const inputChange = (e) => { | ||
const inputChange = ( | ||
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | ||
) => { | ||
// input value 상태 변경 | ||
const { name, value } = e.target; | ||
setFormDate({ | ||
|
@@ -23,12 +32,13 @@ function AddItem() { | |
}; | ||
|
||
const inputFileChange = () => { | ||
const inputFile = inputFileImg.current.files[0]; | ||
console.log(inputFile); | ||
if (inputFileImg.current && inputFileImg.current.files) { | ||
const inputFile = inputFileImg.current.files[0]; | ||
|
||
if (inputFile) { | ||
const fileUrl = URL.createObjectURL(inputFile); | ||
setInputFileUrl(fileUrl); | ||
if (inputFile) { | ||
const fileUrl = URL.createObjectURL(inputFile); | ||
setInputFileUrl(fileUrl); | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -38,16 +48,12 @@ function AddItem() { | |
|
||
const validAddItemVal = () => { | ||
// 유효성 검사 | ||
if ( | ||
return ( | ||
formData.name.trim() !== "" && | ||
formData.info.trim() !== "" && | ||
formData.price.trim() !== "" && | ||
formData.tag.trim() !== "" | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
); | ||
}; | ||
|
||
useEffect(() => { | ||
|
@@ -128,7 +134,7 @@ function AddItem() { | |
type="number" | ||
name="price" | ||
placeholder="판매 가격을 입력해주세요." | ||
value={formData.price === NaN ? null : formData.price} | ||
value={formData.price === "" ? "" : formData.price} | ||
onChange={inputChange} | ||
/> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Link } from "react-router-dom"; | ||
import { getProducts } from "../api.js"; | ||
import { useEffect, useState } from "react"; | ||
import { MouseEvent, SetStateAction, useEffect, useState } from "react"; | ||
|
||
const responsivePageSize = () => { | ||
const winWidth = window.innerWidth; | ||
|
@@ -19,18 +19,33 @@ const responsivePageSize = () => { | |
const RECENT = "recent"; | ||
const FAVORITE = "favorite"; | ||
|
||
interface Product { | ||
id: number; | ||
name: string; | ||
info: string; | ||
price: number; | ||
tag: string; | ||
images: string; | ||
favoriteCount: number; | ||
} | ||
Comment on lines
+22
to
+30
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. API 문서에 나와 있는 Product의 데이터 구조를 그대로 작성해주시는것이 좋을 것 같습니다. {
"createdAt": "2024-08-05T08:25:27.138Z",
"favoriteCount": 0,
"ownerId": 1,
"images": [
"https://example.com/..."
],
"tags": [
"전자제품"
],
"price": 0,
"description": "string",
"name": "상품 이름",
"id": 1
} |
||
|
||
function AllProduct() { | ||
const [products, setProducts] = useState([]); | ||
const [page, setPage] = useState(1); | ||
const [pageSize, setPageSize] = useState(10); | ||
const [order, setOrder] = useState(RECENT); | ||
const [dropArrow, setDropArrow] = useState(""); | ||
const [dropDisplay, setDropDisplay] = useState("none"); | ||
const [orderTxt, setOrderTxt] = useState("최신순"); | ||
const [pagesNum, setPagesNum] = useState([1, 2]); | ||
|
||
const handleLoad = async (options) => { | ||
const [products, setProducts] = useState<Product[]>([]); | ||
const [page, setPage] = useState<number>(1); | ||
const [pageSize, setPageSize] = useState<number>(10); | ||
const [order, setOrder] = useState<string>(RECENT); | ||
const [dropArrow, setDropArrow] = useState<string>(""); | ||
const [dropDisplay, setDropDisplay] = useState<string>("none"); | ||
const [orderTxt, setOrderTxt] = useState<string>("최신순"); | ||
const [pagesNum, setPagesNum] = useState<number[]>([1, 2]); | ||
Comment on lines
+33
to
+40
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.
|
||
|
||
const handleLoad = async (options: { | ||
page: number; | ||
pageSize: number; | ||
order: string; | ||
}) => { | ||
let { list } = await getProducts(options); | ||
console.log(list); | ||
setProducts(list); | ||
}; | ||
|
||
|
@@ -39,23 +54,23 @@ function AllProduct() { | |
setDropDisplay(dropDisplay === "none" ? "block" : "none"); | ||
}; | ||
|
||
const handleNewsOrder = (e) => { | ||
const menuTxt = e.target.textContent; | ||
const handleNewsOrder = (e: MouseEvent<HTMLElement>) => { | ||
const menuTxt = e.currentTarget.textContent || ""; | ||
setOrderTxt(menuTxt); | ||
setDropArrow(""); | ||
setDropDisplay("none"); | ||
setOrder(RECENT); | ||
}; | ||
|
||
const handleBestOrder = (e) => { | ||
const menuTxt = e.target.textContent; | ||
const handleBestOrder = (e: MouseEvent<HTMLElement>) => { | ||
const menuTxt = e.currentTarget.textContent || ""; | ||
setOrderTxt(menuTxt); | ||
setDropArrow(""); | ||
setDropDisplay("none"); | ||
setOrder(FAVORITE); | ||
}; | ||
|
||
const pageNumClick = (page) => { | ||
const pageNumClick = (page: SetStateAction<number>) => { | ||
setPage(page); | ||
}; | ||
|
||
|
@@ -112,16 +127,17 @@ function AllProduct() { | |
const productPrice = product.price | ||
.toString() | ||
.replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ","); // 숫자 3자리 마다 콤마 추가(정규식 사용) | ||
const imgChk = product.images.join("").includes("jpeg"); // 이미지 경로에 jpeg가 있는지 확인 | ||
|
||
return ( | ||
<li key={product.id}> | ||
<Link to={`/Items/${product.id}`}> | ||
<div className="product-img"> | ||
<img | ||
src={ | ||
imgChk ? product.images : "/images/card01-small.png" | ||
} // 이미지 경로에 jpeg가 없으면 기본 이미지 있으면 정상적인 이미지 | ||
product.images | ||
? product.images | ||
: "/images/card01-small.png" | ||
} | ||
alt={product.name} | ||
/> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,29 @@ const responsivePageSize = () => { | |
} | ||
}; | ||
|
||
interface Product { | ||
id: number; | ||
name: string; | ||
info: string; | ||
price: number; | ||
tag: string; | ||
images: string; | ||
favoriteCount: number; | ||
} | ||
Comment on lines
+19
to
+27
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. AllProduct에서 |
||
|
||
function BestProduct() { | ||
const [products, setProducts] = useState([]); | ||
const [products, setProducts] = useState<Product[]>([]); | ||
const [page, setPage] = useState(1); | ||
const [pageSize, setPageSize] = useState(4); | ||
const [order, setOrder] = useState("favorite"); | ||
|
||
const handleLoad = async (options) => { | ||
const handleLoad = async (options: { | ||
page: number; | ||
pageSize: number; | ||
order: string; | ||
}) => { | ||
const { list } = await getProducts(options); | ||
console.log(list); | ||
setProducts(list); | ||
}; | ||
|
||
|
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.
@types
관련 의존성들은devDependancy
에 설치를 해주세요.devDependency
에 설치된 의존성 파일들은 최종 빌드시에 포함되지 않아 번들 사이즈가 줄어듭니다.