-
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.
- Loading branch information
Showing
314 changed files
with
1,198 additions
and
1,545 deletions.
There are no files selected for viewing
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,2 @@ | ||
export * from "./useGetMyAccount"; | ||
export * from "./useLogout"; |
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,19 @@ | ||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { api } from "../core"; | ||
|
||
export const useGetMyAccount = () => { | ||
const queryClient = useQueryClient(); | ||
return useQuery({ | ||
suspense: false, | ||
queryKey: useGetMyAccount.queryKey, | ||
queryFn: useGetMyAccount.queryFn, | ||
onError: () => { | ||
queryClient.setQueryData(useGetMyAccount.queryKey, null); | ||
}, | ||
}); | ||
}; | ||
|
||
useGetMyAccount.queryKey = ["getMyAccount"] as const; | ||
|
||
useGetMyAccount.queryFn = () => api.account.getMyAccount(); |
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,15 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { api } from "../core"; | ||
import { useGetMyAccount } from "./useGetMyAccount"; | ||
|
||
export const useLogout = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(api.auth.logout, { | ||
onSuccess: () => { | ||
api.auth.deleteAccessToken(); | ||
queryClient.setQueryData(useGetMyAccount.queryKey, null); | ||
}, | ||
}); | ||
}; |
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,4 @@ | ||
export * from "./useDeleteMemeFromCollection"; | ||
export * from "./useGetCollectionCheck"; | ||
export * from "./usePostMemeToCollection"; | ||
export * from "./usePostMemeToSharedCollection"; |
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 { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { useGetMyAccount } from "../account"; | ||
import { api } from "../core"; | ||
import { useGetCollectionCheck } from "./useGetCollectionCheck"; | ||
/** | ||
* 콜렉션 삭제 API | ||
*/ | ||
export const useDeleteMemeFromCollection = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: api.collection.deleteMemeFromCollection, | ||
onMutate: async (deletedMemeId) => { | ||
await queryClient.cancelQueries({ | ||
queryKey: useGetCollectionCheck.queryKey(deletedMemeId), | ||
}); | ||
|
||
const previousCollectionInfo = queryClient.getQueryData( | ||
useGetCollectionCheck.queryKey(deletedMemeId), | ||
); | ||
|
||
queryClient.setQueryData(useGetCollectionCheck.queryKey(deletedMemeId), { | ||
collectionId: null, | ||
isAdded: false, | ||
}); | ||
|
||
return { previousCollectionInfo, deletedMemeId }; | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: useGetMyAccount.queryKey }); | ||
}, | ||
onError: (_, deletedMemeId, context) => { | ||
queryClient.setQueryData( | ||
useGetCollectionCheck.queryKey(deletedMemeId), | ||
context?.previousCollectionInfo, | ||
); | ||
}, | ||
}); | ||
}; |
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,29 @@ | ||
import type { QueryClient, UseQueryOptions } from "@tanstack/react-query"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { api } from "../core"; | ||
|
||
/** | ||
* 밈별 콜렉션 정보 API | ||
*/ | ||
export const useGetCollectionCheck = ( | ||
memeId: number, | ||
options?: Pick<UseQueryOptions, "enabled">, | ||
) => { | ||
return useQuery({ | ||
queryKey: useGetCollectionCheck.queryKey(memeId), | ||
queryFn: () => useGetCollectionCheck.queryFn(memeId), | ||
suspense: false, | ||
...options, | ||
}); | ||
}; | ||
|
||
useGetCollectionCheck.queryKey = (memeId: number) => ["getCollectionCheck", memeId] as const; | ||
|
||
useGetCollectionCheck.queryFn = (memeId: number) => api.collection.getCollectionCheck(memeId); | ||
|
||
useGetCollectionCheck.prefetchQuery = (memeId: number, queryClient: QueryClient) => | ||
queryClient.prefetchQuery({ | ||
queryKey: useGetCollectionCheck.queryKey(memeId), | ||
queryFn: () => useGetCollectionCheck.queryFn(memeId), | ||
}); |
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 { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { useGetMyAccount } from "../account"; | ||
import { api } from "../core"; | ||
import { useGetCollectionCheck } from "./useGetCollectionCheck"; | ||
/** | ||
* 콜렉션 저장 API | ||
*/ | ||
export const usePostMemeToCollection = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: api.collection.postMemeToCollection, | ||
onMutate: async (newMemeId) => { | ||
await queryClient.cancelQueries({ | ||
queryKey: useGetCollectionCheck.queryKey(newMemeId), | ||
}); | ||
|
||
const previousCollectionInfo = queryClient.getQueryData( | ||
useGetCollectionCheck.queryKey(newMemeId), | ||
); | ||
|
||
queryClient.setQueryData(useGetCollectionCheck.queryKey(newMemeId), { | ||
collectionId: 1, | ||
isAdded: true, | ||
}); | ||
|
||
return { previousCollectionInfo, newMemeId }; | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: useGetMyAccount.queryKey }); | ||
}, | ||
onError: (_, newMemeId, context) => { | ||
queryClient.setQueryData( | ||
useGetCollectionCheck.queryKey(newMemeId), | ||
context?.previousCollectionInfo, | ||
); | ||
}, | ||
}); | ||
}; |
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 { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { useGetMyAccount } from "../account"; | ||
import { api } from "../core"; | ||
import { useGetMemesByCollectionId } from "../meme"; | ||
|
||
export const usePostMemeToSharedCollection = ({ | ||
memeId, | ||
sharedId, | ||
}: { | ||
memeId: number; | ||
sharedId: number; | ||
}) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: () => api.collection.postMemeToSharedCollection(memeId), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: useGetMemesByCollectionId.queryKey(sharedId) }); | ||
queryClient.invalidateQueries({ queryKey: useGetMyAccount.queryKey }); | ||
}, | ||
}); | ||
}; |
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,5 @@ | ||
export * from "./axios"; | ||
export * from "./query-client"; | ||
export * from "./queryKey"; | ||
export * from "./useCoreInfiniteQuery"; | ||
export * from "./useSuspensedQuery"; |
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
File renamed without changes.
File renamed without changes.
42 changes: 35 additions & 7 deletions
42
...ation/hooks/api/core/useSuspensedQuery.ts → src/api/core/useSuspensedQuery.ts
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,3 @@ | ||
export * from "./useGetMemeDetailById"; | ||
export * from "./useGetMemesByCollectionId"; | ||
export * from "./useGetMemesBySort"; |
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,24 @@ | ||
import type { QueryClient } from "@tanstack/react-query"; | ||
|
||
import { api, useSuspendedQuery } from "../core"; | ||
|
||
/** | ||
* 밈 상세 조회 API | ||
* @param id 상세 조회할 밈 id | ||
*/ | ||
export const useGetMemeDetailById = (id: string) => { | ||
const { data, isRefetching } = useSuspendedQuery({ | ||
queryKey: useGetMemeDetailById.queryKey(id), | ||
queryFn: () => useGetMemeDetailById.queryFn(id), | ||
staleTime: Infinity, | ||
}); | ||
|
||
return { ...data, isRefetching }; | ||
}; | ||
|
||
useGetMemeDetailById.queryKey = (id: string) => ["getMemeDetailById", id] as const; | ||
|
||
useGetMemeDetailById.queryFn = (id: string) => api.meme.getMemeDetailById(id); | ||
|
||
useGetMemeDetailById.fetchQuery = (id: string, queryClient: QueryClient) => | ||
queryClient.fetchQuery(useGetMemeDetailById.queryKey(id), () => api.meme.getMemeDetailById(id)); |
Oops, something went wrong.
8ed3f06
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.
Successfully deployed to the following URLs:
thismeme-web – ./
thismeme-web-git-main-thismeme-official-s-team.vercel.app
thismeme-web-thismeme-official-s-team.vercel.app
app.thismeme.me