mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 16:59:40 +00:00
[FE] When user navigates to devices page the devices are already listed although no community is selected also when we select a community the API is being called repeatedly too many times (#356)
<!-- 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: --> ## Jira Ticket [SP-1589](https://syncrow.atlassian.net/browse/SP-1589) ## Description fixed the issue of community selection (if empty no devices should appear) ## 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 [SP-1589]: https://syncrow.atlassian.net/browse/SP-1589?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
This commit is contained in:
@ -53,8 +53,9 @@ class DeviceManagementBloc
|
|||||||
for (var community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
final spacesList =
|
final spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||||
devices.addAll(await DevicesManagementApi()
|
devices.addAll(await DevicesManagementApi().fetchDevices(projectUuid,
|
||||||
.fetchDevices(projectUuid, spacesId: spacesList));
|
spacesId: spacesList,
|
||||||
|
communities: spaceBloc.state.selectedCommunities));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +159,8 @@ class DeviceManagementBloc
|
|||||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSelectDevice(SelectDevice event, Emitter<DeviceManagementState> emit) {
|
void _onSelectDevice(
|
||||||
|
SelectDevice event, Emitter<DeviceManagementState> emit) {
|
||||||
final selectedUuid = event.selectedDevice.uuid;
|
final selectedUuid = event.selectedDevice.uuid;
|
||||||
|
|
||||||
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
|
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
|
||||||
@ -254,7 +256,8 @@ class DeviceManagementBloc
|
|||||||
_onlineCount = _devices.where((device) => device.online == true).length;
|
_onlineCount = _devices.where((device) => device.online == true).length;
|
||||||
_offlineCount = _devices.where((device) => device.online == false).length;
|
_offlineCount = _devices.where((device) => device.online == false).length;
|
||||||
_lowBatteryCount = _devices
|
_lowBatteryCount = _devices
|
||||||
.where((device) => device.batteryLevel != null && device.batteryLevel! < 20)
|
.where((device) =>
|
||||||
|
device.batteryLevel != null && device.batteryLevel! < 20)
|
||||||
.length;
|
.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +274,8 @@ class DeviceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSearchDevices(SearchDevices event, Emitter<DeviceManagementState> emit) {
|
void _onSearchDevices(
|
||||||
|
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||||
if ((event.community == null || event.community!.isEmpty) &&
|
if ((event.community == null || event.community!.isEmpty) &&
|
||||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||||
(event.deviceNameOrProductName == null ||
|
(event.deviceNameOrProductName == null ||
|
||||||
@ -435,8 +439,8 @@ class DeviceManagementBloc
|
|||||||
final selectedDevices = loaded.selectedDevice?.map((device) {
|
final selectedDevices = loaded.selectedDevice?.map((device) {
|
||||||
if (device.uuid == event.deviceId) {
|
if (device.uuid == event.deviceId) {
|
||||||
return device.copyWith(
|
return device.copyWith(
|
||||||
subspace:
|
subspace: device.subspace
|
||||||
device.subspace?.copyWith(subspaceName: event.newSubSpaceName));
|
?.copyWith(subspaceName: event.newSubSpaceName));
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
@ -937,13 +937,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
|
||||||
devices.addAll(await DevicesManagementApi()
|
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||||
.fetchDevices(projectUuid, spacesId: spacesList));
|
projectUuid,
|
||||||
|
spacesId: spacesList,
|
||||||
|
communities: spaceBloc.state.selectedCommunities,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||||
projectUuid,
|
projectUuid,
|
||||||
spacesId: [createRoutineBloc.selectedSpaceId],
|
spacesId: [createRoutineBloc.selectedSpaceId],
|
||||||
|
communities: spaceBloc.state.selectedCommunities,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,15 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
|
|||||||
|
|
||||||
class DevicesManagementApi {
|
class DevicesManagementApi {
|
||||||
Future<List<AllDevicesModel>> fetchDevices(String projectId,
|
Future<List<AllDevicesModel>> fetchDevices(String projectId,
|
||||||
{List<String>? spacesId}) async {
|
{List<String>? spacesId, List<String>? communities}) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getSpaceDevices.replaceAll('{projectId}', projectId),
|
path: ApiEndpoints.getSpaceDevices.replaceAll('{projectId}', projectId),
|
||||||
queryParameters: {if (spacesId != null) 'spaces': spacesId},
|
queryParameters: {
|
||||||
|
if (spacesId != null && spacesId.isNotEmpty) 'spaces': spacesId,
|
||||||
|
if (communities != null && communities.isNotEmpty)
|
||||||
|
'communities': communities,
|
||||||
|
},
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final List<dynamic> jsonData = json['data'] as List<dynamic>;
|
final List<dynamic> jsonData = json['data'] as List<dynamic>;
|
||||||
|
Reference in New Issue
Block a user