-
Notifications
You must be signed in to change notification settings - Fork 57
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
[박준성] Week7 #273
The head ref may contain hidden characters: "part2-\uBC15\uC900\uC131-week7"
[박준성] Week7 #273
Changes from all commits
1c73b68
52752bd
2a3e020
e93f636
511fc4a
0cdeec7
4ce3ee9
58a7085
d57989b
1e4649a
786f956
dc1bd3c
16983b4
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { BrowserRouter, Routes, Route } from "react-router-dom"; | ||
import SharedPage from "./pages/SharedPage"; | ||
import FolderPage from "./pages/FolderPage"; | ||
import Footer from "./components/Footer"; | ||
|
||
function Main() { | ||
return ( | ||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/shared" element={<SharedPage />}/> | ||
<Route path="/folder" element={<FolderPage />}/> | ||
</Routes> | ||
<Footer /> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
||
export default Main; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,59 @@ | ||
// export async function getProfile() { | ||
// const response = await fetch ('https://bootcamp-api.codeit.kr/api/sample/user') | ||
// const body = await response.json(); | ||
// return body; | ||
// } | ||
// 사용하고 싶은데 사용하지 못해서 남겨둠.. | ||
export async function fetchProfile() { | ||
try { | ||
const response = await fetch( | ||
"https://bootcamp-api.codeit.kr/api/sample/user" | ||
); | ||
const body = await response.json(); | ||
return body; | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
} | ||
|
||
export async function fetchLinks() { | ||
try { | ||
const response = await fetch( | ||
"https://bootcamp-api.codeit.kr/api/sample/folder" | ||
); | ||
const body = await response.json(); | ||
return body; | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
} | ||
|
||
export async function getUser() { | ||
try { | ||
const response = await fetch( | ||
"https://bootcamp-api.codeit.kr/api/users/1" | ||
) | ||
const body = await response.json(); | ||
return body; | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
} | ||
|
||
export async function getUserFolder() { | ||
try { | ||
const response = await fetch( | ||
"https://bootcamp-api.codeit.kr/api/users/1/folders" | ||
) | ||
const body = await response.json(); | ||
return body; | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
} | ||
|
||
export async function getUserLink() { | ||
try { | ||
const response = await fetch( | ||
"https://bootcamp-api.codeit.kr/api/users/1/links" | ||
) | ||
const body = await response.json(); | ||
return body; | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
function AddLink() { | ||
return ( | ||
<div className="AddLink"> | ||
<div className="InputContainer"> | ||
<input className="AddLinkInput" placeholder="링크를 추가해 보세요"/> | ||
<button className="AddLinkButton">추가하기</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default AddLink; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import noneImg from "../assets/noneimg.svg"; | ||
import { timeAgo } from "../time"; | ||
import { useState } from "react"; | ||
import KebabModal from "./KebabModal"; | ||
import { Link } from "react-router-dom"; | ||
|
||
function formatDate(value) { | ||
const date = new Date(value); | ||
return `${date.getFullYear()}. ${date.getMonth() + 1}. ${date.getDate()}`; | ||
} | ||
Comment on lines
+7
to
+10
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. Date객체의 toLocaleString이나 Intl.DateTimeFormat 같은 아이들로도 어느정도 포맷팅은 가능합니다! 위 formatDate함수에서 하는 일은 해당 api로 불가한 포맷팅일까요? |
||
|
||
function Card({ data }) { | ||
const [modalOpen, setModalOpen] = useState(Array(data).fill(false)); | ||
const showModal = (index) => { | ||
const newModalOpen = [...modalOpen]; | ||
newModalOpen[index] = !newModalOpen[index]; | ||
setModalOpen(newModalOpen); | ||
} | ||
Comment on lines
+13
to
+18
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. 배열도 좋지만 Set을 사용해도 좋겠습니다. |
||
|
||
return ( | ||
<div className="CardGrid"> | ||
{data ? (data.map((data, index) => ( | ||
<div className="Contents"> | ||
<Link to={data.url} target="_blank"> | ||
<div className="CardContainer"> | ||
<button className="StarImg"></button> | ||
<img | ||
className="Card" | ||
src={data.image_source || noneImg} | ||
key={data.id} | ||
alt="이미지 미리보기" | ||
/> | ||
</div> | ||
</Link> | ||
<div className="CardInfoContainer"> | ||
{modalOpen[index] && <KebabModal />} | ||
<button className="KebabImg" onClick={() => showModal(index)}></button> | ||
<p className="CreatedAt">{timeAgo(data.created_at)}</p> | ||
<p className="Description"> | ||
{data.description || "no description"} | ||
</p> | ||
<p className="makeDate">{formatDate(data.created_at)}</p> | ||
</div> | ||
</div> | ||
))) : ( | ||
<p>"저장된 링크가 없습니다"</p> | ||
)} | ||
|
||
</div> | ||
); | ||
} | ||
|
||
export default Card; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import noneImg from "../assets/noneimg.svg"; | ||
import { timeAgo } from "../time"; | ||
import KebabModal from "./KebabModal"; | ||
import { useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
function formatDate(value) { | ||
const date = new Date(value); | ||
return `${date.getFullYear()}. ${date.getMonth() + 1}. ${date.getDate()}`; | ||
} | ||
|
||
Comment on lines
+7
to
+11
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. 같은 로직이 다른 파일에도 있었던 것 같아요. 별도의 모듈(utils)로 분리하면 좋겠습니다. |
||
function Card({ data }) { | ||
const [modalOpen, setModalOpen] = useState(Array(data).fill(false)); | ||
const showModal = (index) => { | ||
const newModalOpen = [...modalOpen]; | ||
newModalOpen[index] = !newModalOpen[index]; | ||
setModalOpen(newModalOpen); | ||
} | ||
|
||
return ( | ||
<div className="CardGrid"> | ||
{data && | ||
data.map((data, index) => ( | ||
<div className="Contents"> | ||
<Link to={data.url}> | ||
<div className="CardContainer"> | ||
<button className="StarImg"></button> | ||
<img | ||
className="Card" | ||
src={data.imageSource || noneImg} | ||
key={data.id} | ||
alt="이미지 미리보기" | ||
/> | ||
</div> | ||
</Link> | ||
<div className="CardInfoContainer"> | ||
<button className="KebabImg" onClick={() => showModal(index)}></button> | ||
{modalOpen[index] && <KebabModal />} | ||
<p className="CreatedAt">{timeAgo(data.createdAt)}</p> | ||
<p className="Description"> | ||
{data.description || "no description"} | ||
</p> | ||
<p className="makeDate">{formatDate(data.createdAt)}</p> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default Card; |
This file was deleted.
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.
fetcn 함수를 호출하고 response.json을 반환하는 로직이 반복되는 것 같은데 반복되는 부분만 별도의 함수로 분리해보면 어떨가요?