edits with faris and main task to fix loading state forever and prevent rethrow exceptions without catching them

This commit is contained in:
raf-dev1
2025-06-10 10:05:50 +03:00
parent 15d3a05553
commit 8e9278c93c

View File

@ -478,8 +478,11 @@ class SpaceManagementBloc
event.context, event.spaces, event.communityUuid);
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
emit(SpaceCreationSuccess(spaces: updatedSpaces));
// emit(SpaceCreationSuccess(spaces: updatedSpaces));
// updatedSpaces.forEach(
// (element) => element.uuid,
// );
// final lastUpdatedSpaced = updatedSpaces..addAll(allSpaces);
if (previousState is SpaceManagementLoaded) {
await _updateLoadedState(
spaceTreeState,
@ -490,7 +493,7 @@ class SpaceManagementBloc
);
}
} catch (e) {
emit(SpaceManagementError('Error saving spaces: $e'));
// emit(SpaceManagementError('Error saving spaces: $e'));
if (previousState is SpaceManagementLoaded) {
emit(previousState);
@ -530,8 +533,10 @@ class SpaceManagementBloc
return;
}
}
emit(previousState);
} catch (e, stackTrace) {
rethrow;
emit(previousState);
// rethrow;
}
}
@ -549,6 +554,14 @@ class SpaceManagementBloc
selectedCommunity = filteredCommunities.firstWhere(
(community) => community.uuid == communityUuid,
orElse: () => CommunityModel(
uuid: '',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
name: '',
description: '',
spaces: spaces,
),
);
} catch (e) {
return [];
@ -563,9 +576,7 @@ class SpaceManagementBloc
if (parent.uuid != null) {
await _api.deleteSpace(communityUuid, parent.uuid!, projectUuid);
}
} catch (e) {
rethrow;
}
} catch (e) {}
}
orderedSpaces.removeWhere((space) => parentsToDelete.contains(space));
@ -579,7 +590,7 @@ class SpaceManagementBloc
if (matchedSpaces.isEmpty) continue;
final prevSpace = matchedSpaces[0];
final prevSpace = matchedSpaces.elementAtOrNull(0);
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
@ -658,8 +669,10 @@ class SpaceManagementBloc
isPrivate: space.isPrivate,
position: space.position,
icon: space.icon,
subspaces: subspaceUpdates,
tags: tagUpdates,
subspaces: space.subspaces,
// subspaceUpdates,
tags: space.tags,
// tagUpdates,
spaceModelUuid: space.spaceModel?.uuid,
projectId: projectUuid);
} else {
@ -698,7 +711,8 @@ class SpaceManagementBloc
space.uuid = response?.uuid;
}
} catch (e) {
rethrow; // Stop further execution on failure
return [];
// Stop further execution on failure
}
}
return spaces;