-
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 #496 from SeungRyeolBaek/part3
[백승렬] Week 19
- Loading branch information
Showing
38 changed files
with
777 additions
and
238 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { queryClient } from "@/src/util"; | ||
import "@/styles/reset.css"; | ||
import { QueryClientProvider } from "@tanstack/react-query"; | ||
import type { AppProps } from "next/app"; | ||
|
||
export default function App({ Component, pageProps }: AppProps) { | ||
return <Component {...pageProps} />; | ||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<Component {...pageProps} /> | ||
</QueryClientProvider> | ||
); | ||
} |
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,65 @@ | ||
import { CardList, FolderToolBar, LinkForm } from "@/src/feature"; | ||
import { Layout, SearchBar } from "@/src/ui"; | ||
import { FolderLayout } from "@/src/page-layout/FolderLayout"; | ||
import { | ||
useIntersectionObserver, | ||
useSearchLink, | ||
ALL_LINKS_ID, | ||
} from "@/src/util"; | ||
import { useGetLinks, useGetFolders } from "@/src/data-access"; | ||
import { ROUTE } from "@/src/util"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect, useMemo } from "react"; | ||
|
||
const FolderPage = () => { | ||
const router = useRouter(); | ||
const { folderId } = router.query; | ||
const currentFolderId = useMemo(() => { | ||
if (router.isReady) { | ||
return folderId?.[0] ? parseInt(folderId?.[0]) : ALL_LINKS_ID; | ||
} | ||
return undefined; | ||
}, [router.isReady, folderId]); | ||
const { data: folders } = useGetFolders(); | ||
const { data: links, loading } = useGetLinks(currentFolderId); | ||
const { searchValue, handleChange, handleCloseClick, result } = | ||
useSearchLink(links); | ||
const { ref, isIntersecting } = useIntersectionObserver<HTMLDivElement>(); | ||
|
||
useEffect(() => { | ||
const accessToken = localStorage.getItem("accessToken"); | ||
if (!accessToken) { | ||
router.replace(ROUTE.로그인); | ||
} | ||
}, [router]); | ||
|
||
return ( | ||
<Layout isSticky={false} footerRef={ref}> | ||
<FolderLayout | ||
linkForm={ | ||
<LinkForm | ||
hideFixedLinkForm={isIntersecting} | ||
currentFolderId={currentFolderId} | ||
/> | ||
} | ||
searchBar={ | ||
<SearchBar | ||
value={searchValue} | ||
onChange={handleChange} | ||
onCloseClick={handleCloseClick} | ||
/> | ||
} | ||
folderToolBar={ | ||
<FolderToolBar folders={folders} selectedFolderId={currentFolderId} /> | ||
} | ||
cardList={ | ||
loading ? null : ( | ||
<CardList links={result} currentFolderId={currentFolderId} /> | ||
) | ||
} | ||
/> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default FolderPage; |
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
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,23 @@ | ||
import { instance } from "../util"; | ||
import { FolderRawData } from "../type"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useGetFolders } from "."; | ||
|
||
type Params = { name: string }; | ||
|
||
export const useAddFolder = () => { | ||
const { refetch } = useGetFolders(); | ||
const addFolder = ({ name }: Params) => | ||
instance.post<FolderRawData[]>("/folders", { | ||
name, | ||
}); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["addFolder"], | ||
mutationFn: addFolder, | ||
onSuccess: () => refetch(), | ||
retry: false, | ||
}); | ||
|
||
return { mutate }; | ||
}; |
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,28 @@ | ||
import { instance } from "../util"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useGetLinks, useGetFolders } from "."; | ||
import { LinkRawData, SelectedFolderId } from "../type"; | ||
|
||
type Params = { url: string; folderId: number }; | ||
|
||
export const useAddLink = (folderId?: SelectedFolderId) => { | ||
const { refetch: getLinks } = useGetLinks(folderId); | ||
const { refetch: getFolders } = useGetFolders(); | ||
const addLink = ({ url, folderId }: Params) => | ||
instance.post<LinkRawData[]>("/links", { | ||
url, | ||
folderId, | ||
}); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["addLink"], | ||
mutationFn: addLink, | ||
onSuccess: () => { | ||
getLinks(); | ||
getFolders(); | ||
}, | ||
retry: false, | ||
}); | ||
|
||
return { mutate }; | ||
}; |
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,21 @@ | ||
import { instance } from "../util"; | ||
import { FolderRawData } from "../type"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useGetFolders } from "."; | ||
|
||
type Params = { folderId: number }; | ||
|
||
export const useDeleteFolder = () => { | ||
const { refetch } = useGetFolders(); | ||
const deleteFolder = ({ folderId }: Params) => | ||
instance.delete<FolderRawData[]>(`/folders/${folderId}`); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["deleteFolder"], | ||
mutationFn: deleteFolder, | ||
onSuccess: () => refetch(), | ||
retry: false, | ||
}); | ||
|
||
return { mutate }; | ||
}; |
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,26 @@ | ||
import { instance, queryClient } from "../util" | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useGetLinks, useGetFolders } from "."; | ||
import { LinkRawData, SelectedFolderId } from "../type"; | ||
|
||
type Params = { linkId: number }; | ||
|
||
export const useDeleteLink = (folderId?: SelectedFolderId) => { | ||
const { refetch: getLinks } = useGetLinks(folderId); | ||
const { refetch: getFolders } = useGetFolders(); | ||
const deleteLink = ({ linkId }: Params) => | ||
instance.delete<LinkRawData[]>(`/links/${linkId}`); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["deleteLink"], | ||
mutationFn: deleteLink, | ||
onSuccess: () => { | ||
getLinks(); | ||
getFolders(); | ||
queryClient.invalidateQueries({ queryKey: ["getLinks", folderId] }); | ||
}, | ||
retry: false, | ||
}); | ||
|
||
return { mutate }; | ||
}; |
Oops, something went wrong.