From f1a8b9daee81657ee75d5caae84d1c82faf75220 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 18 Jun 2023 18:47:59 +1000 Subject: [PATCH] fix(ui): clarify scheduler logic - use full conditional syntax with `{}` - do not mutate `action.payload` in a reducer --- .../components/Parameters/Core/ParamScheduler.tsx | 7 +++++-- .../frontend/web/src/features/ui/store/uiSlice.ts | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx b/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx index 0a343d0742..1fed60fa74 100644 --- a/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx +++ b/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx @@ -24,14 +24,17 @@ const ParamScheduler = () => { const { t } = useTranslation(); useEffect(() => { - if (selectedSchedulers.length === 0) + if (selectedSchedulers.length === 0) { dispatch(setSelectedSchedulers([...SCHEDULER_ITEMS])); + } const schedulerFound = activeSchedulers.find( (activeSchedulers) => activeSchedulers.value === scheduler ); - if (!schedulerFound) + + if (!schedulerFound) { dispatch(setScheduler(activeSchedulers[0].value as Scheduler)); + } }, [dispatch, selectedSchedulers, scheduler, activeSchedulers]); const handleChange = useCallback( diff --git a/invokeai/frontend/web/src/features/ui/store/uiSlice.ts b/invokeai/frontend/web/src/features/ui/store/uiSlice.ts index 907d5a5295..4de6109b20 100644 --- a/invokeai/frontend/web/src/features/ui/store/uiSlice.ts +++ b/invokeai/frontend/web/src/features/ui/store/uiSlice.ts @@ -99,13 +99,20 @@ export const uiSlice = createSlice({ setSelectedSchedulers: (state, action: PayloadAction) => { const selectedSchedulerData: SelectItem[] = []; - if (action.payload.length === 0) action.payload = [SCHEDULERS[0].value]; + let selectedSchedulers = [...action.payload]; - action.payload.forEach((item) => { + if (selectedSchedulers.length === 0) { + selectedSchedulers = [SCHEDULERS[0].value]; + } + + selectedSchedulers.forEach((item) => { const schedulerData = SCHEDULERS.find( (scheduler) => scheduler.value === item ); - if (schedulerData) selectedSchedulerData.push(schedulerData); + + if (schedulerData) { + selectedSchedulerData.push(schedulerData); + } }); state.activeSchedulers = selectedSchedulerData;