From 8e9278c93c32b5fc64e6b9578cc0a8d6ade8ba10 Mon Sep 17 00:00:00 2001 From: raf-dev1 Date: Tue, 10 Jun 2025 10:05:50 +0300 Subject: [PATCH] edits with faris and main task to fix loading state forever and prevent rethrow exceptions without catching them --- .../bloc/space_management_bloc.dart | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart index 04087257..e5c9432f 100644 --- a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart +++ b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart @@ -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 subspaceUpdates = []; final List? 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;