Fetch devices based on selection

This commit is contained in:
Abdullah Alassaf
2025-02-03 11:15:36 +03:00
parent 5ae07688cb
commit 506531e16a
9 changed files with 49 additions and 22 deletions

View File

@ -6,8 +6,8 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
import 'package:syncrow_web/services/space_mana_api.dart';
class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
String selectedCommunityId = '';
String selectedSpaceId = '';
String selectedCommunityId = '9cb9da1f-adbe-4688-bf55-29e7584007a7';
String selectedSpaceId = '68dd94cf-0240-4ccf-8c26-df506246a0dd';
SpaceTreeBloc() : super(const SpaceTreeState()) {
on<InitialEvent>(_fetchSpaces);

View File

@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
class SpaceTreeState extends Equatable {
final Map<String, List<String>> selectedCommunityAndSpaces;
final List<CommunityModel> communityList;
final List<CommunityModel> filteredCommunity;
final List<String> expandedCommunities;
@ -19,7 +20,8 @@ class SpaceTreeState extends Equatable {
this.selectedCommunities = const [],
this.selectedSpaces = const [],
this.soldCheck = const [],
this.isSearching = false});
this.isSearching = false,
this.selectedCommunityAndSpaces = const {}});
SpaceTreeState copyWith(
{List<CommunityModel>? communitiesList,
@ -29,7 +31,8 @@ class SpaceTreeState extends Equatable {
List<String>? selectedCommunities,
List<String>? selectedSpaces,
List<String>? soldCheck,
bool? isSearching}) {
bool? isSearching,
Map<String, List<String>>? selectedCommunityAndSpaces}) {
return SpaceTreeState(
communityList: communitiesList ?? this.communityList,
filteredCommunity: filteredCommunity ?? this.filteredCommunity,
@ -38,7 +41,8 @@ class SpaceTreeState extends Equatable {
selectedCommunities: selectedCommunities ?? this.selectedCommunities,
selectedSpaces: selectedSpaces ?? this.selectedSpaces,
soldCheck: soldCheck ?? this.soldCheck,
isSearching: isSearching ?? this.isSearching);
isSearching: isSearching ?? this.isSearching,
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces);
}
@override
@ -50,7 +54,8 @@ class SpaceTreeState extends Equatable {
selectedCommunities,
selectedSpaces,
soldCheck,
isSearching
isSearching,
selectedCommunityAndSpaces
];
}

View File

@ -11,7 +11,8 @@ import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/style.dart';
class SpaceTreeView extends StatelessWidget {
const SpaceTreeView({super.key});
final Function onSelect;
const SpaceTreeView({required this.onSelect, super.key});
@override
Widget build(BuildContext context) {
@ -64,6 +65,8 @@ class SpaceTreeView extends StatelessWidget {
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnCommunitySelected(community.uuid, community.spaces));
onSelect();
},
children: community.spaces.map((space) {
return CustomExpansionTileSpaceTree(
@ -76,6 +79,7 @@ class SpaceTreeView extends StatelessWidget {
onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(
OnSpaceExpanded(community.uuid, space.uuid ?? ''));
onSelect();
},
isSelected: state.selectedSpaces.contains(space.uuid) ||
state.soldCheck.contains(space.uuid),
@ -109,6 +113,7 @@ class SpaceTreeView extends StatelessWidget {
context
.read<SpaceTreeBloc>()
.add(OnSpaceSelected(communityId, child.uuid ?? '', child.children));
onSelect();
},
onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(communityId, child.uuid ?? ''));