-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from hansaemkim38/part3-김한샘-week15
[김한샘] Week15
- Loading branch information
Showing
25 changed files
with
431 additions
and
179 deletions.
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.