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,
|
||||
CollectionSummonInput,
|
||||
CollectionJobAccessoryInput,
|
||||
CollectionFilters
|
||||
CollectionFilters,
|
||||
CollectionCounts
|
||||
} from '$lib/types/api/collection'
|
||||
|
||||
/**
|
||||
|
|
@ -51,6 +52,19 @@ export class CollectionAdapter extends BaseAdapter {
|
|||
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
|
||||
// ============================================
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ import type {
|
|||
CollectionCharacter,
|
||||
CollectionWeapon,
|
||||
CollectionSummon,
|
||||
CollectionFilters
|
||||
CollectionFilters,
|
||||
CollectionCounts
|
||||
} from '$lib/types/api/collection'
|
||||
|
||||
/**
|
||||
|
|
@ -51,6 +52,22 @@ export interface CollectionInitialData<T> {
|
|||
* ```
|
||||
*/
|
||||
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
|
||||
* Works for any user - privacy is enforced server-side
|
||||
|
|
@ -227,6 +244,7 @@ export const collectionQueries = {
|
|||
*/
|
||||
export const collectionKeys = {
|
||||
all: ['collection'] as const,
|
||||
counts: (userId: string) => [...collectionKeys.all, 'counts', userId] as const,
|
||||
characters: (userId?: string) =>
|
||||
userId
|
||||
? ([...collectionKeys.all, 'characters', userId] as const)
|
||||
|
|
|
|||
|
|
@ -178,3 +178,13 @@ export enum CollectionPrivacy {
|
|||
CrewOnly = 1,
|
||||
Private = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection counts response
|
||||
*/
|
||||
export interface CollectionCounts {
|
||||
characters: number
|
||||
weapons: number
|
||||
summons: number
|
||||
artifacts: number
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue