diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart index 6df5a780..56b08ced 100644 --- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart +++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart @@ -35,6 +35,7 @@ class DeviceManagementBloc extends Bloc devices = []; + _devices.clear(); var spaceBloc = event.context.read(); if (spaceBloc.state.selectedCommunities.isEmpty) { devices = await DevicesManagementApi().fetchDevices('', ''); @@ -42,7 +43,7 @@ class DeviceManagementBloc extends Bloc spacesList = spaceBloc.state.selectedCommunityAndSpaces[community] ?? []; for (var space in spacesList) { - await DevicesManagementApi().fetchDevices(community, space); + devices.addAll(await DevicesManagementApi().fetchDevices(community, space)); } } } diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index bc83c40f..b05229c4 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -816,7 +816,7 @@ class RoutineBloc extends Bloc { FutureOr _fetchDevices(FetchDevicesInRoutine event, Emitter emit) async { emit(state.copyWith(isLoading: true)); try { - final devices = await DevicesManagementApi().fetchDevices(communityId, spaceId); + final devices = await DevicesManagementApi().fetchDevices('', ''); emit(state.copyWith(isLoading: false, devices: devices)); } catch (e) { diff --git a/lib/pages/space_tree/bloc/space_tree_bloc.dart b/lib/pages/space_tree/bloc/space_tree_bloc.dart index 75aa58ce..6ac0c0d9 100644 --- a/lib/pages/space_tree/bloc/space_tree_bloc.dart +++ b/lib/pages/space_tree/bloc/space_tree_bloc.dart @@ -6,8 +6,8 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model import 'package:syncrow_web/services/space_mana_api.dart'; class SpaceTreeBloc extends Bloc { - String selectedCommunityId = '9cb9da1f-adbe-4688-bf55-29e7584007a7'; - String selectedSpaceId = '68dd94cf-0240-4ccf-8c26-df506246a0dd'; + String selectedCommunityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9'; + String selectedSpaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6'; SpaceTreeBloc() : super(const SpaceTreeState()) { on(_fetchSpaces); @@ -87,6 +87,7 @@ class SpaceTreeBloc extends Bloc { List.from(state.selectedCommunities.toSet().toList()); List updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList()); List updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); + Map> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces); List childrenIds = _getAllChildIds(event.children); @@ -101,10 +102,13 @@ class SpaceTreeBloc extends Bloc { updatedSoldChecks.removeWhere(childrenIds.contains); } + communityAndSpaces[event.communityId] = updatedSelectedSpaces; + emit(state.copyWith( selectedCommunities: updatedSelectedCommunities, selectedSpaces: updatedSelectedSpaces, - soldCheck: updatedSoldChecks)); + soldCheck: updatedSoldChecks, + selectedCommunityAndSpaces: communityAndSpaces)); } catch (e) { emit(const SpaceTreeErrorState('Something went wrong')); } @@ -116,6 +120,7 @@ class SpaceTreeBloc extends Bloc { List.from(state.selectedCommunities.toSet().toList()); List updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList()); List updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); + Map> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces); List childrenIds = _getAllChildIds(event.children); bool isChildSelected = false; @@ -166,10 +171,13 @@ class SpaceTreeBloc extends Bloc { } } + communityAndSpaces[event.communityId] = updatedSelectedSpaces; + emit(state.copyWith( selectedCommunities: updatedSelectedCommunities, selectedSpaces: updatedSelectedSpaces, - soldCheck: updatedSoldChecks)); + soldCheck: updatedSoldChecks, + selectedCommunityAndSpaces: communityAndSpaces)); emit(state.copyWith(selectedSpaces: updatedSelectedSpaces)); } catch (e) { emit(const SpaceTreeErrorState('Something went wrong')); diff --git a/lib/pages/space_tree/view/space_tree_view.dart b/lib/pages/space_tree/view/space_tree_view.dart index 1fcc63b0..6f7dcb90 100644 --- a/lib/pages/space_tree/view/space_tree_view.dart +++ b/lib/pages/space_tree/view/space_tree_view.dart @@ -75,11 +75,11 @@ class SpaceTreeView extends StatelessWidget { onItemSelected: () { context.read().add(OnSpaceSelected( community.uuid, space.uuid ?? '', space.children)); + onSelect(); }, onExpansionChanged: () { context.read().add( OnSpaceExpanded(community.uuid, space.uuid ?? '')); - onSelect(); }, isSelected: state.selectedSpaces.contains(space.uuid) || state.soldCheck.contains(space.uuid), diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index cdddbbeb..1a8b979e 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -23,7 +23,8 @@ class DevicesManagementApi { : ApiEndpoints.getAllDevices, showServerMessage: true, expectedResponseModel: (json) { - List jsonData = json; + List jsonData = + communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json; List devicesList = jsonData.map((jsonItem) { return AllDevicesModel.fromJson(jsonItem); }).toList();