mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
reduced no of calls on load
This commit is contained in:
@ -18,9 +18,6 @@ import 'package:syncrow_web/services/product_api.dart';
|
||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||
|
||||
class SpaceManagementBloc
|
||||
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
||||
@ -231,12 +228,20 @@ class SpaceManagementBloc
|
||||
) async {
|
||||
_logEvent('LoadCommunityAndSpacesEvent');
|
||||
|
||||
var prevState = state;
|
||||
// If already loaded, use cached data
|
||||
if (state is SpaceManagementLoaded) {
|
||||
emit(state);
|
||||
return;
|
||||
}
|
||||
|
||||
emit(SpaceManagementLoading());
|
||||
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
// Load products only once
|
||||
_onloadProducts();
|
||||
|
||||
List<CommunityModel> communities =
|
||||
await _api.fetchCommunities(projectUuid);
|
||||
|
||||
@ -250,17 +255,20 @@ class SpaceManagementBloc
|
||||
updatedAt: community.updatedAt,
|
||||
name: community.name,
|
||||
description: community.description,
|
||||
spaces: spaces, // New spaces list
|
||||
spaces: spaces,
|
||||
region: community.region,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
final prevSpaceModels = await fetchSpaceModels(prevState);
|
||||
// Fetch space models only once
|
||||
final prevSpaceModels = await fetchSpaceModels(state);
|
||||
|
||||
emit(SpaceManagementLoaded(
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels));
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user