mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-23 00:33:50 +02:00
refactor queryRequest
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { useFavoriteStore, useUserStore } from '../stores';
|
||||
import { queryClient } from '../queries';
|
||||
import { request } from '../service/request';
|
||||
import {
|
||||
entityQueryPolicies,
|
||||
fetchWithEntityPolicy,
|
||||
queryClient,
|
||||
queryKeys
|
||||
} from '../queries';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getCurrentUserId() {
|
||||
return useUserStore().currentUser.id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function refetchActiveFavoriteQueries() {
|
||||
queryClient
|
||||
.invalidateQueries({
|
||||
@@ -34,17 +35,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteLimits() {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteLimits(),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteLimits()
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').GetFavorites}
|
||||
*/
|
||||
@@ -61,17 +51,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavorites(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favorites(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavorites(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').AddFavorite}
|
||||
*/
|
||||
@@ -92,7 +71,7 @@ const favoriteReq = {
|
||||
|
||||
/**
|
||||
* @param {{ objectId: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
deleteFavorite(params) {
|
||||
return request(`favorites/${params.objectId}`, {
|
||||
@@ -110,7 +89,7 @@ const favoriteReq = {
|
||||
|
||||
/**
|
||||
* @param {{ n: number, offset: number, type: string }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
getFavoriteGroups(params) {
|
||||
return request('favorite/groups', {
|
||||
@@ -125,21 +104,10 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteGroups(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteGroups(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteGroups(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{ type: string, group: string, displayName?: string, visibility?: string }} params group is a name
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
saveFavoriteGroup(params) {
|
||||
return request(
|
||||
@@ -163,7 +131,7 @@ const favoriteReq = {
|
||||
* type: string,
|
||||
* group: string
|
||||
* }} params
|
||||
* @return { Promise<{json: any, params}> }
|
||||
* @returns { Promise<{json: any, params}> }
|
||||
*/
|
||||
clearFavoriteGroup(params) {
|
||||
return request(
|
||||
@@ -199,17 +167,6 @@ const favoriteReq = {
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteWorlds(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteWorlds(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteWorlds(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* @type {import('../types/api/favorite').GetFavoriteAvatars}
|
||||
*/
|
||||
@@ -224,17 +181,6 @@ const favoriteReq = {
|
||||
};
|
||||
return args;
|
||||
});
|
||||
},
|
||||
|
||||
getCachedFavoriteAvatars(params) {
|
||||
return fetchWithEntityPolicy({
|
||||
queryKey: queryKeys.favoriteAvatars(params),
|
||||
policy: entityQueryPolicies.favoriteCollection,
|
||||
queryFn: () => favoriteReq.getFavoriteAvatars(params)
|
||||
}).then(({ data, cache }) => ({
|
||||
...data,
|
||||
cache
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user