orgs impl
This commit is contained in:
@@ -6,9 +6,8 @@ import '../blocs/auth/auth_bloc.dart';
|
||||
import '../blocs/auth/auth_state.dart';
|
||||
import '../blocs/organization/organization_bloc.dart';
|
||||
import '../blocs/organization/organization_event.dart';
|
||||
import '../blocs/permission/permission_bloc.dart';
|
||||
import '../blocs/file_browser/file_browser_bloc.dart';
|
||||
import '../blocs/upload/upload_bloc.dart';
|
||||
import '../blocs/file_browser/file_browser_event.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/modern_glass_button.dart';
|
||||
import 'login_form.dart';
|
||||
@@ -172,92 +171,9 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
Widget _buildDrive(OrganizationState state) {
|
||||
if (state is OrganizationLoaded && state.selectedOrg != null) {
|
||||
return FileExplorer(orgId: state.selectedOrg!.id);
|
||||
} else {
|
||||
return const FileExplorer(orgId: 'org1');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildPersonalContent(OrganizationState state) {
|
||||
if (state is OrganizationLoaded && state.selectedOrg != null) {
|
||||
return FileExplorer(orgId: state.selectedOrg!.id);
|
||||
} else {
|
||||
return const FileExplorer(orgId: 'org1');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildOrganizationsContent(OrganizationState state) {
|
||||
if (state is OrganizationLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is OrganizationError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('Error: ${state.error}'),
|
||||
ElevatedButton(
|
||||
onPressed: () =>
|
||||
context.read<OrganizationBloc>().add(LoadOrganizations()),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (state is OrganizationLoaded) {
|
||||
final orgs = state.organizations;
|
||||
if (orgs.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text('No organizations yet. Create one to get started.'),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => _showCreateOrgDialog(context),
|
||||
child: const Text('+ Add organization'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: orgs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final org = orgs[index];
|
||||
final isCurrent = state.selectedOrg?.id == org.id;
|
||||
return ListTile(
|
||||
title: Text(org.name),
|
||||
subtitle: isCurrent ? const Text('(current)') : null,
|
||||
trailing: isCurrent
|
||||
? null
|
||||
: TextButton(
|
||||
onPressed: () {
|
||||
context.read<OrganizationBloc>().add(
|
||||
SelectOrganization(org.id),
|
||||
);
|
||||
},
|
||||
child: const Text('Switch'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _showCreateOrgDialog(context),
|
||||
child: const Text('+ Add organization'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(child: Text('Loading organizations...'));
|
||||
}
|
||||
return state is OrganizationLoaded && state.selectedOrg != null
|
||||
? FileExplorer(orgId: state.selectedOrg!.id)
|
||||
: const FileExplorer(orgId: 'org1');
|
||||
}
|
||||
|
||||
Widget _buildNavButton(String label, IconData icon, {bool isAvatar = false}) {
|
||||
@@ -333,30 +249,53 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
||||
Container(
|
||||
decoration: AppTheme.glassDecoration,
|
||||
child: isLoggedIn
|
||||
? BlocBuilder<
|
||||
? BlocListener<
|
||||
OrganizationBloc,
|
||||
OrganizationState
|
||||
>(
|
||||
builder: (context, orgState) {
|
||||
if (orgState is OrganizationInitial) {
|
||||
WidgetsBinding.instance
|
||||
.addPostFrameCallback((_) {
|
||||
context
|
||||
.read<OrganizationBloc>()
|
||||
.add(LoadOrganizations());
|
||||
});
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
_buildOrgRow(context),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: _buildDrive(orgState),
|
||||
listener: (context, state) {
|
||||
if (state is OrganizationLoaded &&
|
||||
state.selectedOrg != null) {
|
||||
// Reload file browser when org changes
|
||||
context.read<FileBrowserBloc>().add(
|
||||
LoadDirectory(
|
||||
orgId: state.selectedOrg!.id,
|
||||
path: '/',
|
||||
),
|
||||
],
|
||||
);
|
||||
);
|
||||
}
|
||||
},
|
||||
child:
|
||||
BlocBuilder<
|
||||
OrganizationBloc,
|
||||
OrganizationState
|
||||
>(
|
||||
builder: (context, orgState) {
|
||||
if (orgState
|
||||
is OrganizationInitial) {
|
||||
WidgetsBinding.instance
|
||||
.addPostFrameCallback((_) {
|
||||
context
|
||||
.read<
|
||||
OrganizationBloc
|
||||
>()
|
||||
.add(
|
||||
LoadOrganizations(),
|
||||
);
|
||||
});
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
_buildOrgRow(context),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: _buildDrive(orgState),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: const LoginForm(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user