🐛 Fix some post related bugs

This commit is contained in:
2025-10-06 12:51:28 +08:00
parent 277e9ae3d1
commit 3cbc1a59a7
5 changed files with 32 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ part of 'call.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$callNotifierHash() => r'438b516c8b786f47495a3435e22b400cd0ca2772'; String _$callNotifierHash() => r'a8ca3f625c0db3ad9992033ae70864ce15efc281';
/// See also [CallNotifier]. /// See also [CallNotifier].
@ProviderFor(CallNotifier) @ProviderFor(CallNotifier)

View File

@@ -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( return Card(
margin: EdgeInsets.zero, margin: EdgeInsets.zero,

View File

@@ -22,10 +22,17 @@ part 'compose_settings_sheet.g.dart';
Future<List<SnPostCategory>> postCategories(Ref ref) async { Future<List<SnPostCategory>> postCategories(Ref ref) async {
final apiClient = ref.watch(apiClientProvider); final apiClient = ref.watch(apiClientProvider);
final resp = await apiClient.get('/sphere/posts/categories'); final resp = await apiClient.get('/sphere/posts/categories');
return resp.data final categories =
resp.data
.map((e) => SnPostCategory.fromJson(e)) .map((e) => SnPostCategory.fromJson(e))
.cast<SnPostCategory>() .cast<SnPostCategory>()
.toList(); .toList();
// Remove duplicates based on id
final uniqueCategories = <String, SnPostCategory>{};
for (final category in categories) {
uniqueCategories[category.id] = category;
}
return uniqueCategories.values.toList();
} }
/// A reusable widget for tag input fields with chip display /// A reusable widget for tag input fields with chip display

View File

@@ -6,7 +6,7 @@ part of 'compose_settings_sheet.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$postCategoriesHash() => r'24337fe806d088b6468a350f62d5a5d40232a73c'; String _$postCategoriesHash() => r'8799c10eb91cf8c8c7ea72eff3475e1eaa7b9a2b';
/// See also [postCategories]. /// See also [postCategories].
@ProviderFor(postCategories) @ProviderFor(postCategories)

View File

@@ -91,7 +91,17 @@ class ComposeLogic {
}) { }) {
final id = draftId ?? DateTime.now().millisecondsSinceEpoch.toString(); final id = draftId ?? DateTime.now().millisecondsSinceEpoch.toString();
final tagsController = StringTagController(); 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 ?? <SnPostCategory>[];
return ComposeState( return ComposeState(
attachments: ValueNotifier<List<UniversalFile>>( attachments: ValueNotifier<List<UniversalFile>>(
originalPost?.attachments originalPost?.attachments
@@ -120,9 +130,7 @@ class ComposeLogic {
attachmentProgress: ValueNotifier<Map<int, double>>({}), attachmentProgress: ValueNotifier<Map<int, double>>({}),
currentPublisher: ValueNotifier<SnPublisher?>(originalPost?.publisher), currentPublisher: ValueNotifier<SnPublisher?>(originalPost?.publisher),
tagsController: tagsController, tagsController: tagsController,
categories: ValueNotifier<List<SnPostCategory>>( categories: ValueNotifier<List<SnPostCategory>>(categories),
originalPost?.categories ?? [],
),
realm: ValueNotifier(originalPost?.realm), realm: ValueNotifier(originalPost?.realm),
embedView: ValueNotifier<SnPostEmbedView?>(originalPost?.embedView), embedView: ValueNotifier<SnPostEmbedView?>(originalPost?.embedView),
draftId: id, draftId: id,
@@ -134,13 +142,10 @@ class ComposeLogic {
static ComposeState createStateFromDraft(SnPost draft, {int postType = 0}) { static ComposeState createStateFromDraft(SnPost draft, {int postType = 0}) {
final tagsController = StringTagController(); final tagsController = StringTagController();
final categoriesController = StringTagController();
for (var x in draft.tags) { for (var x in draft.tags) {
tagsController.addTag(x.slug); tagsController.addTag(x.slug);
} }
for (var x in draft.categories) {
categoriesController.addTag(x.slug);
}
return ComposeState( return ComposeState(
attachments: ValueNotifier<List<UniversalFile>>( attachments: ValueNotifier<List<UniversalFile>>(
draft.attachments.map((e) => UniversalFile.fromAttachment(e)).toList(), draft.attachments.map((e) => UniversalFile.fromAttachment(e)).toList(),
@@ -154,8 +159,8 @@ class ComposeLogic {
attachmentProgress: ValueNotifier<Map<int, double>>({}), attachmentProgress: ValueNotifier<Map<int, double>>({}),
currentPublisher: ValueNotifier<SnPublisher?>(null), currentPublisher: ValueNotifier<SnPublisher?>(null),
tagsController: tagsController, tagsController: tagsController,
categories: ValueNotifier<List<SnPostCategory>>([]), categories: ValueNotifier<List<SnPostCategory>>(draft.categories),
realm: ValueNotifier(null), realm: ValueNotifier(draft.realm),
embedView: ValueNotifier<SnPostEmbedView?>(draft.embedView), embedView: ValueNotifier<SnPostEmbedView?>(draft.embedView),
draftId: draft.id, draftId: draft.id,
postType: postType, postType: postType,