-
Notifications
You must be signed in to change notification settings - Fork 44
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
[우제윤 ] Week8 #329
The head ref may contain hidden characters: "part2-\uC6B0\uC81C\uC724-week8"
[우제윤 ] Week8 #329
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,4 @@ | |
} | ||
} | ||
} | ||
/* <div className="FolderList_list-container"> */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
width: 100%; | ||
top: 0; | ||
align-items: center; | ||
z-index: 1; | ||
} | ||
|
||
.NavigationBar-items { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
.SearchBar { | ||
z-index: -1; | ||
position: relative; | ||
width: 90%; | ||
width: 325px; | ||
margin-left: 50px; | ||
margin-right: 50px; | ||
margin-top: 20px; | ||
max-width: 1124px; | ||
} | ||
|
||
.SearchBar-InputSearch { | ||
background-color: var(--gray-light); | ||
margin-top: 20px; | ||
width: 100%; | ||
height: 43px; | ||
width: 100%; | ||
border-radius: 10px; | ||
padding-left: 13%; | ||
padding-right: 8%; | ||
} | ||
|
||
.SearchBar-InputSearch-icon { | ||
position: absolute; | ||
top: 52%; | ||
top: 35%; | ||
left: 5%; | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.SearchBar { | ||
width: 745px; | ||
} | ||
.SearchBar-InputSearch { | ||
padding-left: 10%; | ||
padding-right: 8%; | ||
} | ||
} | ||
|
||
@media (min-width: 1124px) { | ||
.SearchBar { | ||
width: 1050px; | ||
} | ||
|
||
.SearchBar-InputSearch-icon { | ||
left: 2%; | ||
} | ||
|
||
.SearchBar-InputSearch { | ||
padding-left: 5%; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useState, useEffect } from "react"; | ||
import { getFolderList, getAllFolderList } from "./getUserFolder"; | ||
const BASE_URL = "https://bootcamp-api.codeit.kr/api"; | ||
|
||
export function useFolderAsync() { | ||
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. custom hook으로 잘 짜셨네요! 👍👍 |
||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const [folderList, setFolderList] = useState(null); | ||
const [allFolderList, setAllFolderList] = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const folderList = await getFolderList(); | ||
const allFolderList = await getAllFolderList(); | ||
|
||
setFolderList(folderList); | ||
setAllFolderList(allFolderList); | ||
setLoading(false); // 로딩 상태 변경 | ||
} catch (error) { | ||
// 에러 발생 시 에러 상태 업데이트 | ||
setError(error); | ||
setLoading(false); // 로딩 상태 변경 | ||
} | ||
}; | ||
|
||
fetchData(); // fetchData 함수 호출 | ||
}, []); | ||
|
||
return { folderList, allFolderList, loading, error }; // 상태를 반환 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.btn { | ||
background-image: linear-gradient(to right, #6d6afe, #6ae3fe); | ||
border-radius: 8px; | ||
color: #f5f5f5; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: none; | ||
cursor: pointer; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import "../CardList/CardList.css"; | ||
import { useState, useEffect } from "react"; | ||
import FolderCardListItem from "./FolderCardListItem"; | ||
|
||
export const FolderCardList = ({ folderId }) => { | ||
const [folderInfo, setFolderInfo] = useState(null); // 폴더 정보 상태 | ||
const BASE_URL = "https://bootcamp-api.codeit.kr/api"; | ||
|
||
useEffect(() => { | ||
const getFolderListById = async () => { | ||
try { | ||
let response; | ||
if (folderId) { | ||
response = await fetch( | ||
`${BASE_URL}/users/1/links?folderId=${folderId}` | ||
); | ||
} else { | ||
response = await fetch(`${BASE_URL}/users/1/links`); | ||
} | ||
|
||
if (!response.ok) { | ||
throw new Error("폴더 정보를 가져오는데 실패했습니다."); | ||
} | ||
|
||
const folderData = await response.json(); | ||
setFolderInfo(folderData); // 폴더 정보 상태 업데이트 | ||
} catch (error) { | ||
console.error(error); | ||
setFolderInfo([]); // 에러 발생 시 폴더 정보를 빈 배열로 초기화 | ||
} | ||
}; | ||
// 폴더 정보 가져오는 함수 호출 | ||
getFolderListById(); | ||
}, [folderId]); // folderId가 변경될 때마다 호출 | ||
|
||
useEffect(() => { | ||
if (folderInfo) { | ||
console.log("폴더 정보:", folderInfo); | ||
} | ||
}, [folderInfo]); | ||
Comment on lines
+36
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. 이 useEffect는 어떤 의미가 있나요? |
||
|
||
if (!folderInfo) { | ||
return <div>로딩 중...</div>; | ||
} | ||
|
||
if (folderInfo.data && Array.isArray(folderInfo.data)) { | ||
// 폴더 정보가 객체이고 그 안에 data 필드가 있는 경우, data를 사용하여 렌더링합니다. | ||
return ( | ||
<div className="CardList"> | ||
{folderInfo.data.map((item, index) => ( | ||
<div className="CardList-item" key={index}> | ||
<FolderCardListItem item={item} /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
Comment on lines
+46
to
+57
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. forlderInfo?.data?.map으로 하면 조건 검사가 좀 더 쉬워집니다. optional chaning 한번 살펴보세요! |
||
|
||
// 폴더 정보가 없거나 잘못된 형태인 경우 에러를 표시합니다. | ||
return <div>폴더 정보를 불러오는 중 문제가 발생했습니다.</div>; | ||
}; |
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.
self-close 해주세요!
<img src={SEARCH_ICON} className="SearchBar-InputSearch-icon"/>