mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fix routine popup
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_state.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||
|
||||
@ -10,11 +11,12 @@ class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
||||
on<SpaceOnlyWithDevicesEvent>(_fetchSpaceOnlyWithDevices);
|
||||
on<SaveCommunityIdAndSpaceIdEvent>(saveSpaceIdCommunityId);
|
||||
on<ResetSelectedEvent>(resetSelected);
|
||||
on<FetchCommunityEvent>(_fetchCommunity);
|
||||
}
|
||||
|
||||
String selectedSpaceId = '';
|
||||
String selectedCommunityId = '';
|
||||
|
||||
List<CommunityModel> communities = [];
|
||||
List<SpaceModel> spacesOnlyWithDevices = [];
|
||||
|
||||
Future<void> _fetchSpaceOnlyWithDevices(
|
||||
@ -30,7 +32,7 @@ class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
||||
|
||||
emit(SpaceWithDeviceLoadedState(spacesOnlyWithDevices));
|
||||
} catch (e) {
|
||||
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
||||
emit(SpaceTreeErrorState('Error loading spaces: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,4 +50,18 @@ class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
||||
selectedCommunityId = '';
|
||||
emit(const ResetSelectedState());
|
||||
}
|
||||
|
||||
Future<void> _fetchCommunity(
|
||||
FetchCommunityEvent event, Emitter<CreateRoutineState> emit) async {
|
||||
emit(const CommunitiesLoadingState());
|
||||
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
communities =
|
||||
await CommunitySpaceManagementApi().fetchCommunities(projectUuid);
|
||||
emit(const CommunityLoadedState());
|
||||
} catch (e) {
|
||||
emit(SpaceTreeErrorState('Error loading communities $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,3 +41,11 @@ class ResetSelectedEvent extends CreateRoutineEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
|
||||
class FetchCommunityEvent extends CreateRoutineEvent {
|
||||
const FetchCommunityEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
@ -44,3 +44,10 @@ class ResetSelectedState extends CreateRoutineState {
|
||||
const ResetSelectedState();
|
||||
}
|
||||
|
||||
class CommunityLoadedState extends CreateRoutineState {
|
||||
const CommunityLoadedState();
|
||||
}
|
||||
|
||||
class CommunitiesLoadingState extends CreateRoutineState {
|
||||
const CommunitiesLoadingState();
|
||||
}
|
Reference in New Issue
Block a user