-
Notifications
You must be signed in to change notification settings - Fork 51
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
[박소현] week19 #556
The head ref may contain hidden characters: "part3-\uBC15\uC18C\uD604-week19"
[박소현] week19 #556
Changes from 21 commits
ed532f1
fd9be93
0179f98
a5dc2aa
818580f
832c2b9
431cd77
ed85349
4475303
753ba0f
4c02cae
aa679c2
ddc9db1
fbadf32
f2ed2e7
ecb98c7
0352c15
6e3c4ca
dedab35
f83202e
cb60c95
8329902
5bfbe18
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ import Loading from "@/components/Loading"; | |
import Options from "@/components/Options"; | ||
|
||
import { FolderUIProps } from "./FolderTypes"; | ||
import { DEFAULT } from "./FolderContainer"; | ||
import { useIntersectionObserver } from "@/hooks/useIntersectionObserver"; | ||
|
||
export default function FolderUI(props: FolderUIProps) { | ||
|
@@ -26,7 +25,7 @@ export default function FolderUI(props: FolderUIProps) { | |
{isOpenModal && ( | ||
<ModalPortal> | ||
<ModalContainer onClose={handleCloseModal}> | ||
<AddFolders /> | ||
<AddFolders onClose={handleCloseModal} /> | ||
</ModalContainer> | ||
</ModalPortal> | ||
)} | ||
|
@@ -51,7 +50,7 @@ export default function FolderUI(props: FolderUIProps) { | |
)} | ||
<S.MenuContainer> | ||
<Categories | ||
categories={[DEFAULT, ...props.folderNames]} | ||
categories={["전체", ...props.folderNames]} | ||
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. 혹시 상수에서 이렇게 다시 바꿔주신 이유가 있을까요? |
||
selected={props.selected} | ||
onClick={props.handleSelectedFolder} | ||
/> | ||
|
@@ -67,7 +66,7 @@ export default function FolderUI(props: FolderUIProps) { | |
<> | ||
<S.MenuContainer> | ||
<S.SubTitle>{props.selected}</S.SubTitle> | ||
{props.selected !== DEFAULT && <Options selected={props.selected} />} | ||
{props.selected !== "전체" && <Options selected={props.selected} />} | ||
</S.MenuContainer> | ||
<CardList links={props.filteredLinks} /> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,127 @@ | ||||||
import { useRouter } from "next/router"; | ||||||
import { ChangeEvent, useContext, useEffect, useState } from "react"; | ||||||
import useSWR from "swr"; | ||||||
import * as S from "../FolderStyles"; | ||||||
|
||||||
import Layout from "@/components/layout/Layout"; | ||||||
import ModalPortal from "@/components/ModalPortal"; | ||||||
import AddFolders from "@/components/modal/AddFolders"; | ||||||
import ModalContainer from "@/components/modal/ModalContainer"; | ||||||
import FolderHero from "@/components/hero/HeroAboutFolder"; | ||||||
import Searchbar from "@/components/inputs/Searchbar"; | ||||||
import Categories from "@/components/Categories"; | ||||||
import CardList from "@/components/card/CardList"; | ||||||
import Options from "@/components/Options"; | ||||||
import Loading from "@/components/Loading"; | ||||||
|
||||||
import { useFolder } from "@/hooks/useFolder"; | ||||||
import { useIntersectionObserver } from "@/hooks/useIntersectionObserver"; | ||||||
import { Folder } from "@/types/folder"; | ||||||
import { LinkData } from "@/types/link"; | ||||||
import { FolderContext } from "@/context/SelectedFolderContext"; | ||||||
import { checkMatchedAllLinks } from "@/common/utils/matchedKeyword"; | ||||||
|
||||||
export default function FolderPage() { | ||||||
const router = useRouter(); | ||||||
const { selectedFolderName, updateFolderName } = useContext(FolderContext); | ||||||
const { ref, isIntersecting } = useIntersectionObserver<HTMLDivElement>(); | ||||||
|
||||||
const [selected, setSelected] = useState(selectedFolderName); | ||||||
const [addLinkValue, setAddLinkValue] = useState(""); | ||||||
const [keyword, setKeyword] = useState(""); | ||||||
const [isOpenModal, setIsOpenModal] = useState(false); | ||||||
const [filteredLinks, setFilteredLinks] = useState<LinkData[]>([]); | ||||||
|
||||||
const { data: foldersData, isLoading } = useFolder("/folders"); | ||||||
const { data: linksData } = useSWR(`/folders/${router.query.id}/links`); | ||||||
|
||||||
const folders: Folder[] = foldersData ?? []; | ||||||
const links: LinkData[] = linksData ?? []; | ||||||
|
||||||
const folderNames = folders.map((folder) => folder.name); | ||||||
|
||||||
const handleAddLink = (link: string) => { | ||||||
setAddLinkValue(link); | ||||||
}; | ||||||
|
||||||
const handleCloseModal = () => setIsOpenModal(false); | ||||||
|
||||||
const handleOnChangeInput = (e: ChangeEvent<HTMLInputElement>) => { | ||||||
setKeyword(e.target.value); | ||||||
const searchedLinks = checkMatchedAllLinks(e.target.value, links); | ||||||
setFilteredLinks(searchedLinks.length !== 0 ? searchedLinks : []); | ||||||
}; | ||||||
|
||||||
const handleDeletekeyword = () => { | ||||||
setKeyword(""); | ||||||
setFilteredLinks(links); | ||||||
}; | ||||||
|
||||||
const handleSelectedFolder = (category: string) => { | ||||||
setSelected(category); | ||||||
const selectedFolderId = folders.find((folder: Folder) => folder.name === category)?.id ?? ""; | ||||||
updateFolderName(category); | ||||||
router.push(`/folder/${selectedFolderId}`); | ||||||
}; | ||||||
|
||||||
useEffect(() => { | ||||||
if (linksData) { | ||||||
setFilteredLinks(linksData); | ||||||
} | ||||||
setSelected(selectedFolderName); | ||||||
}, [linksData, selectedFolderName]); | ||||||
|
||||||
return ( | ||||||
<> | ||||||
{isOpenModal && ( | ||||||
<ModalPortal> | ||||||
<ModalContainer onClose={handleCloseModal}> | ||||||
<AddFolders onClose={handleCloseModal} /> | ||||||
</ModalContainer> | ||||||
</ModalPortal> | ||||||
)} | ||||||
|
||||||
<Layout footerRef={ref}> | ||||||
<FolderHero | ||||||
onChangeAddLink={handleAddLink} | ||||||
addLinkValue={addLinkValue} | ||||||
isFixedInput={isIntersecting} | ||||||
/> | ||||||
<S.Contents> | ||||||
<Searchbar | ||||||
keyword={keyword} | ||||||
handleOnChangeInput={handleOnChangeInput} | ||||||
handleDelete={handleDeletekeyword} | ||||||
/> | ||||||
{keyword && ( | ||||||
<S.SearchInfo> | ||||||
<S.SearchKeyword>{keyword}</S.SearchKeyword> | ||||||
으로 검색한 결과입니다. | ||||||
</S.SearchInfo> | ||||||
)} | ||||||
<S.MenuContainer> | ||||||
<Categories | ||||||
categories={["전체", ...folderNames]} | ||||||
selected={selected} | ||||||
onClick={handleSelectedFolder} | ||||||
/> | ||||||
<S.AddFolderBtn onClick={() => setIsOpenModal(true)}> | ||||||
<span>폴더 추가</span> | ||||||
<S.IconAdd /> | ||||||
</S.AddFolderBtn> | ||||||
</S.MenuContainer> | ||||||
{isLoading && <Loading />} | ||||||
<S.MenuContainer> | ||||||
<S.SubTitle>{selected}</S.SubTitle> | ||||||
{selected !== "전체" && <Options selected={selected} />} | ||||||
</S.MenuContainer> | ||||||
{!isLoading && links.length === 0 ? ( | ||||||
<S.Blank>저장된 링크가 없습니다</S.Blank> | ||||||
) : ( | ||||||
<CardList links={filteredLinks} /> | ||||||
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.
Suggested change
|
||||||
)} | ||||||
</S.Contents> | ||||||
</Layout> | ||||||
</> | ||||||
); | ||||||
} |
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.
react-query가 사용되지는 않는것 같은데 추가하신 이유가 있을까요?