add collection counts query for nav tab totals
This commit is contained in:
parent
b0d359161d
commit
916a6f52cd
3 changed files with 44 additions and 2 deletions
|
|
@ -19,7 +19,8 @@ import type {
|
||||||
CollectionWeaponInput,
|
CollectionWeaponInput,
|
||||||
CollectionSummonInput,
|
CollectionSummonInput,
|
||||||
CollectionJobAccessoryInput,
|
CollectionJobAccessoryInput,
|
||||||
CollectionFilters
|
CollectionFilters,
|
||||||
|
CollectionCounts
|
||||||
} from '$lib/types/api/collection'
|
} from '$lib/types/api/collection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,6 +52,19 @@ export class CollectionAdapter extends BaseAdapter {
|
||||||
super(options)
|
super(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Collection Counts
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total counts for all collection entity types
|
||||||
|
*/
|
||||||
|
async getCounts(userId: string): Promise<CollectionCounts> {
|
||||||
|
return this.request<CollectionCounts>(`/users/${userId}/collection/counts`, {
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Collection Characters
|
// Collection Characters
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ import type {
|
||||||
CollectionCharacter,
|
CollectionCharacter,
|
||||||
CollectionWeapon,
|
CollectionWeapon,
|
||||||
CollectionSummon,
|
CollectionSummon,
|
||||||
CollectionFilters
|
CollectionFilters,
|
||||||
|
CollectionCounts
|
||||||
} from '$lib/types/api/collection'
|
} from '$lib/types/api/collection'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,6 +52,22 @@ export interface CollectionInitialData<T> {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const collectionQueries = {
|
export const collectionQueries = {
|
||||||
|
/**
|
||||||
|
* Get counts for all collection entity types
|
||||||
|
* Used to display totals in the navigation tabs
|
||||||
|
*
|
||||||
|
* @param userId - The user whose collection to fetch counts for
|
||||||
|
* @param enabled - Whether the query is enabled (default: true)
|
||||||
|
*/
|
||||||
|
counts: (userId: string, enabled: boolean = true) =>
|
||||||
|
queryOptions<CollectionCounts>({
|
||||||
|
queryKey: ['collection', 'counts', userId] as const,
|
||||||
|
queryFn: () => collectionAdapter.getCounts(userId),
|
||||||
|
enabled: !!userId && enabled,
|
||||||
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
||||||
|
gcTime: 1000 * 60 * 30 // 30 minutes
|
||||||
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User's collection characters with infinite scroll
|
* User's collection characters with infinite scroll
|
||||||
* Works for any user - privacy is enforced server-side
|
* Works for any user - privacy is enforced server-side
|
||||||
|
|
@ -227,6 +244,7 @@ export const collectionQueries = {
|
||||||
*/
|
*/
|
||||||
export const collectionKeys = {
|
export const collectionKeys = {
|
||||||
all: ['collection'] as const,
|
all: ['collection'] as const,
|
||||||
|
counts: (userId: string) => [...collectionKeys.all, 'counts', userId] as const,
|
||||||
characters: (userId?: string) =>
|
characters: (userId?: string) =>
|
||||||
userId
|
userId
|
||||||
? ([...collectionKeys.all, 'characters', userId] as const)
|
? ([...collectionKeys.all, 'characters', userId] as const)
|
||||||
|
|
|
||||||
|
|
@ -178,3 +178,13 @@ export enum CollectionPrivacy {
|
||||||
CrewOnly = 1,
|
CrewOnly = 1,
|
||||||
Private = 2
|
Private = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection counts response
|
||||||
|
*/
|
||||||
|
export interface CollectionCounts {
|
||||||
|
characters: number
|
||||||
|
weapons: number
|
||||||
|
summons: number
|
||||||
|
artifacts: number
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue