Skip to content

Commit

Permalink
[#254] Modify: query factory 수정 (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjc2021 authored Sep 2, 2024
1 parent 1715907 commit 90f4a41
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 49 deletions.
12 changes: 7 additions & 5 deletions src/hooks/api/auth/queryKeyFactories.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 6 additions & 5 deletions src/hooks/api/chat/queryKeyFactories.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,3 +21,5 @@ export const chatQueries = {
refetchOnMount: false,
}),
};

export default chatQueries;
16 changes: 8 additions & 8 deletions src/hooks/api/report/queryKeyFactories.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
33 changes: 16 additions & 17 deletions src/hooks/api/tag/queryKeyFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
30 changes: 16 additions & 14 deletions src/hooks/api/zzal/queryKeyFactories.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -52,3 +52,5 @@ export const zzalQueries = {
initialPageParam: 0,
}),
};

export default zzalQueries;

0 comments on commit 90f4a41

Please sign in to comment.