From b479210aca3f985efeccd215c6d21d0d2bf5f873 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 21 Nov 2022 13:24:42 -0500 Subject: [PATCH] Update badges again --- src/hooks/inventory/useInventoryBadges.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/hooks/inventory/useInventoryBadges.ts b/src/hooks/inventory/useInventoryBadges.ts index 80d775d0..cf5f3ec5 100644 --- a/src/hooks/inventory/useInventoryBadges.ts +++ b/src/hooks/inventory/useInventoryBadges.ts @@ -61,13 +61,26 @@ const useInventoryBadgesState = () => useMessageEvent(BadgesEvent, event => { const parser = event.getParser(); - const newBadgeCodes = parser.getAllBadgeCodes(); - const newBadgeIds: number[] = []; + const badgesToAdd: string[] = []; - for(const newBadgeCode of newBadgeCodes) newBadgeIds.push(parser.getBadgeId(newBadgeCode)); + setBadgeIds(prevValue => + { + const newValue = [ ...prevValue ]; - setBadgeCodes(prevValue => [ ...prevValue, ...newBadgeCodes ]); - setBadgeIds(prevValue => [ ...prevValue, ...newBadgeIds ]); + parser.getAllBadgeCodes().forEach(code => + { + 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()); });