mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
fixed expand error
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/material.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';
|
||||
@ -24,16 +25,28 @@ class SpaceManagementBloc
|
||||
// Fetch all communities
|
||||
List<CommunityModel> communities = await _api.fetchCommunities();
|
||||
|
||||
Map<String, List<SpaceModel>> communitySpaces = {};
|
||||
// Use Future.wait to handle async calls within map
|
||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
communities.map((community) async {
|
||||
List<SpaceModel> spaces =
|
||||
await _api.getSpaceHierarchy(community.uuid);
|
||||
|
||||
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;
|
||||
}
|
||||
debugPrint(
|
||||
'Fetched spaces for community ${community.name}: ${spaces.length}');
|
||||
|
||||
emit(SpaceManagementLoaded(communitySpaces: communitySpaces));
|
||||
return CommunityModel(
|
||||
uuid: community.uuid,
|
||||
createdAt: community.createdAt,
|
||||
updatedAt: community.updatedAt,
|
||||
name: community.name,
|
||||
description: community.description,
|
||||
spaces: spaces, // New spaces list
|
||||
region: community.region,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
emit(SpaceManagementLoaded(communities: updatedCommunities));
|
||||
} catch (e) {
|
||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
|
||||
abstract class SpaceManagementState extends Equatable {
|
||||
@ -13,12 +14,13 @@ class SpaceManagementInitial extends SpaceManagementState {}
|
||||
class SpaceManagementLoading extends SpaceManagementState {}
|
||||
|
||||
class SpaceManagementLoaded extends SpaceManagementState {
|
||||
final Map<String, List<SpaceModel>> communitySpaces;
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
const SpaceManagementLoaded({required this.communitySpaces});
|
||||
|
||||
const SpaceManagementLoaded({ required this.communities});
|
||||
|
||||
@override
|
||||
List<Object> get props => [communitySpaces];
|
||||
List<Object> get props => [communities];
|
||||
}
|
||||
|
||||
class SpaceCreationSuccess extends SpaceManagementState {}
|
||||
|
@ -13,7 +13,7 @@ class SpaceModel {
|
||||
final SpaceModel? parent;
|
||||
final CommunityModel? community;
|
||||
final List<SpaceModel> children;
|
||||
final String icon;
|
||||
final String? icon;
|
||||
Offset position;
|
||||
bool isHovered;
|
||||
|
||||
@ -54,11 +54,11 @@ class SpaceModel {
|
||||
.map((child) => SpaceModel.fromJson(child))
|
||||
.toList()
|
||||
: [],
|
||||
icon: json['icon'], // New field from JSON
|
||||
icon: json['icon'],
|
||||
position: json['position'] != null
|
||||
? Offset(json['position']['dx'], json['position']['dy'])
|
||||
: Offset(0, 0), // Default position if not provided in JSON
|
||||
isHovered: json['isHovered'] ?? false, // Default isHovered if not in JSON
|
||||
: const Offset(0, 0),
|
||||
isHovered: false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/common/buttons/add_space_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.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/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/view/curved_line_painter.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_space_dialog.dart';
|
||||
@ -53,8 +54,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
if (state is SpaceManagementLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is SpaceManagementLoaded) {
|
||||
return _buildLoadedState(
|
||||
context, screenSize, state.communitySpaces);
|
||||
return _buildLoadedState(context, screenSize, state.communities);
|
||||
} else if (state is SpaceManagementError) {
|
||||
return Center(child: Text('Error: ${state.errorMessage}'));
|
||||
}
|
||||
@ -65,24 +65,22 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadedState(BuildContext context, Size screenSize,
|
||||
Map<String, List<SpaceModel>> communitySpaces) {
|
||||
Widget _buildLoadedState(
|
||||
BuildContext context, Size screenSize, List<CommunityModel> communities) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communitySpaces: communitySpaces,
|
||||
communities: communities,
|
||||
onCommunitySelected: (community) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
LoadCommunityAndSpacesEvent(), // Re-fetch or perform community-specific actions
|
||||
);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: _buildCommunityStructureArea(context, screenSize),
|
||||
),
|
||||
_buildCommunityStructureArea(context, screenSize),
|
||||
],
|
||||
),
|
||||
_buildGradientBorder(),
|
||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/common/custom_expansion_tile.dart';
|
||||
import 'package:syncrow_web/common/search_bar.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/widgets/community_tile.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_community_dialog.dart';
|
||||
@ -11,9 +12,9 @@ import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class SidebarWidget extends StatefulWidget {
|
||||
final Function(String)? onCommunitySelected;
|
||||
final Map<String, List<SpaceModel>> communitySpaces;
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
SidebarWidget({this.onCommunitySelected, required this.communitySpaces});
|
||||
SidebarWidget({this.onCommunitySelected, required this.communities});
|
||||
|
||||
@override
|
||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||
@ -34,9 +35,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
builder: (context) => CreateCommunityDialog(
|
||||
onCreateCommunity: (String communityName) {
|
||||
setState(() {
|
||||
debugPrint("hello");
|
||||
|
||||
// You can update the communitySpaces map here
|
||||
// You can update the community list here when a new community is added
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -44,21 +43,19 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}
|
||||
|
||||
// Function to filter communities based on the search query
|
||||
Map<String, List<SpaceModel>> _filterCommunities() {
|
||||
List<CommunityModel> _filterCommunities() {
|
||||
if (_searchQuery.isEmpty) {
|
||||
return widget.communitySpaces;
|
||||
return widget.communities;
|
||||
}
|
||||
|
||||
// Filter communities and their spaces based on the search query
|
||||
final filteredCommunitySpaces = <String, List<SpaceModel>>{};
|
||||
widget.communitySpaces.forEach((communityName, spaces) {
|
||||
if (communityName.toLowerCase().contains(_searchQuery.toLowerCase()) ||
|
||||
spaces.any(
|
||||
(space) => _containsQuery(space, _searchQuery.toLowerCase()))) {
|
||||
filteredCommunitySpaces[communityName] = spaces;
|
||||
}
|
||||
});
|
||||
return filteredCommunitySpaces;
|
||||
return widget.communities.where((community) {
|
||||
final containsQueryInCommunity =
|
||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
final containsQueryInSpaces = community.spaces
|
||||
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||
return containsQueryInCommunity || containsQueryInSpaces;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Helper function to determine if any space or its children match the search query
|
||||
@ -128,13 +125,10 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Community list
|
||||
Flexible(
|
||||
fit: FlexFit
|
||||
.loose, // Ensure the ListView can flex but doesn't expand indefinitely
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: filteredCommunities.keys.map((communityName) {
|
||||
return _buildCommunityTile(
|
||||
communityName, filteredCommunities[communityName]!);
|
||||
children: filteredCommunities.map((community) {
|
||||
return _buildCommunityTile(community);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
@ -143,21 +137,21 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommunityTile(String communityName, List<SpaceModel> spaces) {
|
||||
bool hasChildren = spaces.isNotEmpty;
|
||||
Widget _buildCommunityTile(CommunityModel community) {
|
||||
bool hasChildren = community.spaces.isNotEmpty;
|
||||
|
||||
debugPrint(
|
||||
'Building CommunityTile for $communityName, hasChildren: $hasChildren');
|
||||
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
|
||||
return CommunityTile(
|
||||
title: communityName,
|
||||
isExpanded: _expandedTiles[communityName] ?? false,
|
||||
title: community.name,
|
||||
isExpanded: _expandedTiles[community.uuid] ?? false,
|
||||
onExpansionChanged: (String title, bool expanded) {
|
||||
debugPrint(
|
||||
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
||||
_handleExpansionChange(title, expanded);
|
||||
_handleExpansionChange(community.uuid, expanded);
|
||||
},
|
||||
children: hasChildren
|
||||
? spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||
? community.spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||
: null, // Render spaces within the community
|
||||
);
|
||||
}
|
||||
|
@ -223,4 +223,5 @@ class CommunitySpaceManagementApi {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user