✨ Article attachments
This commit is contained in:
parent
23321171f3
commit
594ac39e3d
@ -1,3 +1,4 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -6,11 +7,14 @@ import 'package:flutter_highlight/themes/a11y-dark.dart';
|
||||
import 'package:flutter_highlight/themes/a11y-light.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
import 'package:island/pods/config.dart';
|
||||
import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:island/widgets/content/markdown_latex.dart';
|
||||
import 'package:markdown/markdown.dart' as markdown;
|
||||
import 'package:markdown_widget/markdown_widget.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'image.dart';
|
||||
@ -23,6 +27,7 @@ class MarkdownTextContent extends HookConsumerWidget {
|
||||
final TextStyle? linkStyle;
|
||||
final EdgeInsets? linesMargin;
|
||||
final bool isSelectable;
|
||||
final List<SnCloudFile>? attachments;
|
||||
|
||||
const MarkdownTextContent({
|
||||
super.key,
|
||||
@ -33,6 +38,7 @@ class MarkdownTextContent extends HookConsumerWidget {
|
||||
this.linkStyle,
|
||||
this.isSelectable = false,
|
||||
this.linesMargin,
|
||||
this.attachments,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -109,6 +115,29 @@ class MarkdownTextContent extends HookConsumerWidget {
|
||||
final uri = Uri.parse(url);
|
||||
if (uri.scheme == 'solian') {
|
||||
switch (uri.host) {
|
||||
case 'files':
|
||||
final file = attachments?.firstWhereOrNull(
|
||||
(file) => file.id == uri.pathSegments[0],
|
||||
);
|
||||
if (file == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
),
|
||||
child: CloudFileWidget(
|
||||
item: file,
|
||||
fit: BoxFit.cover,
|
||||
).clipRRect(all: 8),
|
||||
),
|
||||
);
|
||||
case 'stickers':
|
||||
final size = doesEnlargeSticker ? 96.0 : 24.0;
|
||||
return ClipRRect(
|
||||
@ -132,9 +161,9 @@ class MarkdownTextContent extends HookConsumerWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
final content = UniversalImage(
|
||||
uri: uri.toString(),
|
||||
fit: BoxFit.cover,
|
||||
final content = ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: 360),
|
||||
child: UniversalImage(uri: uri.toString(), fit: BoxFit.contain),
|
||||
);
|
||||
return content;
|
||||
},
|
||||
|
@ -480,8 +480,7 @@ class ComposeLogic {
|
||||
return;
|
||||
}
|
||||
final cloudFile = attachment.data as SnCloudFile;
|
||||
final baseUrl = ref.read(serverUrlProvider);
|
||||
final markdown = '';
|
||||
final markdown = '';
|
||||
final controller = state.contentController;
|
||||
final text = controller.text;
|
||||
final selection = controller.selection;
|
||||
|
@ -331,6 +331,7 @@ class PostItem extends HookConsumerWidget {
|
||||
item.type == 0
|
||||
? EdgeInsets.only(bottom: 8)
|
||||
: null,
|
||||
attachments: item.attachments,
|
||||
),
|
||||
],
|
||||
// Render tags and categories if they exist
|
||||
@ -689,6 +690,7 @@ Widget _buildReferencePost(BuildContext context, SnPost item) {
|
||||
referencePost.type == 0
|
||||
? EdgeInsets.only(bottom: 4)
|
||||
: null,
|
||||
attachments: item.attachments,
|
||||
).padding(bottom: 4),
|
||||
// Truncation hint for referenced post
|
||||
if (referencePost.isTruncated)
|
||||
@ -696,7 +698,8 @@ Widget _buildReferencePost(BuildContext context, SnPost item) {
|
||||
isCompact: true,
|
||||
margin: const EdgeInsets.only(top: 4, bottom: 8),
|
||||
),
|
||||
if (referencePost.attachments.isNotEmpty && referencePost.type != 1)
|
||||
if (referencePost.attachments.isNotEmpty &&
|
||||
referencePost.type != 1)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@ -1030,6 +1033,7 @@ class _ArticlePostDisplay extends StatelessWidget {
|
||||
MarkdownTextContent(
|
||||
content: item.content!,
|
||||
textStyle: Theme.of(context).textTheme.bodyLarge,
|
||||
attachments: item.attachments,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user