diff --git a/src/hooks/api/auth/queryKeyFactories.ts b/src/hooks/api/auth/queryKeyFactories.ts index 9ca1732..3b6e8ee 100644 --- a/src/hooks/api/auth/queryKeyFactories.ts +++ b/src/hooks/api/auth/queryKeyFactories.ts @@ -1,13 +1,15 @@ import { queryOptions } from "@tanstack/react-query"; import { getUserInformation } from "@/apis/auth"; -export const authQueries = { - all: ["auth"] as const, - userInformationKey: () => [...authQueries.all, "userInfomation"] as const, - getUserInformation: (refreshToken: string) => +const authQueries = { + all: () => ["auth"], + usersInformation: () => [...authQueries.all(), "userInformation"], + userInformation: (refreshToken: string) => queryOptions({ - queryKey: [...authQueries.userInformationKey()] as const, + queryKey: [...authQueries.usersInformation(), refreshToken], queryFn: getUserInformation, enabled: !!refreshToken, }), }; + +export default authQueries; diff --git a/src/hooks/api/chat/queryKeyFactories.ts b/src/hooks/api/chat/queryKeyFactories.ts index b8b5d84..6bc7e1f 100644 --- a/src/hooks/api/chat/queryKeyFactories.ts +++ b/src/hooks/api/chat/queryKeyFactories.ts @@ -1,12 +1,11 @@ import { infiniteQueryOptions } from "@tanstack/react-query"; import { getChat } from "@/apis/chat"; -export const chatQueries = { - all: ["chat"] as const, - chatListKey: () => [...chatQueries.all, "chatList"] as const, - getChatList: () => +const chatQueries = { + all: () => ["chat"], + messages: () => infiniteQueryOptions({ - queryKey: [...chatQueries.chatListKey()] as const, + queryKey: [...chatQueries.all(), "message"], queryFn: async ({ pageParam = 0 }) => await getChat(pageParam), getNextPageParam: (lastPage, _allPages, lastPageParam) => { if (lastPage.length === 0) return; @@ -22,3 +21,5 @@ export const chatQueries = { refetchOnMount: false, }), }; + +export default chatQueries; diff --git a/src/hooks/api/report/queryKeyFactories.ts b/src/hooks/api/report/queryKeyFactories.ts index 7b475d3..d2e6746 100644 --- a/src/hooks/api/report/queryKeyFactories.ts +++ b/src/hooks/api/report/queryKeyFactories.ts @@ -1,12 +1,11 @@ import { infiniteQueryOptions, queryOptions } from "@tanstack/react-query"; import { getReportDetails, getReports } from "@/apis/report"; -export const reportQueries = { - all: ["report"] as const, - reportListKey: () => [...reportQueries.all, "reportList"] as const, - getReportList: () => +const reportQueries = { + all: () => ["report"], + reports: () => infiniteQueryOptions({ - queryKey: [...reportQueries.reportListKey()] as const, + queryKey: [...reportQueries.all(), "list"], queryFn: ({ pageParam = 0 }) => getReports(pageParam), getNextPageParam: (lastPage, _allPages, lastPageParam) => { if (!lastPage) return; @@ -15,10 +14,11 @@ export const reportQueries = { }, initialPageParam: 0, }), - reportDetailKey: () => [...reportQueries.all, "reportDetail"] as const, - getReportDetail: (imageId: string) => + report: (imageId: string) => queryOptions({ - queryKey: [...reportQueries.reportDetailKey(), imageId], + queryKey: [...reportQueries.reports().queryKey, imageId], queryFn: () => getReportDetails(imageId), }), }; + +export default reportQueries; diff --git a/src/hooks/api/tag/queryKeyFactories.ts b/src/hooks/api/tag/queryKeyFactories.ts index 29bce9c..fd49f32 100644 --- a/src/hooks/api/tag/queryKeyFactories.ts +++ b/src/hooks/api/tag/queryKeyFactories.ts @@ -7,40 +7,39 @@ import { getTopTagsFromUploaded, } from "@/apis/tag"; -export const tagQueries = { - all: ["tag"] as const, - tagListKey: () => [...tagQueries.all, "tagList"] as const, - getTagList: (tag: string) => { +const tagQueries = { + all: () => ["tags"], + searchResults: () => [...tagQueries.all(), "search"], + searchResult: (tag: string) => { const MAX_TAG_RESPONSE_COUNT = 10; return queryOptions({ - queryKey: [...tagQueries.tagListKey(), tag] as const, + queryKey: [...tagQueries.searchResults(), tag], queryFn: () => getSearchTag(tag), select: (tags) => tags.filter((_tag, index) => index < MAX_TAG_RESPONSE_COUNT), }); }, - popularTagsKey: () => [...tagQueries.all, "popularTags"] as const, - getPopularTags: () => + popularTags: () => queryOptions({ - queryKey: [...tagQueries.popularTagsKey()] as const, + queryKey: [...tagQueries.all(), "popularTags"], queryFn: getPopularTags, }), - topTagsFromHomeKey: () => [...tagQueries.all, "topTagsFromHome"] as const, - getTopTagsFromHome: () => + topTags: () => [...tagQueries.all(), "topTags"], + topTagsFromHome: () => queryOptions({ - queryKey: [...tagQueries.topTagsFromHomeKey()] as const, + queryKey: [...tagQueries.topTags(), "home"], queryFn: getTopTagsFromHome, }), - topTagsFromLikedKey: () => [...tagQueries.all, "topTagsFromLiked"] as const, - getTopTagsFromLiked: () => + topTagsFromLiked: () => queryOptions({ - queryKey: [...tagQueries.topTagsFromLikedKey()] as const, + queryKey: [...tagQueries.topTags(), "liked"], queryFn: getTopTagsFromLiked, }), - topTagsFromUploadedKey: () => [...tagQueries.all, "topTagsFromUploaded"] as const, - getTopTagsFromUploaded: () => + topTagsFromUploaded: () => queryOptions({ - queryKey: [...tagQueries.topTagsFromUploadedKey()] as const, + queryKey: [...tagQueries.topTags(), "uploaded"], queryFn: getTopTagsFromUploaded, }), }; + +export default tagQueries; diff --git a/src/hooks/api/zzal/queryKeyFactories.ts b/src/hooks/api/zzal/queryKeyFactories.ts index 2d9a652..3519a94 100644 --- a/src/hooks/api/zzal/queryKeyFactories.ts +++ b/src/hooks/api/zzal/queryKeyFactories.ts @@ -1,12 +1,12 @@ import { infiniteQueryOptions, queryOptions } from "@tanstack/react-query"; import { getHomeZzals, getMyLikedZzals, getMyUploadedZzals, getZzalDetails } from "@/apis/zzal"; -export const zzalQueries = { - all: ["zzal"] as const, - zzalDetailKey: () => [...zzalQueries.all, "zzalDetails"] as const, - getZzalDetail: (imageId: number) => +const zzalQueries = { + all: () => ["zzal"], + details: () => [...zzalQueries.all(), "detail"], + detail: (imageId: number) => queryOptions({ - queryKey: [...zzalQueries.zzalDetailKey(), imageId] as const, + queryKey: [...zzalQueries.details(), imageId], queryFn: () => getZzalDetails(imageId), select: (data) => ({ isLiked: data.imageLikeYn, @@ -15,10 +15,10 @@ export const zzalQueries = { ...data, }), }), - homeZzalsKey: () => [...zzalQueries.all, "homeZzals"] as const, - getHomeZzals: (selectedTags: string[]) => + homeZzals: () => [...zzalQueries.all(), "home"], + selectedHomeZzals: (selectedTags: string[]) => infiniteQueryOptions({ - queryKey: [...zzalQueries.homeZzalsKey(), selectedTags] as const, + queryKey: [...zzalQueries.homeZzals(), selectedTags], queryFn: ({ pageParam = 0 }) => getHomeZzals({ page: pageParam, selectedTags }), getNextPageParam: (lastPage, _allPages, lastPageParam) => { if (!lastPage) return; @@ -27,10 +27,10 @@ export const zzalQueries = { }, initialPageParam: 0, }), - myLikedZzalsKey: () => [...zzalQueries.all, "likedZzals"] as const, - getMyLikedZzals: (selectedTags: string[]) => + myLikedZzals: () => [...zzalQueries.all(), "liked"], + selectedMyLikedZzals: (selectedTags: string[]) => infiniteQueryOptions({ - queryKey: [...zzalQueries.myLikedZzalsKey(), selectedTags] as const, + queryKey: [...zzalQueries.myLikedZzals(), selectedTags], queryFn: ({ pageParam = 0 }) => getMyLikedZzals({ page: pageParam, selectedTags }), getNextPageParam: (lastPage, _allPages, lastPageParam) => { if (!lastPage) return; @@ -39,10 +39,10 @@ export const zzalQueries = { }, initialPageParam: 0, }), - myUploadedZzalsKey: () => [...zzalQueries.all, "uploadedZzals"] as const, - getMyUploadedZzals: (selectedTags: string[]) => + myUploadedZzals: () => [...zzalQueries.all(), "uploaded"], + selectedMyUploadedZzals: (selectedTags: string[]) => infiniteQueryOptions({ - queryKey: [...zzalQueries.myUploadedZzalsKey(), selectedTags] as const, + queryKey: [...zzalQueries.myUploadedZzals(), selectedTags], queryFn: ({ pageParam = 0 }) => getMyUploadedZzals({ page: pageParam, selectedTags }), getNextPageParam: (lastPage, _allPages, lastPageParam) => { if (!lastPage) return; @@ -52,3 +52,5 @@ export const zzalQueries = { initialPageParam: 0, }), }; + +export default zzalQueries;