Skip to content
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

[김가희] sprint6 #92

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
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.26.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
Binary file added public/Pretendard-Regular.ttf
Binary file not shown.
Binary file removed public/favicon.ico
Binary file not shown.
Binary file added public/images/free-icon-no-pictures-3875148.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/heart-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions public/images/panda-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions public/images/user-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 4 additions & 35 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<html lang="ko">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<div id="root">

</div>
</body>
</html>
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

25 changes: 0 additions & 25 deletions src/App.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* api 호출 await 필요
* @param {*} page 페이지 번호 | default 1
* @param {*} pageSize 페이지 당 상품 수 | default 10
* @param {*} orderBy 정렬 기준 favorite, recent | default recent
* @param {*} keyword 검색 키워드
* @returns
*/
export async function getItems(
page = 1,
pageSize = 10,
orderBy = "recent",
keyword
) {
Comment on lines +9 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

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

P2:
모든 파람의 경우 default값이 설정되어 있는데, 이런 방식으로는 default값을 설정해두신 장점을 살리기 어렵습니다.
아래처럼 obj로 받으시면 필요한 값만 넘길 수 있으므로 아래와 같은 방식도 고려해보세요~

export async function getItems({
  page = 1,
  pageSize = 10,
  orderBy = "recent",
  keyword
}) { ... }

// BestList.js에서 사용시
  const fetchData = async function () {
    const data = await getItems({ pageSize: 4, orderBy: "favorite" });
    setCardList(data.list);
  };

const searchQuery = keyword ? `keyword=${keyword}` : "";
const response = await fetch(
`https://panda-market-api.vercel.app/products?page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&${searchQuery}`
);
const body = await response.json();
return body;
}

// // 1페이지 10개 최신순 줘
// const 1페이지10개 = getItems(1,10,"recent")
// const 2페이지10개 = getItems(2,10,"recent")
// const 3페이지10개 = getItems(3,10,"recent")

// // 최신순으로 1페이지 1개 줘
// const 1페이지10개 = getItems(1,10,"favorite")
// const 2페이지10개 = getItems(2,10,"favorite")
// const 3페이지10개 = getItems(3,10,"favorite")
Comment on lines +23 to +31
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
테스트를 해보시느라 주석을 남겨두신 것 같은데
이런 주석은 없는 것이 가독성에 더 좋습니다~
코드 베이스에 올라갈 이유가 없는 코드들은 commit 하실때 지우고 올리시는 걸 추천드려요

12 changes: 12 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Nav from "./Nav";

function App({ children }) {
return (
<div>
<Nav></Nav>
<div>{children}</div>
</div>
);
}

export default App;
32 changes: 32 additions & 0 deletions src/components/BestList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from "react";
import { getItems } from "../api";
import Card from "./Card";
import style from "./BestList.module.css";

function BestList() {
const [cardList, setCardList] = useState([]);

const fetchData = async function () {
const data = await getItems(1, 4, "favorite");
setCardList(data.list);
};

useEffect(() => {
fetchData();
}, []);

return (
<div className={style.wrapper}>
<div className={style.bestListBlock}>
<div className={style.label}>베스트 상품</div>
<div className={style.bestList}>
{cardList.map((item) => {
return <Card key={item.id} item={item} imgSize={"282px"}></Card>;
})}
Comment on lines +23 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

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

P3:
아래코드도 동일 동작합니다~

Suggested change
{cardList.map((item) => {
return <Card key={item.id} item={item} imgSize={"282px"}></Card>;
})}
{cardList.map((item) => (
<Card key={item.id} item={item} imgSize={"282px"}></Card>
))}

</div>
</div>
</div>
);
}

export default BestList;
31 changes: 31 additions & 0 deletions src/components/BestList.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@font-face {
font-family: "Pretendard Variable";
src: url("../../public/Pretendard-Regular.ttf");
}

.label {
font-family: "Pretendard Variable";
font-size: 20px;
font-weight: 700;
line-height: 32px;
text-align: left;
color: #111827;
}

.bestList {
display: flex;
justify-content: center;
gap: 24px;
}

.bestListBlock {
display: flex;
flex-direction: column;
gap: 16px;
width: fit-content;
}

.wrapper {
display: flex;
justify-content: center;
}
Loading
Loading