mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
useUserGroups: consolidate 4 dedup'd CatalogGroupsComposer call sites
Four independent components used to send 'new CatalogGroupsComposer()'
on mount and listen for GuildMembershipsMessageEvent:
- useCatalog (writing into catalogOptions.groups)
- CatalogLayoutGuildForumView
- CatalogGuildSelectorWidgetView
- WiredSelectorUsersGroupView
- WiredConditionActorIsGroupMemberView
Each fired its own request and re-listened independently. With four
of them mounted in the wired-tools panel during a builder session,
the same packet went out four times.
New useUserGroups() hook wraps the request/response pair with
useNitroQuery (queryKey ['nitro', 'user', 'groups'], staleTime
Infinity — guild membership is session-stable). All four consumers
now read 'const { data: groups = [] } = useUserGroups()' and React
Query dedups: one composer at the first mount, all subsequent mounts
get the cached array.
Drops 'groups' from ICatalogOptions and the corresponding listener +
prev-state-merge from useCatalog — no remaining consumer reads it.
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export * from './useGroup';
|
||||
export * from './useUserGroups';
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { CatalogGroupsComposer, GuildMembershipsMessageEvent, HabboGroupEntryData } from '@nitrots/nitro-renderer';
|
||||
import { UseQueryResult } from '@tanstack/react-query';
|
||||
import { useNitroQuery } from '../../api/nitro-query';
|
||||
|
||||
/**
|
||||
* The list of guilds the current Habbo belongs to, as returned by
|
||||
* the `CatalogGroupsComposer` → `GuildMembershipsMessageEvent`
|
||||
* request/response pair.
|
||||
*
|
||||
* Cached at session level: the membership list is stable for the
|
||||
* session unless the user joins/leaves a guild (in which case the
|
||||
* relevant flow should invalidate the `['nitro', 'user', 'groups']`
|
||||
* query key, which today nobody does — re-mounting the consumer
|
||||
* refetches via React Query's default behavior).
|
||||
*
|
||||
* Replaces three duplicate request+listener pairs that previously
|
||||
* each issued their own CatalogGroupsComposer:
|
||||
* - useCatalog (catalogOptions.groups)
|
||||
* - WiredSelectorUsersGroupView
|
||||
* - WiredConditionActorIsGroupMemberView
|
||||
*/
|
||||
export const useUserGroups = (
|
||||
options: { enabled?: boolean } = {}
|
||||
): UseQueryResult<HabboGroupEntryData[]> =>
|
||||
useNitroQuery<GuildMembershipsMessageEvent, HabboGroupEntryData[]>({
|
||||
key: [ 'nitro', 'user', 'groups' ],
|
||||
request: () => new CatalogGroupsComposer(),
|
||||
parser: GuildMembershipsMessageEvent,
|
||||
select: event => (event.getParser().groups || []),
|
||||
enabled: options.enabled,
|
||||
staleTime: Infinity
|
||||
});
|
||||
Reference in New Issue
Block a user