Fix RaidCombobox not switching to raid's section

The RaidCombobox should always open to the section that contains the current raid, or the middle section if there is no raid selected. There was some spaghetti code, but this should fix it.
This commit is contained in:
Justin Edmund 2023-07-04 01:51:50 -07:00
parent fd50258f99
commit eaf863584d

View file

@ -115,29 +115,13 @@ const RaidCombobox = (props: Props) => {
sortGroups(appState.raidGroups) sortGroups(appState.raidGroups)
}, []) }, [])
// Set current raid and section when the component mounts // Set current section when the current raid changes
useEffect(() => {
// if (appState.party.raid) {
// setCurrentRaid(appState.party.raid)
// if (appState.party.raid.group.section > 0) {
// setCurrentSection(appState.party.raid.group.section)
// } else {
// setCurrentSection(1)
// }
// } else if (props.showAllRaidsOption && !currentRaid) {
// setCurrentRaid(allRaidsOption)
// }
}, [])
// Set current raid and section when the current raid changes
useEffect(() => { useEffect(() => {
console.log('Raid has changed')
if (props.currentRaid) { if (props.currentRaid) {
setCurrentRaid(props.currentRaid)
if (appState.party.raid && appState.party.raid.group.section > 0)
setCurrentSection(props.currentRaid.group.section) setCurrentSection(props.currentRaid.group.section)
else setCurrentSection(1)
} else { } else {
setCurrentRaid(undefined) setCurrentSection(1)
} }
}, [props.currentRaid]) }, [props.currentRaid])