bug fixed it is locally change the state now

This commit is contained in:
raf-dev1
2025-06-17 16:21:01 +03:00
parent 994e9f4e57
commit 09f2123946

View File

@ -1422,15 +1422,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
event.automationId, event.automationStatusUpdate, projectId); event.automationId, event.automationStatusUpdate, projectId);
if (success) { if (success) {
final updatedAutomations = await SceneApi.getAutomationByUnitId( // await SceneApi.getAutomationByUnitId(
event.automationStatusUpdate.spaceUuid, // event.automationStatusUpdate.spaceUuid,
event.communityId, // event.communityId,
projectId); // projectId);
// Remove from loading set safely // Remove from loading set safely
final updatedLoadingIds = {...state.loadingAutomationIds!} final updatedLoadingIds = {...state.loadingAutomationIds!}
..remove(event.automationId); ..remove(event.automationId);
final updatedAutomations = changeItemStateOnToggelingSceen(
state.automations, event.automationId);
emit(state.copyWith( emit(state.copyWith(
automations: updatedAutomations, automations: updatedAutomations,
loadingAutomationIds: updatedLoadingIds, loadingAutomationIds: updatedLoadingIds,
@ -1452,4 +1454,30 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
)); ));
} }
} }
List<ScenesModel> changeItemStateOnToggelingSceen(
List<ScenesModel> oldSceen, String automationId) {
final updatedAutomations = oldSceen;
final temp =
updatedAutomations.firstWhere((element) => element.id == automationId);
final tempIndex = updatedAutomations.indexWhere(
(element) => element.id == automationId,
);
updatedAutomations.removeWhere(
(element) => element.id == automationId,
);
updatedAutomations.insert(
tempIndex,
ScenesModel(
id: temp.id,
name: temp.name,
status: temp.status == 'enable' ? 'disable' : 'enable',
type: temp.type,
spaceName: temp.spaceName,
spaceId: temp.spaceId,
communityId: temp.communityId,
),
);
return updatedAutomations;
}
} }