mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-20 23:33:50 +02:00
add @tanstack/query
This commit is contained in:
55
src/query/useEntityQueries.js
Normal file
55
src/query/useEntityQueries.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
|
||||
import { avatarRequest, groupRequest, instanceRequest, userRequest, worldRequest } from '../api';
|
||||
import { queryKeys } from './keys';
|
||||
import { entityQueryPolicies, toQueryOptions } from './policies';
|
||||
|
||||
export function useUserQuery(userId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.user(userId),
|
||||
queryFn: () => userRequest.getUser({ userId }),
|
||||
enabled: Boolean(userId),
|
||||
...toQueryOptions(entityQueryPolicies.user)
|
||||
});
|
||||
}
|
||||
|
||||
export function useAvatarQuery(avatarId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.avatar(avatarId),
|
||||
queryFn: () => avatarRequest.getAvatar({ avatarId }),
|
||||
enabled: Boolean(avatarId),
|
||||
...toQueryOptions(entityQueryPolicies.avatar)
|
||||
});
|
||||
}
|
||||
|
||||
export function useWorldQuery(worldId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.world(worldId),
|
||||
queryFn: () => worldRequest.getWorld({ worldId }),
|
||||
enabled: Boolean(worldId),
|
||||
...toQueryOptions(entityQueryPolicies.world)
|
||||
});
|
||||
}
|
||||
|
||||
export function useGroupQuery(groupId, includeRoles = false, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.group(groupId, includeRoles),
|
||||
queryFn: () => groupRequest.getGroup({ groupId, includeRoles }),
|
||||
enabled: Boolean(groupId),
|
||||
...toQueryOptions(entityQueryPolicies.group)
|
||||
});
|
||||
}
|
||||
|
||||
export function useInstanceQuery(worldId, instanceId, options = {}) {
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: queryKeys.instance(worldId, instanceId),
|
||||
queryFn: () => instanceRequest.getInstance({ worldId, instanceId }),
|
||||
enabled: Boolean(worldId && instanceId),
|
||||
...toQueryOptions(entityQueryPolicies.instance)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user