Skip to content

Commit b89b4c0

Browse files
committed
fix: logo for web & forum logo display
1 parent b986603 commit b89b4c0

8 files changed

Lines changed: 73 additions & 13 deletions

File tree

lib/models/forum_model.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Forum {
99
final String createdByUid;
1010
final DateTime createdAt;
1111
final DateTime updatedAt;
12+
final String? avatarUrl;
1213

1314
Forum({
1415
required this.id,
@@ -19,6 +20,7 @@ class Forum {
1920
required this.createdByUid,
2021
required this.createdAt,
2122
required this.updatedAt,
23+
this.avatarUrl,
2224
});
2325

2426
factory Forum.fromJson(Map<String, dynamic> json) {
@@ -31,20 +33,23 @@ class Forum {
3133
createdByUid: json['created_by_uid'] as String,
3234
createdAt: DateTime.parse(json['created_at'] as String),
3335
updatedAt: DateTime.parse(json['updated_at'] as String),
36+
avatarUrl: json['avatar_url'] as String?,
3437
);
3538
}
3639

37-
factory Forum.fromServerRow(List<dynamic> row) {
40+
factory Forum.fromServerRow(List<dynamic> row, {String? baseUrl}) {
3841
final ms = ((double.tryParse(row[3].toString()) ?? 0) * 1000).toInt();
42+
final fid = row[0].toString();
3943
return Forum(
40-
id: row[0].toString(),
44+
id: fid,
4145
name: row[1] as String,
4246
description: (row[4] as String?) ?? '',
4347
isPublic: true,
4448
isCommunity: true,
4549
createdByUid: row[2].toString(),
4650
createdAt: DateTime.fromMillisecondsSinceEpoch(ms),
4751
updatedAt: DateTime.fromMillisecondsSinceEpoch(ms),
52+
avatarUrl: baseUrl != null ? '$baseUrl/avatar/get_avatar/forum/$fid' : null,
4853
);
4954
}
5055

@@ -58,6 +63,7 @@ class Forum {
5863
'created_by_uid': createdByUid,
5964
'created_at': createdAt.toIso8601String(),
6065
'updated_at': updatedAt.toIso8601String(),
66+
if (avatarUrl != null) 'avatar_url': avatarUrl,
6167
};
6268
}
6369
}

lib/screens/forum_detail_screen.dart

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,23 @@ class _ForumDetailScreenState extends State<ForumDetailScreen> {
216216
) {
217217
return AppBar(
218218
leading: BackButton(onPressed: () => context.pop()),
219-
title: Text(
220-
forum.name,
221-
style: TextStyle(color: colorScheme.onPrimaryContainer),
219+
title: Row(
220+
mainAxisSize: MainAxisSize.min,
221+
children: [
222+
ProfilePictureWidget(
223+
avatarUrl: forum.avatarUrl,
224+
radius: 16,
225+
fallbackIcon: Icons.forum,
226+
),
227+
const SizedBox(width: 10),
228+
Flexible(
229+
child: Text(
230+
forum.name,
231+
style: TextStyle(color: colorScheme.onPrimaryContainer),
232+
overflow: TextOverflow.ellipsis,
233+
),
234+
),
235+
],
222236
),
223237
flexibleSpace: Container(
224238
decoration: BoxDecoration(
@@ -264,9 +278,23 @@ class _ForumDetailScreenState extends State<ForumDetailScreen> {
264278
pinned: true,
265279
leading: BackButton(onPressed: () => context.pop()),
266280
flexibleSpace: FlexibleSpaceBar(
267-
title: Text(
268-
forum.name,
269-
style: TextStyle(color: colorScheme.onPrimaryContainer),
281+
title: Row(
282+
mainAxisSize: MainAxisSize.min,
283+
children: [
284+
ProfilePictureWidget(
285+
avatarUrl: forum.avatarUrl,
286+
radius: 14,
287+
fallbackIcon: Icons.forum,
288+
),
289+
const SizedBox(width: 8),
290+
Flexible(
291+
child: Text(
292+
forum.name,
293+
style: TextStyle(color: colorScheme.onPrimaryContainer),
294+
overflow: TextOverflow.ellipsis,
295+
),
296+
),
297+
],
270298
),
271299
background: Container(color: colorScheme.surfaceContainerHighest),
272300
),

lib/screens/forum_screen.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import '../l10n/app_localizations.dart';
44
import '../models/forum_model.dart';
55
import '../services/api/tf_api_client.dart';
66
import '../services/auth_state.dart';
7+
import '../widgets/account/profile_picture.dart';
78
import '../utils/talker.dart';
89

910
class ForumScreen extends StatefulWidget {
@@ -269,9 +270,10 @@ class _ForumListTile extends StatelessWidget {
269270
shape: const RoundedRectangleBorder(
270271
borderRadius: BorderRadius.all(Radius.circular(12)),
271272
),
272-
leading: Icon(
273-
Icons.forum,
274-
color: Theme.of(context).colorScheme.primary,
273+
leading: ProfilePictureWidget(
274+
avatarUrl: forum.avatarUrl,
275+
radius: 20,
276+
fallbackIcon: Icons.forum,
275277
),
276278
title: Text(forum.name),
277279
subtitle: Text(

lib/services/api/tf_api_client.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,21 @@ class TfApiClient {
705705
return _parseBool(result);
706706
}
707707

708+
Future<bool> uploadForumAvatar(
709+
int uid,
710+
String password,
711+
int fid,
712+
String picBase64,
713+
) async {
714+
final result = await secretPost(
715+
'/avatar/upload_forum_avatar',
716+
{'fid': fid, 'pic': picBase64},
717+
uid: uid,
718+
password: password,
719+
);
720+
return _parseBool(result);
721+
}
722+
708723
Future<bool> uploadDefaultAvatar(
709724
int uid,
710725
String password,
@@ -730,7 +745,7 @@ class TfApiClient {
730745
final data = jsonDecode(response.body);
731746
if (data is! List) return [];
732747
return data
733-
.map((row) => Forum.fromServerRow(row as List<dynamic>))
748+
.map((row) => Forum.fromServerRow(row as List<dynamic>, baseUrl: baseUrl))
734749
.toList();
735750
} catch (e) {
736751
talker.error('getForumList failed', e);

lib/utils/web_splash_stub.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// No-op stub for platforms without dart:js (mobile, desktop).
2+
void removeWebSplash() {}

lib/utils/web_splash_web.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'dart:js' as js;
2+
3+
void removeWebSplash() {
4+
js.context.callMethod('removeSplashFromWeb', []);
5+
}

lib/widgets/account/profile_picture.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ class ProfilePictureWidget extends StatelessWidget {
44
final String? avatarUrl;
55
final double radius;
66
final String? fallbackText;
7+
final IconData? fallbackIcon;
78

89
const ProfilePictureWidget({
910
super.key,
1011
this.avatarUrl,
1112
this.radius = 24,
1213
this.fallbackText,
14+
this.fallbackIcon,
1315
});
1416

1517
@override
@@ -26,7 +28,7 @@ class ProfilePictureWidget extends StatelessWidget {
2628
radius: radius,
2729
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
2830
child: Icon(
29-
Icons.person,
31+
fallbackIcon ?? Icons.person,
3032
size: radius,
3133
color: Theme.of(context).colorScheme.onPrimaryContainer,
3234
),

web/splash/img/light-1x.png

15.4 KB
Loading

0 commit comments

Comments
 (0)