Another attempt to fix RaidCombobox loading (#338)

This commit is contained in:
Justin Edmund 2023-07-04 02:05:55 -07:00 committed by GitHub
parent a820e5ad5f
commit e2effa0d66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<HTMLButtonElement>
) => {