Update badges again

This commit is contained in:
Bill 2022-11-21 13:24:42 -05:00
parent 69e21b3e6e
commit b479210aca

View File

@ -61,13 +61,26 @@ const useInventoryBadgesState = () =>
useMessageEvent<BadgesEvent>(BadgesEvent, event => useMessageEvent<BadgesEvent>(BadgesEvent, event =>
{ {
const parser = event.getParser(); const parser = event.getParser();
const newBadgeCodes = parser.getAllBadgeCodes(); const badgesToAdd: string[] = [];
const newBadgeIds: number[] = [];
for(const newBadgeCode of newBadgeCodes) newBadgeIds.push(parser.getBadgeId(newBadgeCode)); setBadgeIds(prevValue =>
{
const newValue = [ ...prevValue ];
setBadgeCodes(prevValue => [ ...prevValue, ...newBadgeCodes ]); parser.getAllBadgeCodes().forEach(code =>
setBadgeIds(prevValue => [ ...prevValue, ...newBadgeIds ]); {
const badgeId = parser.getBadgeId(code);
if(newValue.indexOf(badgeId) >= 0) return;
newValue.push(badgeId);
badgesToAdd.push(code);
});
return newValue;
});
setBadgeCodes(prevValue => [ ...prevValue, ...badgesToAdd ]);
setActiveBadgeCodes(parser.getActiveBadgeCodes()); setActiveBadgeCodes(parser.getActiveBadgeCodes());
}); });