refactor queryRequest

This commit is contained in:
pa
2026-03-09 21:28:45 +09:00
parent c1a35223d4
commit 58b9bdc1c5
60 changed files with 1134 additions and 883 deletions

View File

@@ -1,12 +1,10 @@
import { queryClient } from '../queries';
import { request } from '../service/request';
import { useUserStore } from '../stores/user';
import {
entityQueryPolicies,
fetchWithEntityPolicy,
queryClient,
queryKeys
} from '../queries';
/**
*
*/
function refetchActiveFriendListQueries() {
queryClient
.invalidateQueries({
@@ -44,22 +42,6 @@ const friendReq = {
});
},
/**
* Fetch friends from query cache if still fresh. Otherwise, calls API.
* @param {{ n: number, offset: number, offline?: boolean }} params
* @returns {Promise<{json: any, params: { n: number, offset: number, offline?: boolean }, cache?: boolean}>}
*/
getCachedFriends(params) {
return fetchWithEntityPolicy({
queryKey: queryKeys.friends(params),
policy: entityQueryPolicies.friendList,
queryFn: () => friendReq.getFriends(params)
}).then(({ data, cache }) => ({
...data,
cache
}));
},
/**
* @param {{ userId: string }} params
* @returns {Promise<{json: any, params: { userId: string }}>}
@@ -96,6 +78,7 @@ const friendReq = {
/**
* @param {{ userId: string }} params
* @param customMsg
* @returns {Promise<{json: any, params: { userId: string }}>}
*/
deleteFriend(params, customMsg) {