-
Notifications
You must be signed in to change notification settings - Fork 0
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 #376 from oduck-team/refactor/375
refactor: 프로필 페이지 코드 리팩토링
- Loading branch information
Showing
56 changed files
with
1,167 additions
and
902 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
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,40 @@ | ||
import { AxiosError } from "axios"; | ||
|
||
import useToast from "@/components/Toast/useToast"; | ||
import useToggleBookmark from "@/features/bookmarks/hooks/useToggleBookmark"; | ||
import useDebounce from "@/hooks/useDebounce"; | ||
import { useCommonToastError } from "@/libs/error"; | ||
|
||
export default function useBookmarkDelete(animeId: number, title: string) { | ||
const { toastAuthError, toastDefaultError } = useCommonToastError(); | ||
const toast = useToast(); | ||
const deleteBookmark = useToggleBookmark(animeId); | ||
|
||
const handleDeleteButtonClick = useDebounce(() => { | ||
deleteBookmark.mutate(undefined, { | ||
onSuccess: () => { | ||
toast.success({ | ||
message: `${title} 탈덕 했어요.`, | ||
buttonText: "탈덕 취소하기", | ||
onClickButton: () => deleteBookmark.mutate(), | ||
duration: 4, | ||
}); | ||
}, | ||
onError: (error) => { | ||
if (error instanceof AxiosError && error.response?.status) { | ||
const status = error.response.status; | ||
switch (status) { | ||
case 401: | ||
toastAuthError(); | ||
break; | ||
default: | ||
toastDefaultError(); | ||
break; | ||
} | ||
} | ||
}, | ||
}); | ||
}, 200); | ||
|
||
return { handleDeleteButtonClick }; | ||
} |
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,16 @@ | ||
import { useMemo, useState } from "react"; | ||
|
||
export default function useCroppedImage(): [ | ||
File | null, | ||
React.Dispatch<React.SetStateAction<File | null>>, | ||
string | null, | ||
] { | ||
const [croppedImage, setCroppedImage] = useState<File | null>(null); | ||
|
||
const previewImage = useMemo( | ||
() => croppedImage && URL.createObjectURL(croppedImage), | ||
[croppedImage], | ||
); | ||
|
||
return [croppedImage, setCroppedImage, previewImage]; | ||
} |
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,14 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import useAuth from "@/features/auth/hooks/useAuth"; | ||
import { useApi } from "@/hooks/useApi"; | ||
|
||
export default function useFetchEditProfil() { | ||
const { user } = useAuth(); | ||
const { profile } = useApi(); | ||
const query = useQuery(["profile", "edit", user?.name], () => | ||
profile.getProfile(user?.name), | ||
); | ||
|
||
return query; | ||
} |
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 { useInfiniteQuery } from "@tanstack/react-query"; | ||
|
||
import { useApi } from "@/hooks/useApi"; | ||
|
||
import { SelectedSort } from "./useSortBar"; | ||
import { MENU } from "./useTabMenu"; | ||
|
||
export default function useFetchInfiniteBookmark( | ||
memberId: number, | ||
selectedSort: SelectedSort, | ||
selectedMenu: MENU, | ||
) { | ||
const { profile } = useApi(); | ||
const query = useInfiniteQuery( | ||
["profile", memberId, "bookmark", selectedSort.id, selectedSort.isDESC], | ||
({ pageParam }) => profile.getBookmark(memberId, pageParam, selectedSort), | ||
{ | ||
getNextPageParam: (lastPage) => lastPage.cursor || undefined, | ||
select: (data) => ({ | ||
pages: data.pages.flatMap((page) => page.items), | ||
pageParams: data.pageParams, | ||
}), | ||
enabled: selectedMenu === "입덕애니", | ||
}, | ||
); | ||
|
||
return query; | ||
} |
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 { useInfiniteQuery } from "@tanstack/react-query"; | ||
|
||
import { useApi } from "@/hooks/useApi"; | ||
|
||
import { SelectedSort } from "./useSortBar"; | ||
import { MENU } from "./useTabMenu"; | ||
|
||
export default function useFetchInfiniteReview( | ||
memberId: number, | ||
selectedSort: SelectedSort, | ||
selectedMenu: MENU, | ||
) { | ||
const { profile } = useApi(); | ||
const query = useInfiniteQuery( | ||
["profile", memberId, "review", selectedSort.id, selectedSort.isDESC], | ||
({ pageParam }) => profile.getReview(memberId, pageParam, selectedSort), | ||
{ | ||
getNextPageParam: (lastPage) => lastPage.cursor || undefined, | ||
select: (data) => ({ | ||
pages: data.pages.flatMap((page) => page.items), | ||
pageParams: data.pageParams, | ||
}), | ||
enabled: selectedMenu === "한줄리뷰", | ||
}, | ||
); | ||
|
||
return query; | ||
} |
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,18 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
import useAuth from "@/features/auth/hooks/useAuth"; | ||
import { useApi } from "@/hooks/useApi"; | ||
|
||
export default function useFetchProfile() { | ||
const { user } = useAuth(); | ||
const params = useParams(); | ||
const { profile } = useApi(); | ||
const query = useQuery( | ||
["profile", params.name || user?.name], | ||
() => profile.getProfile(params.name || user?.name), | ||
{ enabled: !!params.name || !!user?.name }, | ||
); | ||
|
||
return query; | ||
} |
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 { useQuery } from "@tanstack/react-query"; | ||
|
||
import { useApi } from "@/hooks/useApi"; | ||
|
||
import { MENU } from "./useTabMenu"; | ||
|
||
export default function useFetchTabListCount( | ||
memberId: number, | ||
selectedMenu: MENU, | ||
) { | ||
const { profile } = useApi(); | ||
const query = useQuery({ | ||
queryKey: [ | ||
"profile", | ||
memberId, | ||
"count", | ||
selectedMenu === "입덕애니" ? "bookmark" : "review", | ||
], | ||
queryFn: () => profile.getTabListCount(memberId, selectedMenu), | ||
}); | ||
|
||
return query; | ||
} |
Oops, something went wrong.