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

[박준성] Week7 #273

Merged
merged 13 commits into from
Jan 11, 2024
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
39 changes: 39 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.20.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
18 changes: 18 additions & 0 deletions src/Main.js
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;
65 changes: 59 additions & 6 deletions src/api.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

fetcn 함수를 호출하고 response.json을 반환하는 로직이 반복되는 것 같은데 반복되는 부분만 별도의 함수로 분리해보면 어떨가요?

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);
}
}
8 changes: 8 additions & 0 deletions src/assets/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/editimg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/kebab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/assets/noneimg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/assets/shareimg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/assets/star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/components/AddLink.js
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;
17 changes: 0 additions & 17 deletions src/components/App.js

This file was deleted.

53 changes: 53 additions & 0 deletions src/components/Card-folder.js
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

배열도 좋지만 Set을 사용해도 좋겠습니다.
모달마다 id를 주고 그 id를 set에 add/delete하는 방식도 고려해보시면 좋을 것 같아요


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;
51 changes: 51 additions & 0 deletions src/components/Card-shared.js
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
19 changes: 0 additions & 19 deletions src/components/Card.js

This file was deleted.

Loading