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

[박형준] sprint5 #255

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
10,461 changes: 5,854 additions & 4,607 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@noonnu/rokaf-sans-medium": "^0.1.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
31 changes: 0 additions & 31 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,9 @@
<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`.
-->
</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.

38 changes: 38 additions & 0 deletions src/App/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@import url('https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.min.css');
@import url('https://fonts.googleapis.com/css2?family=ROKAF+Sans:wght@400;700&display=swap');
@import url('~@noonnu/rokaf-sans-medium');

:root {
--blue100: #3692ff;
--grey200: #1f2937;
--grey100: #4b5563;
}

* {
margin: 0;
padding: 0;

font-family: 'Pretendard', sans-serif;
}

a {
text-decoration: none;
}

.loadChangeButton {
width: 100%;
display: flex;
justify-content: center;
}

.loadChange {
/* width: 100%; */
flex-grow: 1;
height: 50px;

font-size: 25px;
border-radius: 10px;

margin-bottom: 100px;
cursor: pointer;
}
57 changes: 57 additions & 0 deletions src/App/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useEffect, useState } from 'react';
import { getData } from '../api';
import AllItems from '../Components/AllItems/AllItems';
import BestItems from '../Components/BestItems/BestItems';
import Header from '../Components/Header/Header';
import './App.css';

const { list: bestItems } = await getData({ order: 'favorite' });

function App() {
const [allItems, setAllItems] = useState([]);
const [order, setOrder] = useState('recent');
const [page, setPage] = useState(1);
Comment on lines +11 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

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

상태의 초기값들 다 설정해주신것 좋네요 ㅎ


const handleChange = (orderBy) => {
setOrder(orderBy);
};

const handleLoadNext = () => {
if (allItems.length < 10) {
return;
} else {
setPage(page + 1);
}
};
Comment on lines +19 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.

  const handleLoadNext = () => {
    if (allItems.length < 10) return;
      setPage(page + 1);
  };

별건 아닌데 이러면 더 깔끔해보이지 않나요? ㅎㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

너무 깔끔해보입니다. 사실 저도 이렇게 깔끔하게 만들고 싶은데,, 아직까지 처음 배웠던 코드 형식에서 벗어나지 못하는 것 같습니다. 차근차근 좋아지는 모습 보여드리겠습니다.

const handleLoadPre = () => {
if (page === 1) {
return;
} else {
setPage(page - 1);
}
};

const itemLoad = async (orderQuery) => {
const { list: nextItems } = await getData(orderQuery);
setAllItems(nextItems);
};
Comment on lines +34 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 함수는 useCallback으로 감싸든 아니면 useEffect 내부로 들어가는게 좀 더 좋아보이네요 ㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정 반영하겠습니다.


useEffect(() => {
itemLoad({ order, page });
}, [order, page]);

return (
<>
<Header />
<BestItems items={bestItems} />
<AllItems
items={allItems}
onChange={handleChange}
onLoadNext={handleLoadNext}
onLoadPre={handleLoadPre}
/>
</>
);
}

export default App;
141 changes: 141 additions & 0 deletions src/App/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// App.js

import { useEffect, useState } from 'react';
import { getData } from '../api';
import AllItems from '../Components/AllItems/AllItems';
import BestItems from '../Components/BestItems/BestItems';
import Header from '../Components/Header/Header';
import './App.css';

const { list: bestItems } = await getData('favorite');
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 코드에 문제가 있어보이는데요? async로 감싸지도 않았는데 await을 사용하고있네요?
추가로 const [allItems, setAllItems] = useState([]); 이렇게 상태로 담지 않았는지도 여쭤보고싶네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

async로 반드시 감싸지 않으면 안될까요?? 사실 async로 감싸려면 해당 부분을 함수로 만들어야 할 것 같은데,, 어떤 방향으로 코드를 작성해야할지 몰라서 일단 저렇게 만들었습니다. 그리고 왜 bestItems를 state로 만들어서 관리하지 않았냐라고 물으시는 거라면, 저는 베스트 아이템 부분이 고정된다고 생각해서 따로 만들지 않았습니다.


function App() {
const [allItems, setAllItems] = useState([]);
const [order, setOrder] = useState('recent');
const [preOrder, setPreOrder] = useState(order);
const [page, setPage] = useState(1);

const handleChange = (orderBy) => {
setOrder(orderBy);
};

const handLoadMore = () => {
setPage(page + 1);
};

const load = async (orderQuery) => {
const { list: nextItems } = await getData(orderQuery);
if (orderQuery.page === 1) {
setAllItems(nextItems);
} else {
setAllItems([...allItems, ...nextItems]);
}
};

useEffect(() => {
if (order !== preOrder) {
load({ order });
} else {
load({ order, page });
}
}, [order, page]);

return (
<>
<Header />
<BestItems items={bestItems} />
<AllItems
items={allItems}
onChange={handleChange}
onLoadMore={handLoadMore}
/>
</>
);
}

export default App;


























Comment on lines +58 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

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

의미없이 빈공간이 많네요 이런건 prettier나 eslint사용하면 바로 문제될 코드들이 많이 보이는데 둘다 세팅해보면 좋을것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이상하네요, 작성할때는 이런 부분이 없었던 것 같은데, 한번 확인해보고 수정 반영하겠습니다.















// AllItems.js

import AllItemList from './AllItemList/AllItemList';
import './AllItems.css';

function AllItems({ items, onChange, onLoadMore }) {
const allItemsChange = (e) => {
onChange(e.target.value);
};

const handLoadMore = () => {
onLoadMore();
};
Comment on lines +107 to +109
Copy link
Collaborator

Choose a reason for hiding this comment

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

단순히 props로 받은 함수를 한번더 wrapping했을 뿐인데 의미가 없는것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이 부분은 코드잇 강의 코드를 참조했습니다. 어떤 방향으로 작성하는 것이 더 좋을지 의견 주시면 감사하겠습니다.


return (
<div className="allItems">
<div className="container">
<h2>전체 상품</h2>
<div className="allItemsRight">
<input type="text" placeholder="검색할 상품을 입력해주세요"></input>
<button>상품 등록하기</button>
<select
className="orderSelect"
name="order"
onChange={allItemsChange}
>
<option value="recent">최신순</option>
<option value="favorite">베스트순</option>
</select>
</div>
</div>

<ul className="itemList">
{items.map((item, index) => {
return <AllItemList key={item.id} item={item} index={index} />;
})}
</ul>
<button className="loadMore" onClick={handLoadMore}>
더보기
</button>
</div>
);
}

export default AllItems;
Loading
Loading