fix(web): derive schedules-loading state instead of sync setState in effect (lint)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+7
-8
@@ -2648,32 +2648,31 @@ function AddPlayoutDialog({
|
||||
const [channelId, setChannelId] = useState('');
|
||||
const [scheduleId, setScheduleId] = useState('');
|
||||
const [scheduleFile, setScheduleFile] = useState('');
|
||||
const [schedules, setSchedules] = useState<ProgramSchedule[]>([]);
|
||||
const [schedulesLoading, setSchedulesLoading] = useState(false);
|
||||
const [schedules, setSchedules] = useState<ProgramSchedule[] | null>(null);
|
||||
const schedulesLoading = kind === 'Classic' && schedules === null;
|
||||
|
||||
useEffect(() => {
|
||||
if (kind !== 'Classic') {
|
||||
if (kind !== 'Classic' || schedules !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let active = true;
|
||||
setSchedulesLoading(true);
|
||||
getSchedules()
|
||||
.then((result) => {
|
||||
if (active) {
|
||||
setSchedules(result);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
.catch(() => {
|
||||
if (active) {
|
||||
setSchedulesLoading(false);
|
||||
setSchedules([]);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [kind]);
|
||||
}, [kind, schedules]);
|
||||
|
||||
const channels = channelsQuery.status === 'success' ? channelsQuery.channels : [];
|
||||
const needsScheduleFile = kind === 'Sequential' || kind === 'Scripted' || kind === 'ExternalJson';
|
||||
@@ -2741,7 +2740,7 @@ function AddPlayoutDialog({
|
||||
onChange={(event) => setScheduleId(event.target.value)}
|
||||
options={[
|
||||
{ label: schedulesLoading ? 'Loading...' : 'Select a schedule...', value: '' },
|
||||
...schedules.map((schedule) => ({ label: schedule.name ?? `Schedule ${schedule.id}`, value: `${schedule.id}` }))
|
||||
...(schedules ?? []).map((schedule) => ({ label: schedule.name ?? `Schedule ${schedule.id}`, value: `${schedule.id}` }))
|
||||
]}
|
||||
value={scheduleId}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user