fix the flatten

This commit is contained in:
hannathkadher
2025-04-28 12:59:16 +04:00
parent 7cbe20ae88
commit 25614c3dd0

View File

@ -407,21 +407,31 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
List<SpaceModel> flattenSpaces(List<SpaceModel> spaces) {
List<SpaceModel> result = [];
Map<String, SpaceModel> idToSpace = {};
void flatten(SpaceModel space) {
if (space.status == SpaceStatus.deleted || space.status == SpaceStatus.parentDeleted) {
return;
}
result.add(space);
idToSpace[space.internalId] = space;
for (var child in space.children) {
flatten(child);
}
}
for (var space in spaces) {
flatten(space);
}
for (var space in result) {
if (space.parent != null) {
space.parent = idToSpace[space.parent!.internalId];
}
}
return result;
}