mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +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_mana_api.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_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/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
|
class SpaceManagementBloc
|
||||||
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
||||||
@ -231,12 +228,20 @@ class SpaceManagementBloc
|
|||||||
) async {
|
) async {
|
||||||
_logEvent('LoadCommunityAndSpacesEvent');
|
_logEvent('LoadCommunityAndSpacesEvent');
|
||||||
|
|
||||||
var prevState = state;
|
// If already loaded, use cached data
|
||||||
|
if (state is SpaceManagementLoaded) {
|
||||||
|
emit(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
|
// Load products only once
|
||||||
_onloadProducts();
|
_onloadProducts();
|
||||||
|
|
||||||
List<CommunityModel> communities =
|
List<CommunityModel> communities =
|
||||||
await _api.fetchCommunities(projectUuid);
|
await _api.fetchCommunities(projectUuid);
|
||||||
|
|
||||||
@ -250,17 +255,20 @@ class SpaceManagementBloc
|
|||||||
updatedAt: community.updatedAt,
|
updatedAt: community.updatedAt,
|
||||||
name: community.name,
|
name: community.name,
|
||||||
description: community.description,
|
description: community.description,
|
||||||
spaces: spaces, // New spaces list
|
spaces: spaces,
|
||||||
region: community.region,
|
region: community.region,
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
final prevSpaceModels = await fetchSpaceModels(prevState);
|
// Fetch space models only once
|
||||||
|
final prevSpaceModels = await fetchSpaceModels(state);
|
||||||
|
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
spaceModels: prevSpaceModels));
|
spaceModels: prevSpaceModels,
|
||||||
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user