Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/111 #112

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/hooks/api/useFollowMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ export default function useFollowMutation() {
const queryClient = useQueryClient();

function onFollowSuccess(res: FollowResponse, followeeId: number) {
queryClient.setQueryData<InfiniteData<GetUsersResponse>>(
[GET_INFINITE_USERS_KEY],
queryClient.setQueriesData(
{
exact: false,
queryKey: [GET_INFINITE_USERS_KEY],
predicate: (query) => Boolean(query),
},
(oldData) => {
if (oldData === undefined) {
return undefined;
}
return infiniteDataTrasformer(
oldData,
oldData as InfiniteData<GetUsersResponse>,
(user) => (user.userId === followeeId
? { ...user, isFollow: true, relationId: res.value.relationId }
: user),
Expand All @@ -40,14 +44,18 @@ export default function useFollowMutation() {
}

function onUnfollowMutate(_: UnfollowResponse, relationId: number) {
queryClient.setQueryData<InfiniteData<GetUsersResponse>>(
[GET_INFINITE_USERS_KEY],
queryClient.setQueriesData(
{
exact: false,
queryKey: [GET_INFINITE_USERS_KEY],
predicate: (query) => Boolean(query),
},
(oldData) => {
if (oldData === undefined) {
return undefined;
}
return infiniteDataTrasformer(
oldData,
oldData as InfiniteData<GetUsersResponse>,
(user) => (user.relationId === relationId
? { ...user, isFollow: false, relationId: null }
: user),
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/api/useGetInfiniteUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const GET_INFINITE_USERS_KEY = 'getInfiniteUsers';

export default function useGetInfiniteUsers({ type, keyword }:GetUsersProps) {
const query = useInfiniteQuery(
[GET_INFINITE_USERS_KEY],
[GET_INFINITE_USERS_KEY, type, keyword],
async ({ pageParam: lastId }) => apiService.fetchGetUsers({ type, keyword, lastId }),
{
getNextPageParam: (res) => {
Expand All @@ -22,6 +22,7 @@ export default function useGetInfiniteUsers({ type, keyword }:GetUsersProps) {
return lastId;
},
enabled: keyword.length >= 2,
cacheTime: 0,
},
);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const queryClient = new QueryClient(
suspense: false,
retry: process.env.NODE_ENV === 'development' ? false : 3,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnMount: true,
},
},
},
Expand Down
Loading