This commit is contained in:
Tickbase
2025-05-18 11:55:23 +02:00
parent df815f39a8
commit 8bc4118a9d

View File

@@ -41,12 +41,21 @@ const DlcSelectionDialog = ({
const [selectAll, setSelectAll] = useState(true) const [selectAll, setSelectAll] = useState(true)
const [initialized, setInitialized] = useState(false) const [initialized, setInitialized] = useState(false)
// Reset dialog state when it opens or closes
useEffect(() => {
if (!visible) {
setInitialized(false)
setSelectedDlcs([])
setSearchQuery('')
}
}, [visible])
// Initialize selected DLCs when DLC list changes // Initialize selected DLCs when DLC list changes
useEffect(() => { useEffect(() => {
if (dlcs.length > 0) { if (dlcs.length > 0) {
if (!initialized) { if (!initialized) {
// Initial setup - preserve the enabled state from incoming DLCs // Create a new array to ensure we don't share references
setSelectedDlcs(dlcs) setSelectedDlcs([...dlcs])
// Determine initial selectAll state based on if all DLCs are enabled // Determine initial selectAll state based on if all DLCs are enabled
const allSelected = dlcs.every((dlc) => dlc.enabled) const allSelected = dlcs.every((dlc) => dlc.enabled)
@@ -111,15 +120,6 @@ const DlcSelectionDialog = ({
onConfirm(selectedDlcs) onConfirm(selectedDlcs)
}, [onConfirm, selectedDlcs]) }, [onConfirm, selectedDlcs])
// Reset dialog state when it opens or closes
useEffect(() => {
if (!visible) {
setInitialized(false)
setSelectedDlcs([])
setSearchQuery('')
}
}, [visible])
// Count selected DLCs // Count selected DLCs
const selectedCount = selectedDlcs.filter((dlc) => dlc.enabled).length const selectedCount = selectedDlcs.filter((dlc) => dlc.enabled).length
@@ -218,7 +218,7 @@ const DlcSelectionDialog = ({
<Button <Button
variant="secondary" variant="secondary"
onClick={onClose} onClick={onClose}
disabled={isLoading && loadingProgress < 10} // Briefly disable to prevent accidental closing at start disabled={isLoading && loadingProgress < 10}
> >
Cancel Cancel
</Button> </Button>