mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
58 lines
1.9 KiB
Dart
58 lines
1.9 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_state.dart';
|
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
|
|
|
class SpaceManagementBloc
|
|
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
|
final CommunitySpaceManagementApi _api;
|
|
|
|
SpaceManagementBloc(this._api) : super(SpaceManagementInitial()) {
|
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
|
on<CreateSpaceEvent>(_onCreateSpace);
|
|
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
|
}
|
|
|
|
void _onLoadCommunityAndSpaces(
|
|
LoadCommunityAndSpacesEvent event,
|
|
Emitter<SpaceManagementState> emit,
|
|
) async {
|
|
emit(SpaceManagementLoading());
|
|
try {
|
|
// Fetch all communities
|
|
List<CommunityModel> communities = await _api.fetchCommunities();
|
|
|
|
Map<String, List<SpaceModel>> communitySpaces = {};
|
|
|
|
for (CommunityModel community in communities) {
|
|
// Fetch spaces hierarchy for each community
|
|
List<SpaceModel> spaces = await _api.getSpaceHierarchy(community.uuid);
|
|
community.spaces = spaces;
|
|
communitySpaces[community.uuid] = spaces;
|
|
}
|
|
|
|
emit(SpaceManagementLoaded(communitySpaces: communitySpaces));
|
|
} catch (e) {
|
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
|
}
|
|
}
|
|
|
|
void _onCreateSpace(
|
|
CreateSpaceEvent event,
|
|
Emitter<SpaceManagementState> emit,
|
|
) {
|
|
// Handle space creation logic
|
|
// You can emit a new state here based on your needs
|
|
emit(SpaceCreationSuccess());
|
|
}
|
|
|
|
void _onUpdateSpacePosition(
|
|
UpdateSpacePositionEvent event,
|
|
Emitter<SpaceManagementState> emit,
|
|
) {
|
|
// Handle space position update logic
|
|
}
|
|
}
|