From 23321171f31ace855865b2a341b5c23e8b8b343a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 3 Jul 2025 01:11:56 +0800 Subject: [PATCH] :lipstick: Optimized attachment insert in article compose --- assets/i18n/en-US.json | 4 +++- lib/screens/posts/compose_article.dart | 21 +++++++++++++++------ lib/widgets/content/attachment_preview.dart | 6 +++++- lib/widgets/post/compose_shared.dart | 5 +++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/assets/i18n/en-US.json b/assets/i18n/en-US.json index 4ea8c7c..1f5c07d 100644 --- a/assets/i18n/en-US.json +++ b/assets/i18n/en-US.json @@ -375,7 +375,9 @@ "postContent": "Content", "postSettings": "Settings", "postPublisherUnselected": "Publisher Unspecified", - "postVisibility": "Visibility", + "postType": "Post Type", + "articleAttachmentHint": "Attachments must be uploaded and inserted into the article body to be visible.", + "postVisibility": "Post Visibility", "postVisibilityPublic": "Public", "postVisibilityFriends": "Friends Only", "postVisibilityUnlisted": "Unlisted", diff --git a/lib/screens/posts/compose_article.dart b/lib/screens/posts/compose_article.dart index 6b78724..7aafb8d 100644 --- a/lib/screens/posts/compose_article.dart +++ b/lib/screens/posts/compose_article.dart @@ -321,8 +321,15 @@ class ArticleComposeScreen extends HookConsumerWidget { builder: (context, attachments, _) { if (attachments.isEmpty) return const SizedBox.shrink(); return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ const Gap(16), + Text( + 'articleAttachmentHint'.tr(), + style: Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ).padding(bottom: 8), ValueListenableBuilder>( valueListenable: state.attachmentProgress, builder: (context, progressMap, _) { @@ -332,8 +339,8 @@ class ArticleComposeScreen extends HookConsumerWidget { children: [ for (var idx = 0; idx < attachments.length; idx++) SizedBox( - width: 120, - height: 120, + width: 280, + height: 280, child: AttachmentPreview( item: attachments[idx], progress: progressMap[idx], @@ -358,10 +365,12 @@ class ArticleComposeScreen extends HookConsumerWidget { delta, ); }, - onInsert: () => ComposeLogic.insertAttachment( - state, - idx, - ), + onInsert: + () => ComposeLogic.insertAttachment( + ref, + state, + idx, + ), ), ), ], diff --git a/lib/widgets/content/attachment_preview.dart b/lib/widgets/content/attachment_preview.dart index 9f8e5c1..0d6c171 100644 --- a/lib/widgets/content/attachment_preview.dart +++ b/lib/widgets/content/attachment_preview.dart @@ -106,7 +106,11 @@ class AttachmentPreview extends StatelessWidget { style: TextStyle(color: Colors.white), ), Gap(6), - Center(child: LinearProgressIndicator(value: progress)), + Center( + child: LinearProgressIndicator( + value: progress != null ? progress! / 100.0 : null, + ), + ), ], ), ), diff --git a/lib/widgets/post/compose_shared.dart b/lib/widgets/post/compose_shared.dart index 09fe98e..38cf05c 100644 --- a/lib/widgets/post/compose_shared.dart +++ b/lib/widgets/post/compose_shared.dart @@ -474,13 +474,14 @@ class ComposeLogic { state.attachments.value = clone; } - static void insertAttachment(ComposeState state, int index) { + static void insertAttachment(WidgetRef ref, 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 baseUrl = ref.read(serverUrlProvider); + final markdown = '![${cloudFile.name}]($baseUrl/files/${cloudFile.id})'; final controller = state.contentController; final text = controller.text; final selection = controller.selection;