mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-15 12:42:14 -04:00
more refactor
This commit is contained in:
parent
7cf44ef192
commit
20047a956f
14 changed files with 113 additions and 732 deletions
|
@ -9,8 +9,8 @@ import '../../tools/tools.dart';
|
|||
import 'home_account_invalid.dart';
|
||||
import 'home_account_locked.dart';
|
||||
import 'home_account_missing.dart';
|
||||
import 'home_account_ready.dart';
|
||||
import 'home_account_ready/home_account_ready.dart';
|
||||
import 'home_no_active.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
@ -40,9 +40,11 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
|
||||
Widget buildWithLogin(BuildContext context, IList<LocalAccount> localAccounts,
|
||||
Typed<FixedEncodedString43>? activeUserLogin) {
|
||||
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
||||
|
||||
if (activeUserLogin == null) {
|
||||
// If no logged in user is active, show the loading panel
|
||||
return waitingPage(context);
|
||||
return const HomeNoActive();
|
||||
}
|
||||
|
||||
final accountInfo = AccountRepository.instance
|
||||
|
@ -72,8 +74,6 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
|
||||
return SafeArea(
|
||||
child: GestureDetector(
|
||||
|
@ -81,7 +81,6 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scale.primaryScale.activeElementBackground),
|
||||
child:
|
||||
buildWithLogin(context, localAccounts, activeUserLogin))));
|
||||
child: buildWithLogin(context))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
@ -14,23 +14,16 @@ import '../../../contact_invitation/contact_invitation.dart';
|
|||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../../theme/theme.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
import 'main_pager/main_pager.dart';
|
||||
|
||||
class HomeAccountReady extends StatefulWidget {
|
||||
const HomeAccountReady(
|
||||
{required IList<LocalAccount> localAccounts,
|
||||
required TypedKey activeUserLogin,
|
||||
required ActiveAccountInfo activeAccountInfo,
|
||||
required proto.Account account,
|
||||
{required ActiveAccountInfo activeAccountInfo,
|
||||
required Account account,
|
||||
super.key})
|
||||
: _localAccounts = localAccounts,
|
||||
_activeUserLogin = activeUserLogin,
|
||||
_activeAccountInfo = activeAccountInfo,
|
||||
_account = account;
|
||||
: _accountReadyContext = accountReadyContext;
|
||||
|
||||
final IList<LocalAccount> _localAccounts;
|
||||
final TypedKey _activeUserLogin;
|
||||
final ActiveAccountInfo _activeAccountInfo;
|
||||
final proto.Account _account;
|
||||
final AccountReadyContext _accountReadyContext;
|
||||
|
||||
@override
|
||||
HomeAccountReadyState createState() => HomeAccountReadyState();
|
||||
|
@ -52,7 +45,7 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||
Future.delayed(Duration.zero, () async {
|
||||
//
|
||||
final cir = await ContactInvitationRepository.open(
|
||||
widget._activeAccountInfo, widget._account);
|
||||
widget.activeAccountInfo, widget._accountReadyContext.account);
|
||||
|
||||
setState(() {
|
||||
_contactInvitationRepository = cir;
|
||||
|
@ -66,15 +59,6 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||
_contactInvitationRepository?.dispose();
|
||||
}
|
||||
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget buildAccountList() {
|
||||
return const Column(children: [
|
||||
Center(child: Text('Small Profile')),
|
||||
Center(child: Text('Contact invitations')),
|
||||
Center(child: Text('Contacts'))
|
||||
]);
|
||||
}
|
||||
|
||||
Widget buildUnlockAccount(
|
||||
BuildContext context,
|
||||
IList<LocalAccount> localAccounts,
|
||||
|
@ -83,141 +67,66 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||
return const Center(child: Text('unlock account'));
|
||||
}
|
||||
|
||||
/// We have an active, unlocked, user login
|
||||
Widget buildReadyAccount(
|
||||
BuildContext context,
|
||||
IList<LocalAccount> localAccounts,
|
||||
TypedKey activeUserLogin,
|
||||
DHTRecord accountRecord) {
|
||||
Widget buildUserPanel(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
|
||||
xxx get rid of the cubit here and
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => AccountRecordCubit(record: accountRecord),
|
||||
child: Column(children: <Widget>[
|
||||
Row(children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings),
|
||||
color: scale.secondaryScale.text,
|
||||
constraints: const BoxConstraints.expand(height: 64, width: 64),
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.all(scale.secondaryScale.border),
|
||||
shape: MaterialStateProperty.all(
|
||||
const RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(16))))),
|
||||
tooltip: translate('app_bar.settings_tooltip'),
|
||||
onPressed: () async {
|
||||
context.go('/home/settings');
|
||||
}).paddingLTRB(0, 0, 8, 0),
|
||||
context
|
||||
.watch<AccountRecordCubit>()
|
||||
.state
|
||||
.builder((context, account) => ProfileWidget(
|
||||
name: account.profile.name,
|
||||
pronouns: account.profile.pronouns,
|
||||
))
|
||||
.expanded(),
|
||||
]).paddingAll(8),
|
||||
context
|
||||
.watch<AccountRecordCubit>()
|
||||
.state
|
||||
.builder((context, account) => MainPager(
|
||||
localAccounts: localAccounts,
|
||||
activeUserLogin: activeUserLogin,
|
||||
account: account))
|
||||
.expanded()
|
||||
]));
|
||||
return Column(children: <Widget>[
|
||||
Row(children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings),
|
||||
color: scale.secondaryScale.text,
|
||||
constraints: const BoxConstraints.expand(height: 64, width: 64),
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.all(scale.secondaryScale.border),
|
||||
shape: MaterialStateProperty.all(const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(16))))),
|
||||
tooltip: translate('app_bar.settings_tooltip'),
|
||||
onPressed: () async {
|
||||
context.go('/home/settings');
|
||||
}).paddingLTRB(0, 0, 8, 0),
|
||||
ProfileWidget(
|
||||
name: widget._accountReadyContext.account.profile.name,
|
||||
pronouns: widget._accountReadyContext.account.profile.pronouns,
|
||||
).expanded(),
|
||||
]).paddingAll(8),
|
||||
MainPager().expanded()
|
||||
]);
|
||||
}
|
||||
|
||||
xxx get rid of this whole function
|
||||
Widget buildPhone(BuildContext context) =>
|
||||
Material(color: Colors.transparent, child: buildUserPanel(context));
|
||||
|
||||
Widget buildUserPanel() => Builder(builder: (context) {
|
||||
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
Widget buildTabletLeftPane(BuildContext context) => Builder(
|
||||
builder: (context) =>
|
||||
Material(color: Colors.transparent, child: buildUserPanel(context)));
|
||||
|
||||
if (activeUserLogin == null) {
|
||||
// If no logged in user is active, show the loading panel
|
||||
return waitingPage(context);
|
||||
}
|
||||
|
||||
final account = AccountRepository.instance
|
||||
.getAccountInfo(accountMasterRecordKey: activeUserLogin)!;
|
||||
|
||||
switch (account.status) {
|
||||
case AccountInfoStatus.noAccount:
|
||||
Future.delayed(0.ms, () async {
|
||||
await showErrorModal(
|
||||
context,
|
||||
translate('home.missing_account_title'),
|
||||
translate('home.missing_account_text'));
|
||||
// Delete account
|
||||
await AccountRepository.instance
|
||||
.deleteLocalAccount(activeUserLogin);
|
||||
// Switch to no active user login
|
||||
await AccountRepository.instance.switchToAccount(null);
|
||||
});
|
||||
return waitingPage(context);
|
||||
case AccountInfoStatus.accountInvalid:
|
||||
Future.delayed(0.ms, () async {
|
||||
await showErrorModal(
|
||||
context,
|
||||
translate('home.invalid_account_title'),
|
||||
translate('home.invalid_account_text'));
|
||||
// Delete account
|
||||
await AccountRepository.instance
|
||||
.deleteLocalAccount(activeUserLogin);
|
||||
// Switch to no active user login
|
||||
await AccountRepository.instance.switchToAccount(null);
|
||||
});
|
||||
return waitingPage(context);
|
||||
case AccountInfoStatus.accountLocked:
|
||||
// Show unlock widget
|
||||
return buildUnlockAccount(context, localAccounts);
|
||||
case AccountInfoStatus.accountReady:
|
||||
return buildReadyAccount(
|
||||
context,
|
||||
localAccounts,
|
||||
activeUserLogin,
|
||||
account.activeAccountInfo!.accountRecord,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Widget buildPhone() =>
|
||||
Material(color: Colors.transparent, child: buildUserPanel());
|
||||
|
||||
Widget buildTabletLeftPane() =>
|
||||
Material(color: Colors.transparent, child: buildUserPanel());
|
||||
|
||||
Widget buildTabletRightPane() => buildChatComponent();
|
||||
Widget buildTabletRightPane(BuildContext context) => buildChatComponent();
|
||||
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget buildTablet() => Builder(builder: (context) {
|
||||
final w = MediaQuery.of(context).size.width;
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
Widget buildTablet(BuildContext context) {
|
||||
final w = MediaQuery.of(context).size.width;
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
|
||||
final children = [
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 300, maxWidth: 300),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: w / 2),
|
||||
child: buildTabletLeftPane())),
|
||||
SizedBox(
|
||||
width: 2,
|
||||
height: double.infinity,
|
||||
child: ColoredBox(color: scale.primaryScale.hoverBorder)),
|
||||
Expanded(child: buildTabletRightPane()),
|
||||
];
|
||||
final children = [
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 300, maxWidth: 300),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: w / 2),
|
||||
child: buildTabletLeftPane(context))),
|
||||
SizedBox(
|
||||
width: 2,
|
||||
height: double.infinity,
|
||||
child: ColoredBox(color: scale.primaryScale.hoverBorder)),
|
||||
Expanded(child: buildTabletRightPane(context)),
|
||||
];
|
||||
|
||||
return Row(
|
||||
children: children,
|
||||
);
|
||||
});
|
||||
return Row(
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -225,11 +134,13 @@ xxx get rid of this whole function
|
|||
return waitingPage(context);
|
||||
}
|
||||
|
||||
return responsiveVisibility(
|
||||
context: context,
|
||||
phone: false,
|
||||
)
|
||||
? buildTablet()
|
||||
: buildPhone();
|
||||
return RepositoryProvider.value(
|
||||
value: _contactInvitationRepository,
|
||||
child: responsiveVisibility(
|
||||
context: context,
|
||||
phone: false,
|
||||
)
|
||||
? buildTablet(context)
|
||||
: buildPhone(context));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,34 +5,17 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../../account_manager/account_manager.dart';
|
||||
import '../../../../proto/proto.dart' as proto;
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../contacts/contacts.dart';
|
||||
import '../../../theme/theme.dart';
|
||||
import '../../../../theme/theme.dart';
|
||||
|
||||
class AccountPage extends StatefulWidget {
|
||||
const AccountPage({
|
||||
required this.localAccounts,
|
||||
required this.activeUserLogin,
|
||||
required this.account,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final IList<LocalAccount> localAccounts;
|
||||
final TypedKey activeUserLogin;
|
||||
final proto.Account account;
|
||||
|
||||
@override
|
||||
AccountPageState createState() => AccountPageState();
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(IterableProperty<LocalAccount>('localAccounts', localAccounts))
|
||||
..add(DiagnosticsProperty<TypedKey>('activeUserLogin', activeUserLogin))
|
||||
..add(DiagnosticsProperty<proto.Account>('account', account));
|
||||
}
|
||||
}
|
||||
|
||||
class AccountPageState extends State<AccountPage> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue