Pilot: move InfoStand event listeners to useAvatarInfoWidget owner

InfoStandWidgetUserView previously subscribed to three room-session
events (RSUBE_BADGES, USER_FIGURE, FAVOURITE_GROUP_UPDATE) and pushed
the result back to its parent via a setAvatarInfo prop, with each
handler running CloneObject(prev) before patching one field. Three
issues with that shape:

- CloneObject was deep-cloning the whole AvatarInfoUser shape blindly
  with no class-prototype awareness;
- the three listeners raced on shallow merges across the same prev
  reference in StrictMode dev;
- the subscriptions lived outside the state owner, forcing a prop
  callback barrier per event.

The subscriptions are now in useAvatarInfoWidget — the actual owner of
avatarInfo — and call three pure reducers extracted to
src/hooks/rooms/widgets/avatarInfo.reducers.ts (applyUserBadgesUpdate,
applyUserFigureUpdate, applyFavouriteGroupUpdate). Each reducer returns
the same reference when the event doesn't apply so React bail-outs work.
The clone now constructs a fresh AvatarInfoUser preserving prototype.

dedupeBadges is extracted to its own pure module under src/api/avatar/
so Vitest can cover it without pulling in the renderer.

InfoStandWidgetUserView loses the setAvatarInfo prop (parent updated)
and the CloneObject import.
This commit is contained in:
simoleo89
2026-05-11 20:37:21 +02:00
parent bb1238a5e5
commit 559d860a7b
6 changed files with 125 additions and 79 deletions
+21
View File
@@ -0,0 +1,21 @@
/**
* Strips duplicate badge codes from a server-supplied badge array,
* preserving slot indices: a duplicate is replaced by an empty string
* rather than shifted out, so badge[i] still corresponds to slot i.
*
* Empty / falsy entries are normalized to '' (some servers emit null
* inside the array for unused slots).
*/
export const dedupeBadges = (badges: ReadonlyArray<string>): string[] =>
{
const seen = new Set<string>();
return badges.map(code =>
{
if(!code || seen.has(code)) return '';
seen.add(code);
return code;
});
};
+1
View File
@@ -3,5 +3,6 @@ export * from './AvatarEditorColorSorter';
export * from './AvatarEditorPartSorter';
export * from './AvatarEditorThumbnailsHelper';
export * from './BuildPurchasableClothingFigure';
export * from './dedupeBadges';
export * from './IAvatarEditorCategory';
export * from './IAvatarEditorCategoryPartItem';