mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-14 12:12:27 -04:00
chat refactor
This commit is contained in:
parent
4a8958a868
commit
03a6a781a6
18 changed files with 239 additions and 333 deletions
|
@ -6,6 +6,8 @@ import 'package:flutter_translate/flutter_translate.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../chat/chat.dart';
|
||||
import '../../../chat_list/chat_list.dart';
|
||||
import '../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../theme/theme.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
|
@ -106,9 +108,18 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||
return waitingPage(context);
|
||||
}
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => ContactInvitationListCubit(
|
||||
activeAccountInfo: activeAccountInfo, account: accountData.value),
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => ContactInvitationListCubit(
|
||||
activeAccountInfo: activeAccountInfo,
|
||||
account: accountData.value)),
|
||||
BlocProvider(
|
||||
create: (context) => ChatListCubit(
|
||||
activeAccountInfo: activeAccountInfo,
|
||||
account: accountData.value)),
|
||||
BlocProvider(create: (context) => ActiveChatCubit(null))
|
||||
],
|
||||
child: responsiveVisibility(
|
||||
context: context,
|
||||
phone: false,
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../../contacts/contacts.dart';
|
||||
import '../../../../theme/theme.dart';
|
||||
|
||||
class AccountPage extends StatefulWidget {
|
||||
|
|
|
@ -27,14 +27,9 @@ class ChatsPageState extends State<ChatsPage> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
/// We have an active, unlocked, user login
|
||||
Widget buildChatList(
|
||||
BuildContext context,
|
||||
IList<LocalAccount> localAccounts,
|
||||
TypedKey activeUserLogin,
|
||||
proto.Account account,
|
||||
// ignore: prefer_expression_function_bodies
|
||||
) {
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(BuildContext context) {
|
||||
final contactList = ref.watch(fetchContactListProvider).asData?.value ??
|
||||
const IListConst([]);
|
||||
final chatList =
|
||||
|
@ -47,45 +42,4 @@ class ChatsPageState extends State<ChatsPage> {
|
|||
.expanded(),
|
||||
if (chatList.isEmpty) const EmptyChatListWidget().expanded(),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(BuildContext context) {
|
||||
final localAccountsV = ref.watch(localAccountsProvider);
|
||||
final loginsV = ref.watch(loginsProvider);
|
||||
|
||||
if (!localAccountsV.hasValue || !loginsV.hasValue) {
|
||||
return waitingPage(context);
|
||||
}
|
||||
final localAccounts = localAccountsV.requireValue;
|
||||
final logins = loginsV.requireValue;
|
||||
|
||||
final activeUserLogin = logins.activeUserLogin;
|
||||
if (activeUserLogin == null) {
|
||||
// If no logged in user is active show a placeholder
|
||||
return waitingPage(context);
|
||||
}
|
||||
final accountV = ref
|
||||
.watch(fetchAccountProvider(accountMasterRecordKey: activeUserLogin));
|
||||
if (!accountV.hasValue) {
|
||||
return waitingPage(context);
|
||||
}
|
||||
final account = accountV.requireValue;
|
||||
switch (account.status) {
|
||||
case AccountInfoStatus.noAccount:
|
||||
return waitingPage(context);
|
||||
case AccountInfoStatus.accountInvalid:
|
||||
return waitingPage(context);
|
||||
case AccountInfoStatus.accountLocked:
|
||||
return waitingPage(context);
|
||||
case AccountInfoStatus.accountReady:
|
||||
return buildChatList(
|
||||
context,
|
||||
localAccounts,
|
||||
activeUserLogin,
|
||||
account.account!,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue