-
Notifications
You must be signed in to change notification settings - Fork 43
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
The head ref may contain hidden characters: "React-\uBC15\uD615\uC900-sprint5"
[박형준] sprint5 #255
Changes from all commits
6ed8def
37f2515
51f7f0f
7d4ea5a
93e0b7f
7d4c433
6696b89
8298dfc
51246a1
3224bfc
ede57c4
13d5cf4
dc07893
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.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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; | ||
} |
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); | ||
|
||
const handleChange = (orderBy) => { | ||
setOrder(orderBy); | ||
}; | ||
|
||
const handleLoadNext = () => { | ||
if (allItems.length < 10) { | ||
return; | ||
} else { | ||
setPage(page + 1); | ||
} | ||
}; | ||
Comment on lines
+19
to
+25
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 handleLoadNext = () => {
if (allItems.length < 10) return;
setPage(page + 1);
}; 별건 아닌데 이러면 더 깔끔해보이지 않나요? ㅎㅎ 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 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
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 commentThe 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; |
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'); | ||
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. 이건 코드에 문제가 있어보이는데요? async로 감싸지도 않았는데 await을 사용하고있네요? 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. 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
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. 의미없이 빈공간이 많네요 이런건 prettier나 eslint사용하면 바로 문제될 코드들이 많이 보이는데 둘다 세팅해보면 좋을것 같아요 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. 이상하네요, 작성할때는 이런 부분이 없었던 것 같은데, 한번 확인해보고 수정 반영하겠습니다. |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 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
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. 단순히 props로 받은 함수를 한번더 wrapping했을 뿐인데 의미가 없는것 같아요 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. 이 부분은 코드잇 강의 코드를 참조했습니다. 어떤 방향으로 작성하는 것이 더 좋을지 의견 주시면 감사하겠습니다. |
||
|
||
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; |
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.
상태의 초기값들 다 설정해주신것 좋네요 ㅎ