From a1ff88bfd938780455eae78ddbca8d78ada6ce1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Fri, 9 Jan 2026 22:44:45 +0100 Subject: [PATCH] Refactor FileExplorer and HomePage to use dynamic orgId instead of hardcoded values --- b0esche_cloud/lib/pages/file_explorer.dart | 21 ++++--- b0esche_cloud/lib/pages/home_page.dart | 73 +++++++++++++--------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/b0esche_cloud/lib/pages/file_explorer.dart b/b0esche_cloud/lib/pages/file_explorer.dart index 5c4948b..128a9da 100644 --- a/b0esche_cloud/lib/pages/file_explorer.dart +++ b/b0esche_cloud/lib/pages/file_explorer.dart @@ -234,7 +234,7 @@ class _FileExplorerState extends State { if (newName.isNotEmpty && newName != file.name) { context.read().add( RenameFile( - orgId: 'org1', + orgId: widget.orgId, path: file.path, newName: newName, ), @@ -361,7 +361,7 @@ class _FileExplorerState extends State { ); if (confirmed == true) { context.read().add( - DeleteFile(orgId: 'org1', path: file.path), + DeleteFile(orgId: widget.orgId, path: file.path), ); } } @@ -725,7 +725,7 @@ class _FileExplorerState extends State { StartUpload( files: files, targetPath: '/', - orgId: 'org1', + orgId: widget.orgId, ), ); } @@ -747,7 +747,7 @@ class _FileExplorerState extends State { if (folderName != null && folderName.isNotEmpty) { context.read().add( CreateFolder( - orgId: 'org1', + orgId: widget.orgId, parentPath: '/', folderName: folderName, ), @@ -781,7 +781,7 @@ class _FileExplorerState extends State { onPressed: () { final parentPath = _getParentPath(state.currentPath); context.read().add( - LoadDirectory(orgId: 'org1', path: parentPath), + LoadDirectory(orgId: widget.orgId, path: parentPath), ); }, ), @@ -830,7 +830,10 @@ class _FileExplorerState extends State { state.currentPath, ); context.read().add( - LoadDirectory(orgId: 'org1', path: parentPath), + LoadDirectory( + orgId: widget.orgId, + path: parentPath, + ), ); }, ), @@ -888,7 +891,7 @@ class _FileExplorerState extends State { StartUpload( files: files, targetPath: '/', - orgId: 'org1', + orgId: widget.orgId, ), ); } @@ -910,7 +913,7 @@ class _FileExplorerState extends State { if (folderName != null && folderName.isNotEmpty) { context.read().add( CreateFolder( - orgId: 'org1', + orgId: widget.orgId, parentPath: state.currentPath, folderName: folderName, ), @@ -965,7 +968,7 @@ class _FileExplorerState extends State { onAcceptWithDetails: (draggedFile) { context.read().add( MoveFile( - orgId: 'org1', + orgId: widget.orgId, sourcePath: draggedFile.data.path, targetPath: file.path, ), diff --git a/b0esche_cloud/lib/pages/home_page.dart b/b0esche_cloud/lib/pages/home_page.dart index 2176620..1876407 100644 --- a/b0esche_cloud/lib/pages/home_page.dart +++ b/b0esche_cloud/lib/pages/home_page.dart @@ -163,37 +163,52 @@ class _HomePageState extends State with TickerProviderStateMixin { Widget _buildOrgRow(BuildContext context) { return BlocBuilder( builder: (context, state) { + List orgs = []; + Organization? selectedOrg; + bool isLoading = false; + if (state is OrganizationLoaded) { - final orgs = state.organizations; - return Column( - children: [ - Row( - children: [ - ...orgs.map( - (org) => Row( - children: [ - _buildOrgButton( - org, - org.id == state.selectedOrg?.id, - () { - context.read().add( - SelectOrganization(org.id), - ); - }, - ), - const SizedBox(width: 16), - ], - ), - ), - _buildAddButton(() => _showCreateOrgDialog(context)), - ], - ), - const Divider(height: 1), - ], - ); - } else { - return const SizedBox.shrink(); + orgs = state.organizations; + selectedOrg = state.selectedOrg; + isLoading = state.isLoading; + } else if (state is OrganizationLoading) { + isLoading = true; } + + return Column( + children: [ + Row( + children: [ + ...orgs.map( + (org) => Row( + children: [ + _buildOrgButton(org, org.id == selectedOrg?.id, () { + context.read().add( + SelectOrganization(org.id), + ); + }), + const SizedBox(width: 16), + ], + ), + ), + if (isLoading) + SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation( + AppTheme.accentColor, + ), + ), + ) + else + _buildAddButton(() => _showCreateOrgDialog(context)), + ], + ), + const Divider(height: 1), + ], + ); }, ); }