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

[김보민] week15 #481

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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

# misc
.DS_Store
._.DS_Store
**/.DS_Store
**/._.DS_Store
*.pem

# debug
Expand Down
1 change: 0 additions & 1 deletion components/SinginForm/index.js

This file was deleted.

1 change: 0 additions & 1 deletion components/SingupForm/index.js

This file was deleted.

1 change: 0 additions & 1 deletion components/SocalLogin/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"baseUrl": "5-Weekly-Mission"
"baseUrl": "src"
},
"include": ["5-Weekly-Mission"]
"include": ["src"]
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@hookform/error-message": "^2.0.1",
"axios": "^1.6.8",
"axios": "^1.7.2",
"classnames": "^2.5.1",
"next": "^13.5.6",
"react": "^18",
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

pages 폴더도 src 하위로 옮겨주세요~

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AppProps } from "next/app";
import "styles/giobal.css";
import "src/styles/global.css";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
Expand Down
95 changes: 0 additions & 95 deletions pages/folder.js

This file was deleted.

83 changes: 83 additions & 0 deletions pages/folder/[folderId].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
Header,
SearchBar,
Footer,
LinkInput,
LinkList,
Sorting,
ErrorComponent,
FolderTitle,
} from "../../src/components";
import { getData } from "../../src/utils";
import styles from "src/styles/folder.module.scss";
import { useEffect, useState } from "react";
import classNames from "classnames/bind";
import { useRouter } from "next/router";

const cx = classNames.bind(styles);

function FolderPage() {
const [linksByQuery, setLinksByQuery] = useState([]);
const [Folders, setFolders] = useState([]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

상태 변수는 카멜 케이스로, 소문자로 시작하도록 일관성을 맞춰주세요~

Copy link
Collaborator

Choose a reason for hiding this comment

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

37, 39번째줄도요!

const [user, setUser] = useState([]);
const [searchKeyWord, setSearchKeyWord] = useState("");
const [name, setName] = useState("");

const router = useRouter();
const { folderId } = router.query;

/* 받아온 배열이 비어있을 경우 체크. */
function checkArrayBlank(array) {
return !Array.isArray(array) || array.length === 0;
}

/* 쿼리id로 받은 링크들, 유저데이터, 선택한 폴더 이름 데이터 가져오기*/
async function fetchData() {
const linkUrl = `/links?folderId=${folderId}`;
const FolderUrl = `/folders/${folderId}`;

const Folders = await getData("/folders");
const linksByQuery = await getData(linkUrl);
const user = await getData("/users");
const name = await getData(FolderUrl);

setLinksByQuery(linksByQuery.data.folder);
setUser(user.data[0]);
setName(name.data[0].name);
setFolders(Folders.data.folder);
Comment on lines +44 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

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

folderid 가 변경될 때 fetchData 가 실행되면서 전체 폴더, 폴더에 있는 링크들, 유저, 폴더 정보 요렇게 총 네가지를 다시 불러오고 있습니다.
유저 정보 같은건 새로 불러오지 않아도 될 것 같은데 네가지 모두 다 불러와야하는지 검토해보시면 좋을 것 같아요~

}

useEffect(() => {
fetchData();
}, [folderId]);

return (
<div>
<Header userEmail={user.email} />
<LinkInput folders={Folders} />
<div className={cx("contents-wrapper")}>
<SearchBar
searchKeyWord={searchKeyWord}
setSearchKeyWord={setSearchKeyWord}
/>
<div className={cx("links-wrapper")}>
<Sorting folders={Folders} folderId={folderId} />
<FolderTitle name={name} />
{checkArrayBlank(linksByQuery) ? (
<ErrorComponent />
) : (
<LinkList
searchKeyWord={searchKeyWord}
links={linksByQuery}
createdTime="created_at"
image="image_source"
/>
)}
</div>
</div>
<Footer />
</div>
);
}

export default FolderPage;
75 changes: 75 additions & 0 deletions pages/folder/index.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

index 와 folderId 페이지로 나눠주신 이유가 있나용?

파일명 컨벤션 중에 optional 로 segment 값을 받을 수 있는게 있습니다. 요걸로 하나의 페이지로 작업해볼 수 있을 것 같습니다!
https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes#optional-catch-all-segments

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
Header,
SearchBar,
Footer,
LinkInput,
LinkList,
Sorting,
ErrorComponent,
FolderTitle,
} from "../../src/components";
import { checkAccessToken, getData } from "../../src/utils";
import styles from "src/styles/folder.module.scss";
import { useEffect, useState } from "react";
import classNames from "classnames/bind";

const cx = classNames.bind(styles);

function FolderPage() {
const [searchKeyWord, setSearchKeyWord] = useState("");
const [user, setUser] = useState("");
const [Folders, setFolders] = useState("");
const [AllLinks, setAllLinks] = useState("");

function checkArrayBlank(array) {
return array.length && array.length !== 0 ? false : true;
}

async function fetchData() {
const user = await getData("/users");
const Folders = await getData("/folders");
const AllLinks = await getData("/links");

setUser(user.data[0]);
setFolders(Folders.data.folder);
setAllLinks(AllLinks.data.folder);
}

useEffect(() => {
/* AccessToken없으면 signin페이지로 이동*/
if (!checkAccessToken("signInToken")) {
location.href = "signin";
}
fetchData();
}, []);

return (
<div>
<Header userEmail={user.email} />
<LinkInput folders={Folders} />
<div className={cx("contents-wrapper")}>
<SearchBar
searchKeyWord={searchKeyWord}
setSearchKeyWord={setSearchKeyWord}
/>
<div className={cx("links-wrapper")}>
<Sorting folders={Folders} />
<FolderTitle name={"전체"} />
{checkArrayBlank(AllLinks) ? (
<ErrorComponent />
) : (
<LinkList
searchKeyWord={searchKeyWord}
links={AllLinks}
createdTime="created_at"
image="image_source"
/>
)}
</div>
</div>
<Footer />
</div>
);
}

export default FolderPage;
52 changes: 52 additions & 0 deletions pages/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import styles from "src/styles/SharedPage.module.scss";
import classNames from "classnames/bind";
import {
Header,
FolderInfo,
SearchBar,
LinkList,
Footer,
} from "../src/components";
import { getLinkList, getData, ApiUrl } from "../src/utils";
import { useEffect, useState } from "react";

const cx = classNames.bind(styles);

function SharedPage() {
const [links, setLinks] = useState([]);
const [user, setUser] = useState([]);
const [searchKeyWord, setSearchKeyWord] = useState("");

const getUserData = async () => {
const { links } = await getLinkList();
const user = await getData(ApiUrl.sampleUser);
setLinks(links);
setUser(user);
};

useEffect(() => {
getUserData();
}, []);

return (
<>
<Header userEmail={user.email} />
<FolderInfo userName={user.name} />
<div className={cx("contents-wrapper")}>
<SearchBar
searchKeyWord={searchKeyWord}
setSearchKeyWord={setSearchKeyWord}
/>
<LinkList
searchKeyWord={searchKeyWord}
links={links}
createdTime="createdAt"
image="imageSource"
/>
</div>
<Footer />
</>
);
}

export default SharedPage;
Loading
Loading