-
Notifications
You must be signed in to change notification settings - Fork 46
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 #475
Merged
clianor
merged 20 commits into
codeit-bootcamp-frontend:part3-김한샘
from
hansaemkim38:part3-김한샘-week15
May 30, 2024
The head ref may contain hidden characters: "part3-\uAE40\uD55C\uC0D8-week15"
Merged
[김한샘] Week15 #475
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2af053a
refactor: GetDaysAgo 조건 수정
hansaemkim38 aab086e
refactor: useAuthGuard 훅 추가
hansaemkim38 65877ab
refactor: 피드백 반영 > loginButton -> submitButton 변경
hansaemkim38 18c383a
refactor: 피드백 반영 > 오타수정
hansaemkim38 c391bed
add: folder, shared 추가 제거
hansaemkim38 c6710a1
feat: Request interceptors 추가
hansaemkim38 46d3d70
feat: 기존 탭 관련 folder페이지에서 불러오던 api 변경
hansaemkim38 3e1c926
feat: folder page > 다이나믹 라우터 추가
hansaemkim38 35afd15
refactor : 피드백 반영 > 절대경로
hansaemkim38 b7e80f5
refactor : FolderTabList > 이름 상위에서 처리
hansaemkim38 f16dc75
feat: 미사용 삭제 및 api 추가
hansaemkim38 78774a0
feat: Shared 페이지 동적 라우터 추가
hansaemkim38 165b2d5
refactor: Folder page 리다이렉트 추가, 상수 추가
hansaemkim38 78fe1ed
refactor: 개별 상태 변수를 단일 상태 객체로 교체
hansaemkim38 4b4dbd3
refactor: 피드백 반영 > 변수명 변경
hansaemkim38 37510cd
remove: 미사용 type 삭제
hansaemkim38 7552961
feat: 기존 샘플 헤더 데이터를 로그인 유저 정보로 변경
hansaemkim38 47d2e30
refactor: 기존 해더부분 folder/[id]일시 스타일 적용 수정
hansaemkim38 73cbf87
feat: TabData 관련 기존 샘플 삭제 및 교체
hansaemkim38 468a86d
test: test
hansaemkim38 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Search from "@/src/components/Search/Search"; | ||
import React, { useEffect, useState } from "react"; | ||
import AddLinkForm from "@/src/components/AddLinkForm/AddLinkForm"; | ||
import { getFolderIdLinks, getSharedFolderIdData } from "@/src/fetchUtils/index"; | ||
import FolderTabList from "@/src/components/FolderTabList/FolderTabList"; | ||
import CardList from "@/src/components/CardList/CardList"; | ||
import useModal from "@/src/hooks/useModal"; | ||
import ModalContext from "@/src/components/Modal/ModalContext"; | ||
import ModalContainer from "@/src/components/Modal/ModalContainer"; | ||
import Header from "@/src/components/Header/Header"; | ||
import Footer from "@/src/components/Footer/Footer"; | ||
import { useRouter } from "next/router"; | ||
import { getAccessToken } from "@/src/utils/constants"; | ||
|
||
function Folder() { | ||
const [folderTabDataList, setFolderTabDataList] = useState<FolderTabDataList[]>([]); | ||
const [userFolderDataList, setUserFolderDataList] = useState<UserFolderdataList[]>(); | ||
|
||
const { isOpen, openModal, closeModal } = useModal(); | ||
const [modalType, setModalType] = useState(""); | ||
const [cardUrl, setCardUrl] = useState(""); | ||
const [folderTabName, setFolderTabName] = useState<string | null>(""); | ||
const [searchInputValue, setSearchInputValue] = useState<string>(""); | ||
const [folderDataId, setFolderDataId] = useState<number>(0); | ||
const [name, setName] = useState<string>(""); | ||
|
||
const router = useRouter(); | ||
const { id } = router.query; | ||
|
||
useEffect(() => { | ||
const token = getAccessToken(); | ||
if (!token) { | ||
router.push("/signin"); | ||
} | ||
}, [router]); | ||
|
||
useEffect(() => { | ||
if (!router.isReady) return; | ||
|
||
async function fetchDataAndSetState() { | ||
const folderTabDataListPromise = getSharedFolderIdData(); | ||
const userFolderDataListPromise = getFolderIdLinks(Number(id)); | ||
|
||
const [fetchedFolderTabDataList, fetchedUserFolderDataList] = await Promise.all([ | ||
folderTabDataListPromise, | ||
userFolderDataListPromise, | ||
]); | ||
|
||
fetchedFolderTabDataList.data.folder.filter((item: FolderTabDataList) => { | ||
if (item.id === Number(id)) { | ||
setName(item.name); | ||
} | ||
}); | ||
setFolderTabDataList(fetchedFolderTabDataList.data.folder); | ||
setUserFolderDataList(fetchedUserFolderDataList?.data.folder); | ||
setFolderDataId(Number(id)); | ||
} | ||
fetchDataAndSetState(); | ||
}, [id, router]); | ||
|
||
const onChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchInputValue(e.target.value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header setFolderDataId={setFolderDataId} /> | ||
<div className="content-wrap"> | ||
<ModalContext.Provider | ||
value={{ isOpen, openModal, closeModal, setModalType, setCardUrl, folderDataId }} | ||
> | ||
<AddLinkForm /> | ||
<ModalContainer | ||
modalType={modalType} | ||
folderTabDataList={folderTabDataList} | ||
cardUrl={cardUrl} | ||
folderTabName={folderTabName} | ||
/> | ||
<div className="wrap"> | ||
<Search searchInputValue={searchInputValue} onChangeValue={onChangeValue} /> | ||
<FolderTabList | ||
folderTabDataList={folderTabDataList} | ||
setUserFolderDataList={setUserFolderDataList} | ||
setFolderTabName={setFolderTabName} | ||
name={name} | ||
setName={setName} | ||
/> | ||
<CardList userFolderDataList={userFolderDataList} searchInputValue={searchInputValue} /> | ||
</div> | ||
</ModalContext.Provider> | ||
</div> | ||
<Footer /> | ||
</> | ||
); | ||
} | ||
|
||
export default Folder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from "react"; | ||
import ConHeader from "@/src/components/ConHeader/ConHeader"; | ||
import Search from "@/src/components/Search/Search"; | ||
import CardList from "@/src/components/CardList/CardList"; | ||
import { useEffect, useState } from "react"; | ||
import { | ||
getSharedData, | ||
getSharedFolderIdData, | ||
getSharedFolderUserData, | ||
} from "@/src/fetchUtils/index"; | ||
import Header from "@/src/components/Header/Header"; | ||
import Footer from "@/src/components/Footer/Footer"; | ||
import { useRouter } from "next/router"; | ||
|
||
function Shared() { | ||
const [folderData, setFolderData] = useState<SharedAuthData | null>(null); | ||
const [cardListData, setCardListData] = useState<FolderLinks[]>([]); | ||
const [searchInputValue, setSearchInputValue] = useState<string>(""); | ||
const [folderInfo, setFolderInfo] = useState({ | ||
userId: 0, | ||
name: "", | ||
}); | ||
const router = useRouter(); | ||
const { id } = router.query; // folderId | ||
|
||
// 폴더 이름 id 세팅. | ||
useEffect(() => { | ||
if (!router.isReady) return; | ||
async function fetchDataAndSetState() { | ||
const response = await getSharedFolderIdData(Number(id)); | ||
if (response) { | ||
const { data } = response; | ||
|
||
setFolderInfo((prev) => ({ | ||
...prev, | ||
userId: data[0].userId, | ||
})); | ||
setFolderInfo((prev) => ({ | ||
...prev, | ||
name: data[0].name, | ||
})); | ||
} | ||
} | ||
fetchDataAndSetState(); | ||
}, [router, id]); | ||
|
||
// UserId 코드잇 이름정보, 이미지 세팅 | ||
useEffect(() => { | ||
if (!router.isReady) return; | ||
async function fetchDataAndSetState() { | ||
const response = await getSharedFolderUserData(folderInfo.userId); | ||
if (response) { | ||
const { data } = response; | ||
setFolderData(data[0]); | ||
} | ||
} | ||
fetchDataAndSetState(); | ||
}, [folderInfo.userId, router]); | ||
|
||
// 카드정보 | ||
useEffect(() => { | ||
if (!router.isReady) return; | ||
async function fetchDataAndSetState() { | ||
const response = await getSharedData(folderInfo.userId, Number(id)); | ||
if (response) { | ||
const { data } = response; | ||
setCardListData(data); | ||
} | ||
} | ||
fetchDataAndSetState(); | ||
}, [id, folderInfo.userId, router]); | ||
|
||
const onChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchInputValue(e.target.value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<div className="content-wrap"> | ||
<ConHeader folderData={folderData} folderInfo={folderInfo} /> | ||
<div className="wrap"> | ||
<Search searchInputValue={searchInputValue} onChangeValue={onChangeValue} /> | ||
<CardList cardListData={cardListData} searchInputValue={searchInputValue} /> | ||
</div> | ||
</div> | ||
<Footer /> | ||
</> | ||
); | ||
} | ||
|
||
export default Shared; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
비즈니스 로직이 길어지게 되면 해당 로직을 커스텀 훅으로 별도로 분리 해보는 것도 하나의 방법이 될 수 있습니다.
먼저 하나의 커스텀 훅으로 분리를 해보고 해당 훅으로부터 연관된것들끼리 묶어 별도의 커스텀 훅으로 쪼개나가는 것도 좋은 리팩토링 방법이 될것으로 보여집니다.