From 1fd042bcae52c1f66e4d1d15dd39083550e49b9c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 8 Sep 2024 01:48:01 +0800 Subject: [PATCH] :bug: Bug fixes on profile page --- lib/models/account.dart | 34 +++++++++++++++++ lib/models/account.g.dart | 38 +++++++++++++++++++ lib/screens/account/profile_page.dart | 10 ++--- lib/screens/dashboard.dart | 5 ++- .../attachments/attachment_fullscreen.dart | 6 +-- 5 files changed, 83 insertions(+), 10 deletions(-) diff --git a/lib/models/account.dart b/lib/models/account.dart index 54c6281..be1534a 100644 --- a/lib/models/account.dart +++ b/lib/models/account.dart @@ -15,6 +15,7 @@ class Account { dynamic avatar; dynamic banner; String description; + AccountProfile? profile; List? badges; String? emailAddress; int? externalId; @@ -31,6 +32,7 @@ class Account { required this.avatar, required this.banner, required this.description, + required this.profile, required this.badges, required this.emailAddress, this.externalId, @@ -67,3 +69,35 @@ class AccountBadge { Map toJson() => _$AccountBadgeToJson(this); } + +@JsonSerializable() +class AccountProfile { + int id; + DateTime createdAt; + DateTime updatedAt; + DateTime? deletedAt; + String? firstName; + String? lastName; + int? experience; + DateTime? lastSeenAt; + DateTime? birthday; + int accountId; + + AccountProfile({ + required this.id, + required this.createdAt, + required this.updatedAt, + required this.deletedAt, + required this.firstName, + required this.lastName, + required this.experience, + required this.lastSeenAt, + required this.birthday, + required this.accountId, + }); + + factory AccountProfile.fromJson(Map json) => + _$AccountProfileFromJson(json); + + Map toJson() => _$AccountProfileToJson(this); +} diff --git a/lib/models/account.g.dart b/lib/models/account.g.dart index 703928b..416ecc7 100644 --- a/lib/models/account.g.dart +++ b/lib/models/account.g.dart @@ -24,6 +24,9 @@ Account _$AccountFromJson(Map json) => Account( avatar: json['avatar'], banner: json['banner'], description: json['description'] as String, + profile: json['profile'] == null + ? null + : AccountProfile.fromJson(json['profile'] as Map), badges: (json['badges'] as List?) ?.map((e) => AccountBadge.fromJson(e as Map)) .toList(), @@ -43,6 +46,7 @@ Map _$AccountToJson(Account instance) => { 'avatar': instance.avatar, 'banner': instance.banner, 'description': instance.description, + 'profile': instance.profile?.toJson(), 'badges': instance.badges?.map((e) => e.toJson()).toList(), 'email_address': instance.emailAddress, 'external_id': instance.externalId, @@ -70,3 +74,37 @@ Map _$AccountBadgeToJson(AccountBadge instance) => 'type': instance.type, 'account_id': instance.accountId, }; + +AccountProfile _$AccountProfileFromJson(Map json) => + AccountProfile( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + firstName: json['first_name'] as String?, + lastName: json['last_name'] as String?, + experience: (json['experience'] as num?)?.toInt(), + lastSeenAt: json['last_seen_at'] == null + ? null + : DateTime.parse(json['last_seen_at'] as String), + birthday: json['birthday'] == null + ? null + : DateTime.parse(json['birthday'] as String), + accountId: (json['account_id'] as num).toInt(), + ); + +Map _$AccountProfileToJson(AccountProfile instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'first_name': instance.firstName, + 'last_name': instance.lastName, + 'experience': instance.experience, + 'last_seen_at': instance.lastSeenAt?.toIso8601String(), + 'birthday': instance.birthday?.toIso8601String(), + 'account_id': instance.accountId, + }; diff --git a/lib/screens/account/profile_page.dart b/lib/screens/account/profile_page.dart index 60d426f..45faed6 100644 --- a/lib/screens/account/profile_page.dart +++ b/lib/screens/account/profile_page.dart @@ -84,10 +84,7 @@ class _AccountProfilePageState extends State { } int get _userSocialCreditPoints { - int birthPart = - DateTime.now().difference(_userinfo!.createdAt.toLocal()).inSeconds; - birthPart = birthPart >> 16; - return _totalUpvote * 2 - _totalDownvote + birthPart; + return _totalUpvote * 2 - _totalDownvote + _postController.postTotal.value; } @override @@ -97,8 +94,9 @@ class _AccountProfilePageState extends State { _postController = PostListController(author: widget.name); _albumPagingController.addPageRequestListener((pageKey) async { final client = ServiceFinder.configureClient('files'); - final resp = await client - .get('/attachments?take=10&offset=$pageKey&author=${widget.name}'); + final resp = await client.get( + '/attachments?take=10&offset=$pageKey&author=${widget.name}&original=true', + ); if (resp.statusCode == 200) { final result = PaginationResult.fromJson(resp.body); final out = result.data diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 9b04ae2..dda2c01 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -23,6 +23,7 @@ import 'package:solian/providers/message/adaptor.dart'; import 'package:solian/providers/websocket.dart'; import 'package:solian/router.dart'; import 'package:solian/screens/account/notification.dart'; +import 'package:solian/theme.dart'; import 'package:solian/widgets/chat/chat_event.dart'; import 'package:solian/widgets/daily_sign/history_chart.dart'; import 'package:solian/widgets/posts/post_list.dart'; @@ -491,7 +492,9 @@ class _DashboardScreenState extends State { /// Footer Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: SolianTheme.isLargeScreen(context) + ? MainAxisAlignment.start + : MainAxisAlignment.center, children: [ Text( 'Powered by Solar Network', diff --git a/lib/widgets/attachments/attachment_fullscreen.dart b/lib/widgets/attachments/attachment_fullscreen.dart index 56dfe52..861447c 100644 --- a/lib/widgets/attachments/attachment_fullscreen.dart +++ b/lib/widgets/attachments/attachment_fullscreen.dart @@ -199,7 +199,7 @@ class _AttachmentFullScreenState extends State { radius: 19, ), ), - const IgnorePointer(child: Gap(8)), + const Gap(8), Expanded( child: IgnorePointer( child: Column( @@ -241,7 +241,7 @@ class _AttachmentFullScreenState extends State { ), ], ), - const IgnorePointer(child: Gap(4)), + const Gap(4), IgnorePointer( child: Text( widget.item.alt, @@ -253,7 +253,7 @@ class _AttachmentFullScreenState extends State { ), ), ), - const IgnorePointer(child: Gap(2)), + const Gap(2), IgnorePointer( child: Wrap( spacing: 6,