refactor: improve readability and structure in SidebarWidget's space tile handling

This commit is contained in:
Faris Armoush
2025-04-13 12:33:50 +03:00
parent c2f5a8df10
commit 55695ca5db

View File

@ -183,23 +183,30 @@ class _SidebarWidgetState extends State<SidebarWidget> {
onExpansionChanged: (title, expanded) {},
children: hasChildren
? community.spaces
.where((space) => (space.status != SpaceStatus.deleted ||
space.status != SpaceStatus.parentDeleted))
.map((space) => _buildSpaceTile(space, community))
.where((space) {
final isDeleted = space.status != SpaceStatus.deleted;
final isParentDeleted = space.status != SpaceStatus.parentDeleted;
return (isDeleted || isParentDeleted);
})
.map((space) => _buildSpaceTile(space: space, community: community))
.toList()
: null,
);
}
Widget _buildSpaceTile(SpaceModel space, CommunityModel community,
{int depth = 1}) {
Widget _buildSpaceTile({
required SpaceModel space,
required CommunityModel community,
int depth = 1,
}) {
bool spaceIsExpanded = _isSpaceOrChildSelected(space);
final isSelected = _selectedId == space.uuid;
return Padding(
padding: EdgeInsets.only(left: depth * 16.0),
child: SpaceTile(
title: space.name,
key: ValueKey(space.uuid),
isSelected: _selectedId == space.uuid,
isSelected: isSelected,
initiallyExpanded: spaceIsExpanded,
onExpansionChanged: (expanded) {},
onItemSelected: () {
@ -212,11 +219,14 @@ class _SidebarWidgetState extends State<SidebarWidget> {
SelectSpaceEvent(selectedCommunity: community, selectedSpace: space),
);
},
children: space.children.isNotEmpty
? space.children
.map((childSpace) => _buildSpaceTile(childSpace, community))
.toList()
: [],
children: space.children
.map(
(childSpace) => _buildSpaceTile(
space: childSpace,
community: community,
),
)
.toList(),
),
);
}