Skip to content

Commit f9fb20e

Browse files
authored
Merge pull request #125 from jeschun/React-박신천-sprint8A
[박신천] Sprint 8
2 parents 066ca20 + ee76819 commit f9fb20e

File tree

18 files changed

+1864
-295
lines changed

18 files changed

+1864
-295
lines changed

.DS_Store

0 Bytes
Binary file not shown.

vite-project/package-lock.json

Lines changed: 1748 additions & 247 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite-project/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"react": "^19.1.0",
14-
"react-dom": "^19.1.0",
13+
"@types/jest": "^30.0.0",
14+
"@types/node": "^24.3.1",
15+
"axios": "^1.11.0",
16+
"file-loader": "^6.2.0",
17+
"install": "^0.13.0",
18+
"react": "^19.1.1",
19+
"react-dom": "^19.1.1",
1520
"react-router-dom": "^7.8.2"
1621
},
1722
"devDependencies": {
1823
"@eslint/js": "^9.25.0",
19-
"@types/react": "^19.1.2",
20-
"@types/react-dom": "^19.1.2",
24+
"@types/react": "^19.1.12",
25+
"@types/react-dom": "^19.1.9",
2126
"@vitejs/plugin-react": "^4.7.0",
2227
"eslint": "^9.25.0",
2328
"eslint-plugin-react-hooks": "^5.2.0",
File renamed without changes.

vite-project/src/api/api.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

vite-project/src/api/api.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import instance from "./axiosInstance";
2+
3+
export interface Items {
4+
id: number;
5+
name: string;
6+
price: number;
7+
tags: string[];
8+
images: string[];
9+
favoriteCount: number;
10+
createdAt: string;
11+
updatedAt: string;
12+
}
13+
export type OrderBy = "recent" | "favorite";
14+
export interface GetListsParams {
15+
page: number;
16+
pageSize: number;
17+
orderBy: OrderBy;
18+
keyword?: string;
19+
}
20+
21+
export interface GetListsResponse {
22+
list: Items[];
23+
}
24+
25+
export async function getLists({
26+
page = 1,
27+
pageSize = 10,
28+
orderBy = "recent",
29+
keyword = "",
30+
}: GetListsParams): Promise<GetListsResponse> {
31+
const query = `page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&keyword=${keyword}`;
32+
33+
try {
34+
const { data } = await instance.get(`/products?${query}`);
35+
return data;
36+
} catch {
37+
throw new Error("상품 목록을 가져오는데 실패했습니다.");
38+
}
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import axios from "axios";
2+
3+
const instance = axios.create({
4+
baseURL: "https://panda-market-api.vercel.app",
5+
headers: {
6+
"Content-Type": "application/json",
7+
},
8+
});
9+
10+
export default instance;

vite-project/src/components/AllItems.jsx renamed to vite-project/src/components/AllItems.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import { useNavigate } from "react-router-dom";
22
import "./AllItems.css";
3+
import { OrderBy } from "../api/api";
34

4-
const AllItems = ({ orderBy, setOrderBy, search, setSearch }) => {
5+
interface Props {
6+
orderBy: string;
7+
setOrderBy: React.Dispatch<React.SetStateAction<OrderBy>>; // AllItems 왼쪽 setOrderBy가 any로 떠서 오른쪽 setOrderBy를 hover 해서 뜬걸 그대로 붙여넣었습니다
8+
search: string;
9+
setSearch: React.Dispatch<React.SetStateAction<string>>; // ''
10+
}
11+
const AllItems = ({ orderBy, setOrderBy, search, setSearch }: Props) => {
512
const navigate = useNavigate();
613

714
const navigateToRegister = () => {
815
navigate("/additem");
916
};
1017

18+
const SetOrderBySelect = (e: React.ChangeEvent<HTMLSelectElement>) => {
19+
if (e.target.value === "recent" || e.target.value === "favorite")
20+
setOrderBy(e.target.value);
21+
}; //OrderBy가 리터럴 유니온 타입인데, e.target.value가 string 으로 타입오류가 떠서 if 문으로 고쳤습니다
22+
1123
return (
1224
<>
1325
<div className="allitems_menu">
@@ -29,9 +41,7 @@ const AllItems = ({ orderBy, setOrderBy, search, setSearch }) => {
2941
<select
3042
className="dropped-down"
3143
value={orderBy}
32-
onChange={(e) => {
33-
setOrderBy(e.target.value);
34-
}}
44+
onChange={SetOrderBySelect}
3545
>
3646
<option value="recent">최신순</option>
3747
<option value="favorite">좋아요순</option>
File renamed without changes.

0 commit comments

Comments
 (0)