🐛 Fix the compose

This commit is contained in:
2025-10-10 01:04:21 +08:00
parent ac424bde36
commit e1ea61c5f1
2 changed files with 17 additions and 7 deletions

View File

@@ -152,7 +152,7 @@ class PostComposeCard extends HookConsumerWidget {
originalPost: originalPost, originalPost: originalPost,
repliedPost: repliedPost, repliedPost: repliedPost,
forwardedPost: forwardedPost, forwardedPost: forwardedPost,
onSuccess: () { onSuccess: (SnPost createdPost) {
// Mark as submitted // Mark as submitted
submitted.value = true; submitted.value = true;
@@ -163,6 +163,9 @@ class PostComposeCard extends HookConsumerWidget {
// Reset the form for new composition // Reset the form for new composition
ComposeStateUtils.resetForm(state); ComposeStateUtils.resetForm(state);
// Call the widget's onSubmit callback to trigger activity list refresh
onSubmit?.call(createdPost);
}, },
); );
} }

View File

@@ -9,16 +9,18 @@ import 'package:island/widgets/post/compose_shared.dart';
/// Utility class for common compose submit logic. /// Utility class for common compose submit logic.
class ComposeSubmitUtils { class ComposeSubmitUtils {
/// Performs the submit action for posts. /// Performs the submit action for posts.
static Future<void> performSubmit( static Future<SnPost> performSubmit(
WidgetRef ref, WidgetRef ref,
ComposeState state, ComposeState state,
BuildContext context, { BuildContext context, {
SnPost? originalPost, SnPost? originalPost,
SnPost? repliedPost, SnPost? repliedPost,
SnPost? forwardedPost, SnPost? forwardedPost,
required VoidCallback onSuccess, required Function(SnPost) onSuccess,
}) async { }) async {
if (state.submitting.value) return; if (state.submitting.value) {
throw Exception('Already submitting');
}
// Don't submit empty posts (no content and no attachments) // Don't submit empty posts (no content and no attachments)
final hasContent = final hasContent =
@@ -34,7 +36,7 @@ class ComposeSubmitUtils {
context, context,
).showSnackBar(SnackBar(content: Text('postContentEmpty'))); ).showSnackBar(SnackBar(content: Text('postContentEmpty')));
} }
return; // Don't submit empty posts throw Exception('Post content is empty'); // Don't submit empty posts
} }
try { try {
@@ -82,15 +84,20 @@ class ComposeSubmitUtils {
}; };
// Send request // Send request
client.request( final response = await client.request(
endpoint, endpoint,
queryParameters: {'pub': state.currentPublisher.value?.name}, queryParameters: {'pub': state.currentPublisher.value?.name},
data: payload, data: payload,
options: Options(method: isNewPost ? 'POST' : 'PATCH'), options: Options(method: isNewPost ? 'POST' : 'PATCH'),
); );
// Parse the response into a SnPost
final post = SnPost.fromJson(response.data);
// Call the success callback with the created/updated post // Call the success callback with the created/updated post
onSuccess(); onSuccess(post);
return post;
} catch (err) { } catch (err) {
// Show error message if context is mounted // Show error message if context is mounted
if (context.mounted) { if (context.mounted) {