From 3cbc1a59a78cca16fb22932cd114fc9721a3f56a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 6 Oct 2025 12:51:28 +0800 Subject: [PATCH] :bug: Fix some post related bugs --- lib/pods/chat/call.g.dart | 2 +- lib/widgets/post/compose_card.dart | 5 +++- lib/widgets/post/compose_settings_sheet.dart | 15 ++++++++--- .../post/compose_settings_sheet.g.dart | 2 +- lib/widgets/post/compose_shared.dart | 25 +++++++++++-------- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/pods/chat/call.g.dart b/lib/pods/chat/call.g.dart index 5c4db434..57a92fde 100644 --- a/lib/pods/chat/call.g.dart +++ b/lib/pods/chat/call.g.dart @@ -6,7 +6,7 @@ part of 'call.dart'; // RiverpodGenerator // ************************************************************************** -String _$callNotifierHash() => r'438b516c8b786f47495a3435e22b400cd0ca2772'; +String _$callNotifierHash() => r'a8ca3f625c0db3ad9992033ae70864ce15efc281'; /// See also [CallNotifier]. @ProviderFor(CallNotifier) diff --git a/lib/widgets/post/compose_card.dart b/lib/widgets/post/compose_card.dart index 2cbd64d6..a0d4987e 100644 --- a/lib/widgets/post/compose_card.dart +++ b/lib/widgets/post/compose_card.dart @@ -166,7 +166,10 @@ class PostComposeCard extends HookConsumerWidget { ); } - final maxHeight = math.min(640.0, MediaQuery.of(context).size.height * 0.8); + final maxHeight = math.min( + 640.0, + MediaQuery.of(context).size.height * (isInDialog ? 0.8 : 0.72), + ); return Card( margin: EdgeInsets.zero, diff --git a/lib/widgets/post/compose_settings_sheet.dart b/lib/widgets/post/compose_settings_sheet.dart index a9c2dd46..63e49a89 100644 --- a/lib/widgets/post/compose_settings_sheet.dart +++ b/lib/widgets/post/compose_settings_sheet.dart @@ -22,10 +22,17 @@ part 'compose_settings_sheet.g.dart'; Future> postCategories(Ref ref) async { final apiClient = ref.watch(apiClientProvider); final resp = await apiClient.get('/sphere/posts/categories'); - return resp.data - .map((e) => SnPostCategory.fromJson(e)) - .cast() - .toList(); + final categories = + resp.data + .map((e) => SnPostCategory.fromJson(e)) + .cast() + .toList(); + // Remove duplicates based on id + final uniqueCategories = {}; + for (final category in categories) { + uniqueCategories[category.id] = category; + } + return uniqueCategories.values.toList(); } /// A reusable widget for tag input fields with chip display diff --git a/lib/widgets/post/compose_settings_sheet.g.dart b/lib/widgets/post/compose_settings_sheet.g.dart index 7816a5dc..d3455de9 100644 --- a/lib/widgets/post/compose_settings_sheet.g.dart +++ b/lib/widgets/post/compose_settings_sheet.g.dart @@ -6,7 +6,7 @@ part of 'compose_settings_sheet.dart'; // RiverpodGenerator // ************************************************************************** -String _$postCategoriesHash() => r'24337fe806d088b6468a350f62d5a5d40232a73c'; +String _$postCategoriesHash() => r'8799c10eb91cf8c8c7ea72eff3475e1eaa7b9a2b'; /// See also [postCategories]. @ProviderFor(postCategories) diff --git a/lib/widgets/post/compose_shared.dart b/lib/widgets/post/compose_shared.dart index f2836000..e335ff23 100644 --- a/lib/widgets/post/compose_shared.dart +++ b/lib/widgets/post/compose_shared.dart @@ -91,7 +91,17 @@ class ComposeLogic { }) { final id = draftId ?? DateTime.now().millisecondsSinceEpoch.toString(); final tagsController = StringTagController(); - originalPost?.tags.forEach((x) => tagsController.addTag(x.slug)); + + // Initialize tags from original post + if (originalPost != null) { + for (var tag in originalPost.tags) { + tagsController.addTag(tag.slug); + } + } + + // Initialize categories from original post + final categories = originalPost?.categories ?? []; + return ComposeState( attachments: ValueNotifier>( originalPost?.attachments @@ -120,9 +130,7 @@ class ComposeLogic { attachmentProgress: ValueNotifier>({}), currentPublisher: ValueNotifier(originalPost?.publisher), tagsController: tagsController, - categories: ValueNotifier>( - originalPost?.categories ?? [], - ), + categories: ValueNotifier>(categories), realm: ValueNotifier(originalPost?.realm), embedView: ValueNotifier(originalPost?.embedView), draftId: id, @@ -134,13 +142,10 @@ class ComposeLogic { static ComposeState createStateFromDraft(SnPost draft, {int postType = 0}) { final tagsController = StringTagController(); - final categoriesController = StringTagController(); for (var x in draft.tags) { tagsController.addTag(x.slug); } - for (var x in draft.categories) { - categoriesController.addTag(x.slug); - } + return ComposeState( attachments: ValueNotifier>( draft.attachments.map((e) => UniversalFile.fromAttachment(e)).toList(), @@ -154,8 +159,8 @@ class ComposeLogic { attachmentProgress: ValueNotifier>({}), currentPublisher: ValueNotifier(null), tagsController: tagsController, - categories: ValueNotifier>([]), - realm: ValueNotifier(null), + categories: ValueNotifier>(draft.categories), + realm: ValueNotifier(draft.realm), embedView: ValueNotifier(draft.embedView), draftId: draft.id, postType: postType,