mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Refactor ScheduleBloc and related components to use dynamic category … (#279)
<!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Description <!--- Describe your changes in detail --> Fix scheduling Bugs ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ New feature (non-breaking change which adds functionality) - [x] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore
This commit is contained in:
@ -257,11 +257,11 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
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<ScheduleEvent, ScheduleState> {
|
||||
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<ScheduleEvent, ScheduleState> {
|
||||
);
|
||||
|
||||
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<ScheduleEvent, ScheduleState> {
|
||||
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<ScheduleEvent, ScheduleState> {
|
||||
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<ScheduleEvent, ScheduleState> {
|
||||
dateTime.day, dateTime.hour, dateTime.minute);
|
||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
|
||||
// Future <void> _updateScheduleEvent(
|
||||
// StatusUpdatedScheduleEvent event,
|
||||
// Emitter<ScheduleState> 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -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<Object> get props => [scheduleId, functionOn, enable];
|
||||
List<Object> get props => [scheduleId, functionOn, enable, category];
|
||||
}
|
||||
|
||||
class UpdateScheduleModeEvent extends ScheduleEvent {
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -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),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -164,6 +164,7 @@ class _ScheduleTableView extends StatelessWidget {
|
||||
onTap: () {
|
||||
context.read<ScheduleBloc>().add(
|
||||
ScheduleUpdateEntryEvent(
|
||||
category: schedule.category,
|
||||
scheduleId: schedule.scheduleId,
|
||||
functionOn: schedule.function.value,
|
||||
enable: !schedule.enable,
|
||||
|
Reference in New Issue
Block a user