✨ Render post article thumbnail
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:html2md/html2md.dart' as html2md;
|
||||
import 'package:island/models/account.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
import 'package:island/models/post.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/services/time.dart';
|
||||
@@ -1030,6 +1031,16 @@ class PostBody extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
SnCloudFile? getThumbnailAttachment() {
|
||||
final thumbnailId = item.meta?['thumbnail'] as String?;
|
||||
if (thumbnailId == null) return null;
|
||||
try {
|
||||
return item.attachments.firstWhere((a) => a.id == thumbnailId);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -1042,7 +1053,6 @@ class PostBody extends ConsumerWidget {
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
margin: EdgeInsets.only(
|
||||
top: 4,
|
||||
left: renderingPadding.horizontal,
|
||||
@@ -1050,6 +1060,16 @@ class PostBody extends ConsumerWidget {
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (getThumbnailAttachment() != null)
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(8),
|
||||
),
|
||||
child: CloudFileWidget(item: getThumbnailAttachment()!),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Align(
|
||||
@@ -1064,22 +1084,17 @@ class PostBody extends ConsumerWidget {
|
||||
if (item.title != null)
|
||||
Text(
|
||||
item.title!,
|
||||
style: Theme.of(context).textTheme.titleMedium!.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
style: Theme.of(context).textTheme.titleMedium!
|
||||
.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
if (item.description != null)
|
||||
if (item.description?.isNotEmpty ?? false)
|
||||
Text(
|
||||
item.description!,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
)
|
||||
else
|
||||
MarkdownTextContent(
|
||||
content: '${_convertContentToMarkdown(item)}...',
|
||||
attachments: item.attachments,
|
||||
noMentionChip: item.fediverseUri != null,
|
||||
),
|
||||
],
|
||||
).padding(horizontal: 16, vertical: 12),
|
||||
],
|
||||
),
|
||||
)
|
||||
else if ((item.content?.isNotEmpty ?? false) ||
|
||||
|
||||
Reference in New Issue
Block a user