mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-14 08:55:26 -04:00
add multiple accounts menu
This commit is contained in:
parent
b0d4e35c6f
commit
87bb1657c7
25 changed files with 583 additions and 70 deletions
|
@ -4,7 +4,9 @@ import 'package:veilid_support/veilid_support.dart';
|
|||
|
||||
import '../../proto/proto.dart' as proto;
|
||||
|
||||
class AccountRecordCubit extends DefaultDHTRecordCubit<proto.Account> {
|
||||
typedef AccountRecordState = proto.Account;
|
||||
|
||||
class AccountRecordCubit extends DefaultDHTRecordCubit<AccountRecordState> {
|
||||
AccountRecordCubit({
|
||||
required super.open,
|
||||
}) : super(decodeState: proto.Account.fromBuffer);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:bloc_advanced_tools/bloc_advanced_tools.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
|
||||
typedef AccountRecordsBlocMapState
|
||||
= BlocMapState<TypedKey, AsyncValue<AccountRecordState>>;
|
||||
|
||||
// Map of the logged in user accounts to their account information
|
||||
class AccountRecordsBlocMapCubit extends BlocMapCubit<TypedKey,
|
||||
AsyncValue<AccountRecordState>, AccountRecordCubit>
|
||||
with StateMapFollower<UserLoginsState, TypedKey, UserLogin> {
|
||||
AccountRecordsBlocMapCubit(AccountRepository accountRepository)
|
||||
: _accountRepository = accountRepository;
|
||||
|
||||
// Add account record cubit
|
||||
Future<void> _addAccountRecordCubit({required UserLogin userLogin}) async =>
|
||||
add(() => MapEntry(
|
||||
userLogin.superIdentityRecordKey,
|
||||
AccountRecordCubit(
|
||||
open: () => _accountRepository.openAccountRecord(userLogin))));
|
||||
|
||||
/// StateFollower /////////////////////////
|
||||
|
||||
@override
|
||||
Future<void> removeFromState(TypedKey key) => remove(key);
|
||||
|
||||
@override
|
||||
Future<void> updateState(TypedKey key, UserLogin value) async {
|
||||
await _addAccountRecordCubit(userLogin: value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
final AccountRepository _accountRepository;
|
||||
}
|
|
@ -3,7 +3,7 @@ import 'dart:async';
|
|||
import 'package:bloc/bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../repository/account_repository/account_repository.dart';
|
||||
import '../repository/account_repository.dart';
|
||||
|
||||
class ActiveLocalAccountCubit extends Cubit<TypedKey?> {
|
||||
ActiveLocalAccountCubit(AccountRepository accountRepository)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export 'account_record_cubit.dart';
|
||||
export 'account_records_bloc_map_cubit.dart';
|
||||
export 'active_local_account_cubit.dart';
|
||||
export 'local_accounts_cubit.dart';
|
||||
export 'user_logins_cubit.dart';
|
||||
|
|
|
@ -4,7 +4,7 @@ import 'package:bloc/bloc.dart';
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
|
||||
import '../models/models.dart';
|
||||
import '../repository/account_repository/account_repository.dart';
|
||||
import '../repository/account_repository.dart';
|
||||
|
||||
class LocalAccountsCubit extends Cubit<IList<LocalAccount>> {
|
||||
LocalAccountsCubit(AccountRepository accountRepository)
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:bloc_advanced_tools/bloc_advanced_tools.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../models/models.dart';
|
||||
import '../repository/account_repository/account_repository.dart';
|
||||
import '../repository/account_repository.dart';
|
||||
|
||||
class UserLoginsCubit extends Cubit<IList<UserLogin>> {
|
||||
typedef UserLoginsState = IList<UserLogin>;
|
||||
|
||||
class UserLoginsCubit extends Cubit<UserLoginsState>
|
||||
with StateMapFollowable<UserLoginsState, TypedKey, UserLogin> {
|
||||
UserLoginsCubit(AccountRepository accountRepository)
|
||||
: _accountRepository = accountRepository,
|
||||
super(accountRepository.getUserLogins()) {
|
||||
|
@ -30,6 +35,16 @@ class UserLoginsCubit extends Cubit<IList<UserLogin>> {
|
|||
await _accountRepositorySubscription.cancel();
|
||||
}
|
||||
|
||||
/// StateMapFollowable /////////////////////////
|
||||
@override
|
||||
IMap<TypedKey, UserLogin> getStateMap(UserLoginsState state) {
|
||||
final stateValue = state;
|
||||
return IMap.fromIterable(stateValue,
|
||||
keyMapper: (e) => e.superIdentityRecordKey, valueMapper: (e) => e);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
final AccountRepository _accountRepository;
|
||||
late final StreamSubscription<AccountRepositoryChange>
|
||||
_accountRepositorySubscription;
|
||||
|
|
|
@ -3,9 +3,9 @@ import 'dart:async';
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../../proto/proto.dart' as proto;
|
||||
import '../../../tools/tools.dart';
|
||||
import '../../models/models.dart';
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../tools/tools.dart';
|
||||
import '../models/models.dart';
|
||||
|
||||
const String veilidChatAccountKey = 'com.veilid.veilidchat';
|
||||
|
|
@ -1 +1 @@
|
|||
export 'account_repository/account_repository.dart';
|
||||
export 'account_repository.dart';
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../proto/proto.dart' as proto;
|
||||
import '../../theme/theme.dart';
|
||||
import '../account_manager.dart';
|
||||
|
||||
class SwitchAccountWidget extends StatelessWidget {
|
||||
const SwitchAccountWidget({
|
||||
super.key,
|
||||
});
|
||||
//
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
final textTheme = theme.textTheme;
|
||||
|
||||
final accountRepo = AccountRepository.instance;
|
||||
final localAccounts = accountRepo.getLocalAccounts();
|
||||
for (final la in localAccounts) {
|
||||
//
|
||||
}
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: ShapeDecoration(
|
||||
color: scale.primaryScale.border,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16))),
|
||||
child: Column(children: []),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue