From e36a4e5785dab81e631b20c66f1aceade6a358d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Sun, 11 Jan 2026 00:44:23 +0100 Subject: [PATCH] Refactor organization creation logic for improved readability and maintainability --- .../lib/blocs/organization/organization_bloc.dart | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/b0esche_cloud/lib/blocs/organization/organization_bloc.dart b/b0esche_cloud/lib/blocs/organization/organization_bloc.dart index 605ee06..942a5aa 100644 --- a/b0esche_cloud/lib/blocs/organization/organization_bloc.dart +++ b/b0esche_cloud/lib/blocs/organization/organization_bloc.dart @@ -112,15 +112,15 @@ class OrganizationBloc extends Bloc { } return; } - + // Get existing organizations list List existingOrgs = []; Organization? selectedOrg; - + if (state is OrganizationLoaded) { existingOrgs = (state as OrganizationLoaded).organizations; selectedOrg = (state as OrganizationLoaded).selectedOrg; - + // Check for duplicate name (client-side validation) if (existingOrgs.any((org) => org.name == name)) { emit( @@ -134,7 +134,7 @@ class OrganizationBloc extends Bloc { return; } } - + // Set loading state emit( OrganizationLoaded( @@ -143,13 +143,11 @@ class OrganizationBloc extends Bloc { isLoading: true, ), ); - + try { final newOrg = await orgApi.createOrganization(name); final updatedOrgs = [...existingOrgs, newOrg]; - emit( - OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg), - ); + emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg)); // Reset blocs and load permissions for new org permissionBloc.add(PermissionsReset()); fileBrowserBloc.add(ResetFileBrowser());