add copy constructor and properly update paynym account model, as well as fix desktop navigation on follow/unfollow

This commit is contained in:
julian 2023-01-04 14:56:36 -06:00
parent 929723d0d5
commit d957cad4ba
2 changed files with 39 additions and 16 deletions

View file

@ -36,6 +36,22 @@ class PaynymAccount {
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map))) PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(); .toList();
PaynymAccount copyWith({
String? nymID,
String? nymName,
List<PaynymCode>? codes,
List<PaynymAccountLite>? followers,
List<PaynymAccountLite>? following,
}) {
return PaynymAccount(
nymID ?? this.nymID,
nymName ?? this.nymName,
codes ?? this.codes,
followers ?? this.followers,
following ?? this.following,
);
}
Map<String, dynamic> toMap() => { Map<String, dynamic> toMap() => {
"nymID": nymID, "nymID": nymID,
"nymName": nymName, "nymName": nymName,

View file

@ -87,7 +87,7 @@ class _PaynymFollowToggleButtonState
if (result.value!.following == followedAccount.value!.nymID) { if (result.value!.following == followedAccount.value!.nymID) {
if (!loadingPopped && mounted) { if (!loadingPopped && mounted) {
Navigator.of(context).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
} }
unawaited( unawaited(
@ -97,14 +97,19 @@ class _PaynymFollowToggleButtonState
context: context, context: context,
), ),
); );
ref.read(myPaynymAccountStateProvider.state).state!.following.add(
PaynymAccountLite( final myAccount = ref.read(myPaynymAccountStateProvider.state).state!;
followedAccount.value!.nymID,
followedAccount.value!.nymName, myAccount.following.add(
followedAccount.value!.codes.first.code, PaynymAccountLite(
followedAccount.value!.codes.first.segwit, followedAccount.value!.nymID,
), followedAccount.value!.nymName,
); followedAccount.value!.codes.first.code,
followedAccount.value!.codes.first.segwit,
),
);
ref.read(myPaynymAccountStateProvider.state).state = myAccount.copyWith();
setState(() { setState(() {
isFollowing = true; isFollowing = true;
@ -113,7 +118,7 @@ class _PaynymFollowToggleButtonState
return true; return true;
} else { } else {
if (!loadingPopped && mounted) { if (!loadingPopped && mounted) {
Navigator.of(context).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
} }
unawaited( unawaited(
@ -181,7 +186,7 @@ class _PaynymFollowToggleButtonState
if (result.value!.unfollowing == followedAccount.value!.nymID) { if (result.value!.unfollowing == followedAccount.value!.nymID) {
if (!loadingPopped && mounted) { if (!loadingPopped && mounted) {
Navigator.of(context).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
} }
unawaited( unawaited(
@ -191,12 +196,14 @@ class _PaynymFollowToggleButtonState
context: context, context: context,
), ),
); );
ref
.read(myPaynymAccountStateProvider.state) final myAccount = ref.read(myPaynymAccountStateProvider.state).state!;
.state!
.following myAccount.following
.removeWhere((e) => e.nymId == followedAccount.value!.nymID); .removeWhere((e) => e.nymId == followedAccount.value!.nymID);
ref.read(myPaynymAccountStateProvider.state).state = myAccount.copyWith();
setState(() { setState(() {
isFollowing = false; isFollowing = false;
}); });
@ -204,7 +211,7 @@ class _PaynymFollowToggleButtonState
return true; return true;
} else { } else {
if (!loadingPopped && mounted) { if (!loadingPopped && mounted) {
Navigator.of(context).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
} }
unawaited( unawaited(