diff --git a/lib/pages/device_managment/schedule_device/bloc/schedule_bloc.dart b/lib/pages/device_managment/schedule_device/bloc/schedule_bloc.dart index c4e731db..62213205 100644 --- a/lib/pages/device_managment/schedule_device/bloc/schedule_bloc.dart +++ b/lib/pages/device_managment/schedule_device/bloc/schedule_bloc.dart @@ -257,11 +257,11 @@ class ScheduleBloc extends Bloc { category: event.category, deviceId: deviceId, time: getTimeStampWithoutSeconds(dateTime).toString(), - code: 'switch_1', + code: event.category, value: event.functionOn, days: event.selectedDays); if (success) { - add(const ScheduleGetEvent(category: 'switch_1')); + add(ScheduleGetEvent(category: event.category)); } else { emit(const ScheduleError('Failed to add schedule')); } @@ -282,7 +282,7 @@ class ScheduleBloc extends Bloc { scheduleId: event.scheduleId, category: event.category, time: getTimeStampWithoutSeconds(dateTime).toString(), - function: Status(code: 'switch_1', value: event.functionOn), + function: Status(code: event.category, value: event.functionOn), days: event.selectedDays, ); final success = await DevicesManagementApi().editScheduleRecord( @@ -291,7 +291,9 @@ class ScheduleBloc extends Bloc { ); if (success) { - add(const ScheduleGetEvent(category: 'switch_1')); + add(ScheduleGetEvent( + category: event.category, + )); } else { emit(const ScheduleError('Failed to update schedule')); } @@ -312,7 +314,7 @@ class ScheduleBloc extends Bloc { final updatedSchedules = currentState.schedules.map((schedule) { if (schedule.scheduleId == event.scheduleId) { return schedule.copyWith( - function: Status(code: 'switch_1', value: event.functionOn), + function: Status(code: event.category, value: event.functionOn), enable: event.enable, ); } @@ -533,10 +535,6 @@ class ScheduleBloc extends Bloc { Duration.zero; } if (state is ScheduleLoaded) { - print('Updating existing state with fetched status'); - print('scheduleMode: $scheduleMode'); - print('countdownRemaining: $countdownRemaining'); - print('isCountdownActive: $isCountdownActive'); final currentState = state as ScheduleLoaded; emit(currentState.copyWith( scheduleMode: scheduleMode, @@ -586,35 +584,4 @@ class ScheduleBloc extends Bloc { dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - - // Future _updateScheduleEvent( - // StatusUpdatedScheduleEvent event, - // Emitter emit, - // ) async { - // if (state is ScheduleLoaded) { - // final currentState = state as ScheduleLoaded; - - // final updatedSchedules = currentState.schedules.map((schedule) { - // if (schedule.scheduleId == event.scheduleId) { - // return schedule.copyWith( - // function: Status(code: 'switch_1', value: event.functionOn), - // enable: event.enable, - // ); - // } - // return schedule; - // }).toList(); - - // bool success = await DevicesManagementApi().updateScheduleRecord( - // enable: event.enable, - // uuid: currentState.status.uuid, - // scheduleId: event.scheduleId, - // ); - - // if (success) { - // emit(currentState.copyWith(schedules: updatedSchedules)); - // } else { - // emit(currentState); - // } - // } - // } } diff --git a/lib/pages/device_managment/schedule_device/bloc/schedule_event.dart b/lib/pages/device_managment/schedule_device/bloc/schedule_event.dart index 5099679c..7ec144fe 100644 --- a/lib/pages/device_managment/schedule_device/bloc/schedule_event.dart +++ b/lib/pages/device_managment/schedule_device/bloc/schedule_event.dart @@ -121,15 +121,17 @@ class ScheduleUpdateEntryEvent extends ScheduleEvent { final String scheduleId; final bool functionOn; final bool enable; + final String category; const ScheduleUpdateEntryEvent({ required this.scheduleId, required this.functionOn, required this.enable, + required this.category, }); @override - List get props => [scheduleId, functionOn, enable]; + List get props => [scheduleId, functionOn, enable, category]; } class UpdateScheduleModeEvent extends ScheduleEvent { diff --git a/lib/pages/device_managment/schedule_device/schedule_widgets/schedual_view.dart b/lib/pages/device_managment/schedule_device/schedule_widgets/schedual_view.dart index 2ae5b869..2fa34559 100644 --- a/lib/pages/device_managment/schedule_device/schedule_widgets/schedual_view.dart +++ b/lib/pages/device_managment/schedule_device/schedule_widgets/schedual_view.dart @@ -15,7 +15,7 @@ class BuildScheduleView extends StatelessWidget { const BuildScheduleView( {super.key, required this.deviceUuid, required this.category}); final String deviceUuid; - final String category; + final String category; @override Widget build(BuildContext context) { @@ -51,6 +51,7 @@ class BuildScheduleView extends StatelessWidget { const SizedBox(height: 20), if (state.scheduleMode == ScheduleModes.schedule) ScheduleManagementUI( + category: category, deviceUuid: deviceUuid, onAddSchedule: () async { final entry = await ScheduleDialogHelper diff --git a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_managment_ui.dart b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_managment_ui.dart index b60f00b9..8f871ce4 100644 --- a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_managment_ui.dart +++ b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_managment_ui.dart @@ -7,11 +7,13 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart'; class ScheduleManagementUI extends StatelessWidget { final String deviceUuid; final VoidCallback onAddSchedule; + final String category; const ScheduleManagementUI({ super.key, required this.deviceUuid, required this.onAddSchedule, + this.category = 'switch_1', }); @override @@ -42,7 +44,7 @@ class ScheduleManagementUI extends StatelessWidget { ), ), const SizedBox(height: 20), - ScheduleTableWidget(deviceUuid: deviceUuid), + ScheduleTableWidget(deviceUuid: deviceUuid, category: category), ], ); } diff --git a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_mode_selector.dart b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_mode_selector.dart index 2bcc0957..25bf7f2c 100644 --- a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_mode_selector.dart +++ b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_mode_selector.dart @@ -39,10 +39,10 @@ class ScheduleModeSelector extends StatelessWidget { context, 'Countdown', ScheduleModes.countdown, currentMode), _buildRadioTile( context, 'Schedule', ScheduleModes.schedule, currentMode), - _buildRadioTile( - context, 'Circulate', ScheduleModes.circulate, currentMode), - _buildRadioTile( - context, 'Inching', ScheduleModes.inching, currentMode), + // _buildRadioTile( + // context, 'Circulate', ScheduleModes.circulate, currentMode), + // _buildRadioTile( + // context, 'Inching', ScheduleModes.inching, currentMode), ], ), ], diff --git a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_table.dart b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_table.dart index 97ca03e1..98ae0515 100644 --- a/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_table.dart +++ b/lib/pages/device_managment/schedule_device/schedule_widgets/schedule_table.dart @@ -164,6 +164,7 @@ class _ScheduleTableView extends StatelessWidget { onTap: () { context.read().add( ScheduleUpdateEntryEvent( + category: schedule.category, scheduleId: schedule.scheduleId, functionOn: schedule.function.value, enable: !schedule.enable,