🐛 Bug fixes on profile page

This commit is contained in:
LittleSheep 2024-12-08 00:40:44 +08:00
parent 4a9ccc7c7a
commit fa346b528e
3 changed files with 51 additions and 26 deletions

View File

@ -377,7 +377,7 @@
"accountJoinedAt": "加入于 {}", "accountJoinedAt": "加入于 {}",
"accountBirthday": "出生于 {}", "accountBirthday": "出生于 {}",
"accountBadge": "徽章", "accountBadge": "徽章",
"badgeCompanyStaff": "索尔辛茨士大夫 · Staff", "badgeCompanyStaff": "索尔辛茨士大夫 · 员工",
"badgeSiteMigration": "Solar Network 原住民", "badgeSiteMigration": "Solar Network 原住民",
"accountStatus": "状态", "accountStatus": "状态",
"accountStatusOnline": "在线", "accountStatusOnline": "在线",

View File

@ -6,6 +6,7 @@ import 'package:gap/gap.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:relative_time/relative_time.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/sn_network.dart';
import 'package:surface/types/account.dart'; import 'package:surface/types/account.dart';
@ -28,14 +29,14 @@ const Map<String, (String, IconData, Color)> kBadgesMeta = {
class UserScreen extends StatefulWidget { class UserScreen extends StatefulWidget {
final String name; final String name;
const UserScreen({super.key, required this.name}); const UserScreen({super.key, required this.name});
@override @override
State<UserScreen> createState() => _UserScreenState(); State<UserScreen> createState() => _UserScreenState();
} }
class _UserScreenState extends State<UserScreen> class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateMixin {
with SingleTickerProviderStateMixin {
late final ScrollController _scrollController = ScrollController(); late final ScrollController _scrollController = ScrollController();
SnAccount? _account; SnAccount? _account;
@ -75,14 +76,12 @@ class _UserScreenState extends State<UserScreen>
double _appBarBlur = 0.0; double _appBarBlur = 0.0;
late final _appBarWidth = MediaQuery.of(context).size.width; late final _appBarWidth = MediaQuery.of(context).size.width;
late final _appBarHeight = late final _appBarHeight = (_appBarWidth * kBannerAspectRatio).roundToDouble();
(_appBarWidth * kBannerAspectRatio).roundToDouble();
void _updateAppBarBlur() { void _updateAppBarBlur() {
if (_scrollController.offset > _appBarHeight) return; if (_scrollController.offset > _appBarHeight) return;
setState(() { setState(() {
_appBarBlur = _appBarBlur = (_scrollController.offset / _appBarHeight * 10).clamp(0.0, 10.0);
(_scrollController.offset / _appBarHeight * 10).clamp(0.0, 10.0);
}); });
} }
@ -218,9 +217,7 @@ class _UserScreenState extends State<UserScreen>
Symbols.circle, Symbols.circle,
fill: 1, fill: 1,
size: 16, size: 16,
color: (_status?.isOnline ?? false) color: (_status?.isOnline ?? false) ? Colors.green : Colors.grey,
? Colors.green
: Colors.grey,
).padding(all: 4), ).padding(all: 4),
const Gap(8), const Gap(8),
Text( Text(
@ -230,19 +227,55 @@ class _UserScreenState extends State<UserScreen>
: 'accountStatusOffline'.tr() : 'accountStatusOffline'.tr()
: 'loading'.tr(), : 'loading'.tr(),
), ),
if (_status != null && !_status!.isOnline && _status!.lastSeenAt != null)
Text(
'accountStatusLastSeen'.tr(args: [
_status!.lastSeenAt != null
? RelativeTime(context).format(
_status!.lastSeenAt!.toLocal(),
)
: 'unknown',
]),
).padding(left: 6).opacity(0.75),
], ],
).padding(vertical: 8, horizontal: 12), ).padding(vertical: 8, horizontal: 12),
), ),
const Gap(8), const Gap(8),
Wrap(
children: _account!.badges
.map(
(ele) => Tooltip(
richMessage: TextSpan(
children: [
TextSpan(text: kBadgesMeta[ele.type]?.$1.tr() ?? 'unknown'.tr()),
if (ele.metadata['title'] != null)
TextSpan(
text: '\n${ele.metadata['title']}',
style: const TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: '\n'),
TextSpan(
text: DateFormat.yMEd().format(ele.createdAt),
),
],
),
child: Icon(
kBadgesMeta[ele.type]?.$2 ?? Symbols.question_mark,
color: kBadgesMeta[ele.type]?.$3,
fill: 1,
),
),
)
.toList(),
).padding(horizontal: 8),
const Gap(8),
Column( Column(
children: [ children: [
Row( Row(
children: [ children: [
const Icon(Symbols.calendar_add_on), const Icon(Symbols.calendar_add_on),
const Gap(8), const Gap(8),
Text('publisherJoinedAt').tr(args: [ Text('publisherJoinedAt').tr(args: [DateFormat('y/M/d').format(_account!.createdAt)]),
DateFormat('y/M/d').format(_account!.createdAt)
]),
], ],
), ),
Row( Row(
@ -279,11 +312,7 @@ class _UserScreenState extends State<UserScreen>
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('accountBadge') Text('accountBadge').bold().fontSize(17).tr().padding(horizontal: 20, bottom: 4),
.bold()
.fontSize(17)
.tr()
.padding(horizontal: 20, bottom: 4),
SizedBox( SizedBox(
height: 80, height: 80,
width: double.infinity, width: double.infinity,
@ -297,8 +326,7 @@ class _UserScreenState extends State<UserScreen>
child: Card( child: Card(
child: ListTile( child: ListTile(
leading: Icon( leading: Icon(
kBadgesMeta[badge.type]?.$2 ?? kBadgesMeta[badge.type]?.$2 ?? Symbols.question_mark,
Symbols.question_mark,
color: kBadgesMeta[badge.type]?.$3, color: kBadgesMeta[badge.type]?.$3,
fill: 1, fill: 1,
), ),
@ -308,8 +336,7 @@ class _UserScreenState extends State<UserScreen>
subtitle: badge.metadata['title'] != null subtitle: badge.metadata['title'] != null
? Text(badge.metadata['title']) ? Text(badge.metadata['title'])
: Text( : Text(
DateFormat('y/M/d') DateFormat('y/M/d').format(badge.createdAt),
.format(badge.createdAt),
), ),
), ),
), ),

View File

@ -73,7 +73,6 @@ class MarkdownTextContent extends StatelessWidget {
extensionSet: markdown.ExtensionSet( extensionSet: markdown.ExtensionSet(
<markdown.BlockSyntax>[ <markdown.BlockSyntax>[
markdown.CodeBlockSyntax(), markdown.CodeBlockSyntax(),
...markdown.ExtensionSet.commonMark.blockSyntaxes,
...markdown.ExtensionSet.gitHubFlavored.blockSyntaxes, ...markdown.ExtensionSet.gitHubFlavored.blockSyntaxes,
], ],
<markdown.InlineSyntax>[ <markdown.InlineSyntax>[
@ -82,7 +81,6 @@ class MarkdownTextContent extends StatelessWidget {
markdown.AutolinkSyntax(), markdown.AutolinkSyntax(),
markdown.AutolinkExtensionSyntax(), markdown.AutolinkExtensionSyntax(),
markdown.CodeSyntax(), markdown.CodeSyntax(),
...markdown.ExtensionSet.commonMark.inlineSyntaxes,
...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes ...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes
], ],
), ),
@ -93,7 +91,7 @@ class MarkdownTextContent extends StatelessWidget {
final segments = uri.split('/'); final segments = uri.split('/');
switch (segments[0]) { switch (segments[0]) {
default: default:
GoRouter.of(context).push(uri); GoRouter.of(context).push('/$uri');
} }
return; return;
} }
@ -188,7 +186,7 @@ class _UserNameCardInlineSyntax extends markdown.InlineSyntax {
final alias = match[0]!; final alias = match[0]!;
final anchor = markdown.Element.text('a', alias) final anchor = markdown.Element.text('a', alias)
..attributes['href'] = Uri.encodeFull( ..attributes['href'] = Uri.encodeFull(
'solink://users/${alias.substring(1)}', 'solink://account/${alias.substring(1)}',
); );
parser.addNode(anchor); parser.addNode(anchor);