From e2effa0d6661fe4e4d0af9fa188f71d9719ef33b Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 4 Jul 2023 02:05:55 -0700 Subject: [PATCH] Another attempt to fix RaidCombobox loading (#338) --- components/raids/RaidCombobox/index.tsx | 33 ++++++++++--------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/components/raids/RaidCombobox/index.tsx b/components/raids/RaidCombobox/index.tsx index 3de4b900..382e2938 100644 --- a/components/raids/RaidCombobox/index.tsx +++ b/components/raids/RaidCombobox/index.tsx @@ -112,15 +112,26 @@ const RaidCombobox = (props: Props) => { // Fetch all raids on mount useEffect(() => { - sortGroups(appState.raidGroups) + const sections: [RaidGroup[], RaidGroup[], RaidGroup[]] = [[], [], []] + + appState.raidGroups.forEach((group) => { + if (group.section > 0) sections[group.section - 1].push(group) + }) + + if (appState.raidGroups[0]) { + setFarmingRaid(appState.raidGroups[0].raids[0]) + } + + setSections(sections) }, []) // Set current section when the current raid changes useEffect(() => { - console.log('Raid has changed') if (props.currentRaid) { + setCurrentRaid(props.currentRaid) setCurrentSection(props.currentRaid.group.section) } else { + setCurrentRaid(undefined) setCurrentSection(1) } }, [props.currentRaid]) @@ -201,24 +212,6 @@ const RaidCombobox = (props: Props) => { else setSort(Sort.ASCENDING) } - // Sorts the raid groups into sections - const sortGroups = useCallback( - (groups: RaidGroup[]) => { - const sections: [RaidGroup[], RaidGroup[], RaidGroup[]] = [[], [], []] - - groups.forEach((group) => { - if (group.section > 0) sections[group.section - 1].push(group) - }) - - if (groups[0]) { - setFarmingRaid(groups[0].raids[0]) - } - - setSections(sections) - }, - [setSections] - ) - const handleSortButtonKeyDown = ( event: React.KeyboardEvent ) => {