mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-12 11:12:19 -04:00
checkpoint
This commit is contained in:
parent
c40f835ec5
commit
aea196deb3
7 changed files with 371 additions and 177 deletions
|
@ -105,7 +105,8 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||
Widget _getAccountList(
|
||||
{required IList<LocalAccount> localAccounts,
|
||||
required TypedKey? activeLocalAccount,
|
||||
required AccountRecordsBlocMapState accountRecords}) {
|
||||
required PerAccountCollectionBlocMapState
|
||||
perAccountCollectionBlocMapState}) {
|
||||
final theme = Theme.of(context);
|
||||
final scaleScheme = theme.extension<ScaleScheme>()!;
|
||||
|
||||
|
@ -116,11 +117,13 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||
final superIdentityRecordKey = la.superIdentity.recordKey;
|
||||
|
||||
// See if this account is logged in
|
||||
final acctRecord = accountRecords.get(superIdentityRecordKey);
|
||||
if (acctRecord != null) {
|
||||
final avAccountRecordState = perAccountCollectionBlocMapState
|
||||
.get(superIdentityRecordKey)
|
||||
?.avAccountRecordState;
|
||||
if (avAccountRecordState != null) {
|
||||
// Account is logged in
|
||||
final scale = theme.extension<ScaleScheme>()!.tertiaryScale;
|
||||
final loggedInAccount = acctRecord.when(
|
||||
final loggedInAccount = avAccountRecordState.when(
|
||||
data: (value) => _makeAccountWidget(
|
||||
name: value.profile.name,
|
||||
scale: scale,
|
||||
|
@ -233,7 +236,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||
final scale = theme.extension<ScaleScheme>()!;
|
||||
//final textTheme = theme.textTheme;
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
final accountRecords =
|
||||
final perAccountCollectionBlocMapState =
|
||||
context.watch<PerAccountCollectionBlocMapCubit>().state;
|
||||
final activeLocalAccount = context.watch<ActiveLocalAccountCubit>().state;
|
||||
final gradient = LinearGradient(
|
||||
|
@ -278,7 +281,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||
_getAccountList(
|
||||
localAccounts: localAccounts,
|
||||
activeLocalAccount: activeLocalAccount,
|
||||
accountRecords: accountRecords),
|
||||
perAccountCollectionBlocMapState: perAccountCollectionBlocMapState),
|
||||
_getBottomButtons(),
|
||||
const Spacer(),
|
||||
Row(children: [
|
||||
|
|
|
@ -9,11 +9,8 @@ import 'package:veilid_support/veilid_support.dart';
|
|||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../chat/chat.dart';
|
||||
import '../../chat_list/chat_list.dart';
|
||||
import '../../contact_invitation/contact_invitation.dart';
|
||||
import '../../contacts/contacts.dart';
|
||||
import '../../conversation/conversation.dart';
|
||||
import '../../proto/proto.dart' as proto;
|
||||
import '../../theme/theme.dart';
|
||||
import '../../tools/tools.dart';
|
||||
import 'active_account_page_controller_wrapper.dart';
|
||||
|
@ -98,113 +95,39 @@ class HomeScreenState extends State<HomeScreen> {
|
|||
return const HomeAccountReadyMain();
|
||||
}
|
||||
|
||||
Widget _buildUnlockedAccount(BuildContext context) {
|
||||
final accountRecordKey = context.select<AccountInfoCubit, TypedKey>(
|
||||
(c) => c.state.unlockedAccountInfo!.accountRecordKey);
|
||||
final contactListRecordPointer =
|
||||
context.select<AccountRecordCubit, OwnedDHTRecordPointer?>(
|
||||
(c) => c.state.asData?.value.contactList.toVeilid());
|
||||
final contactInvitationListRecordPointer =
|
||||
context.select<AccountRecordCubit, OwnedDHTRecordPointer?>(
|
||||
(c) => c.state.asData?.value.contactInvitationRecords.toVeilid());
|
||||
final chatListRecordPointer =
|
||||
context.select<AccountRecordCubit, OwnedDHTRecordPointer?>(
|
||||
(c) => c.state.asData?.value.chatList.toVeilid());
|
||||
Widget _buildAccount(BuildContext context, TypedKey superIdentityRecordKey,
|
||||
PerAccountCollectionState perAccountCollectionState) {
|
||||
switch (perAccountCollectionState.accountInfo.status) {
|
||||
case AccountInfoStatus.accountInvalid:
|
||||
return const HomeAccountInvalid();
|
||||
case AccountInfoStatus.accountLocked:
|
||||
return const HomeAccountLocked();
|
||||
case AccountInfoStatus.accountUnlocked:
|
||||
// Are we ready to render?
|
||||
if (!perAccountCollectionState.isReady) {
|
||||
return waitingPage();
|
||||
}
|
||||
|
||||
if (contactListRecordPointer == null ||
|
||||
contactInvitationListRecordPointer == null ||
|
||||
chatListRecordPointer == null) {
|
||||
return waitingPage();
|
||||
}
|
||||
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
// Contact Cubits
|
||||
BlocProvider(
|
||||
create: (context) => ContactInvitationListCubit(
|
||||
locator: context.read,
|
||||
accountRecordKey: accountRecordKey,
|
||||
contactInvitationListRecordPointer:
|
||||
contactInvitationListRecordPointer,
|
||||
)),
|
||||
BlocProvider(
|
||||
create: (context) => ContactListCubit(
|
||||
locator: context.read,
|
||||
accountRecordKey: accountRecordKey,
|
||||
contactListRecordPointer: contactListRecordPointer)),
|
||||
BlocProvider(
|
||||
create: (context) => WaitingInvitationsBlocMapCubit(
|
||||
locator: context.read,
|
||||
)),
|
||||
// Chat Cubits
|
||||
BlocProvider(
|
||||
create: (context) => ActiveChatCubit(
|
||||
null,
|
||||
)),
|
||||
BlocProvider(
|
||||
create: (context) => ChatListCubit(
|
||||
locator: context.read,
|
||||
accountRecordKey: accountRecordKey,
|
||||
chatListRecordPointer: chatListRecordPointer)),
|
||||
// Conversation Cubits
|
||||
BlocProvider(
|
||||
create: (context) => ActiveConversationsBlocMapCubit(
|
||||
locator: context.read,
|
||||
)),
|
||||
BlocProvider(
|
||||
create: (context) => ActiveSingleContactChatBlocMapCubit(
|
||||
locator: context.read,
|
||||
)),
|
||||
],
|
||||
child: MultiBlocListener(listeners: [
|
||||
// Re-export all ready blocs to the account display subtree
|
||||
return perAccountCollectionState.provide(
|
||||
child: MultiBlocListener(listeners: [
|
||||
BlocListener<WaitingInvitationsBlocMapCubit,
|
||||
WaitingInvitationsBlocMapState>(
|
||||
listener: _invitationStatusListener,
|
||||
)
|
||||
], child: Builder(builder: _buildAccountReadyDeviceSpecific)));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildAccount(BuildContext context, TypedKey superIdentityRecordKey,
|
||||
PerAccountCollectionCubit perAccountCollectionCubit) =>
|
||||
BlocBuilder<PerAccountCollectionCubit, PerAccountCollectionState>(
|
||||
key: ValueKey(superIdentityRecordKey),
|
||||
bloc: perAccountCollectionCubit,
|
||||
builder: (context, state) {
|
||||
|
||||
|
||||
switch (state.accountInfo.status) {
|
||||
case AccountInfoStatus.accountInvalid:
|
||||
return const HomeAccountInvalid();
|
||||
case AccountInfoStatus.accountLocked:
|
||||
return const HomeAccountLocked();
|
||||
case AccountInfoStatus.accountUnlocked:
|
||||
|
||||
// Get the current active account record cubit
|
||||
final activeAccountRecordCubit = context.select<
|
||||
PerAccountCollectionBlocMapCubit,
|
||||
AccountRecordCubit?>(
|
||||
(c) => c.tryOperate(superIdentityRecordKey,
|
||||
closure: (x) => x));
|
||||
if (activeAccountRecordCubit == null) {
|
||||
return waitingPage();
|
||||
}
|
||||
|
||||
return MultiBlocProvider(providers: [
|
||||
BlocProvider<AccountRecordCubit>.value(
|
||||
value: activeAccountRecordCubit),
|
||||
], child: Builder(builder: _buildUnlockedAccount));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Widget _buildAccountPageView(BuildContext context) {
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
final activeLocalAccountCubit = context.watch<ActiveLocalAccountCubit>();
|
||||
final perAccountCollectionBlocMapCubit =
|
||||
context.watch<PerAccountCollectionBlocMapCubit>();
|
||||
final activeLocalAccountCubit =
|
||||
context.watch<ActiveLocalAccountCubit>().state;
|
||||
final perAccountCollectionBlocMapState =
|
||||
context.watch<PerAccountCollectionBlocMapCubit>().state;
|
||||
|
||||
final activeIndex = localAccounts.indexWhere(
|
||||
(x) => x.superIdentity.recordKey == activeLocalAccountCubit.state);
|
||||
(x) => x.superIdentity.recordKey == activeLocalAccountCubit);
|
||||
if (activeIndex == -1) {
|
||||
return const HomeNoActive();
|
||||
}
|
||||
|
@ -231,16 +154,15 @@ class HomeScreenState extends State<HomeScreen> {
|
|||
itemBuilder: (context, index) {
|
||||
final superIdentityRecordKey =
|
||||
localAccounts[index].superIdentity.recordKey;
|
||||
final perAccountCollectionCubit =
|
||||
perAccountCollectionBlocMapCubit.tryOperate(
|
||||
superIdentityRecordKey,
|
||||
closure: (c) => c);
|
||||
if (perAccountCollectionCubit == null) {
|
||||
final perAccountCollectionState =
|
||||
perAccountCollectionBlocMapState
|
||||
.get(superIdentityRecordKey);
|
||||
if (perAccountCollectionState == null) {
|
||||
return HomeAccountMissing(
|
||||
key: ValueKey(superIdentityRecordKey));
|
||||
}
|
||||
return _buildAccount(context, superIdentityRecordKey,
|
||||
perAccountCollectionCubit);
|
||||
perAccountCollectionState);
|
||||
})));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue