diff --git a/lib/screens/posts/compose_article.dart b/lib/screens/posts/compose_article.dart index 95b6526..6b78724 100644 --- a/lib/screens/posts/compose_article.dart +++ b/lib/screens/posts/compose_article.dart @@ -358,6 +358,10 @@ class ArticleComposeScreen extends HookConsumerWidget { delta, ); }, + onInsert: () => ComposeLogic.insertAttachment( + state, + idx, + ), ), ), ], diff --git a/lib/widgets/content/attachment_preview.dart b/lib/widgets/content/attachment_preview.dart index 8932dda..9f8e5c1 100644 --- a/lib/widgets/content/attachment_preview.dart +++ b/lib/widgets/content/attachment_preview.dart @@ -15,6 +15,7 @@ class AttachmentPreview extends StatelessWidget { final double? progress; final Function(int)? onMove; final Function? onDelete; + final Function? onInsert; final Function? onRequestUpload; const AttachmentPreview({ super.key, @@ -23,6 +24,7 @@ class AttachmentPreview extends StatelessWidget { this.onRequestUpload, this.onMove, this.onDelete, + this.onInsert, }); @override @@ -166,6 +168,18 @@ class AttachmentPreview extends StatelessWidget { onMove?.call(1); }, ), + if (onInsert != null) + InkWell( + borderRadius: BorderRadius.circular(8), + child: const Icon( + Symbols.add, + size: 14, + color: Colors.white, + ).padding(horizontal: 8, vertical: 6), + onTap: () { + onInsert?.call(); + }, + ), ], ), ), diff --git a/lib/widgets/post/compose_shared.dart b/lib/widgets/post/compose_shared.dart index 6ec31e6..09fe98e 100644 --- a/lib/widgets/post/compose_shared.dart +++ b/lib/widgets/post/compose_shared.dart @@ -474,6 +474,23 @@ class ComposeLogic { state.attachments.value = clone; } + static void insertAttachment(ComposeState state, int index) { + final attachment = state.attachments.value[index]; + if (!attachment.isOnCloud) { + return; + } + final cloudFile = attachment.data as SnCloudFile; + final markdown = '![${cloudFile.name}](${cloudFile.id})'; + final controller = state.contentController; + final text = controller.text; + final selection = controller.selection; + final newText = text.replaceRange(selection.start, selection.end, markdown); + controller.text = newText; + controller.selection = TextSelection.fromPosition( + TextPosition(offset: selection.start + markdown.length), + ); + } + static Future performAction( WidgetRef ref, ComposeState state, diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 8ef7e6e..6a373e4 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -163,7 +163,7 @@ class PostItem extends HookConsumerWidget { if ((item.repliedPost != null || item.forwardedPost != null) && showReferencePost) _buildReferencePost(context, item), - if (item.attachments.isNotEmpty) + if (item.attachments.isNotEmpty && item.type != 1) CloudFileList( files: item.attachments, maxWidth: math.min( @@ -389,7 +389,7 @@ class PostItem extends HookConsumerWidget { item.forwardedPost != null) && showReferencePost) _buildReferencePost(context, item), - if (item.attachments.isNotEmpty) + if (item.attachments.isNotEmpty && item.type != 1) CloudFileList( files: item.attachments, maxWidth: math.min( @@ -696,7 +696,7 @@ Widget _buildReferencePost(BuildContext context, SnPost item) { isCompact: true, margin: const EdgeInsets.only(top: 4, bottom: 8), ), - if (referencePost.attachments.isNotEmpty) + if (referencePost.attachments.isNotEmpty && referencePost.type != 1) Row( mainAxisSize: MainAxisSize.min, children: [ diff --git a/lib/widgets/post/post_replies_sheet.dart b/lib/widgets/post/post_replies_sheet.dart index 1410c33..d8e8860 100644 --- a/lib/widgets/post/post_replies_sheet.dart +++ b/lib/widgets/post/post_replies_sheet.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:island/models/post.dart'; +import 'package:island/pods/userinfo.dart'; import 'package:island/widgets/content/sheet.dart'; import 'package:island/widgets/post/post_replies.dart'; import 'package:island/widgets/post/post_quick_reply.dart'; @@ -14,6 +15,8 @@ class PostRepliesSheet extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { + final user = ref.watch(userInfoProvider); + return SheetScaffold( titleText: 'repliesCount'.plural(post.repliesCount), child: Column( @@ -21,26 +24,29 @@ class PostRepliesSheet extends HookConsumerWidget { // Replies list Expanded( child: CustomScrollView( - slivers: [PostRepliesList( - postId: post.id.toString(), - backgroundColor: Colors.transparent, - )], + slivers: [ + PostRepliesList( + postId: post.id.toString(), + backgroundColor: Colors.transparent, + ), + ], ), ), // Quick reply section - Material( - elevation: 2, - child: PostQuickReply( - parent: post, - onPosted: () { - ref.invalidate(postRepliesNotifierProvider(post.id)); - }, - ).padding( - bottom: MediaQuery.of(context).padding.bottom + 16, - top: 16, - horizontal: 16, + if (user.value != null) + Material( + elevation: 2, + child: PostQuickReply( + parent: post, + onPosted: () { + ref.invalidate(postRepliesNotifierProvider(post.id)); + }, + ).padding( + bottom: MediaQuery.of(context).padding.bottom + 16, + top: 16, + horizontal: 16, + ), ), - ), ], ), );