🐛 Fix edit post got truncated post lead to wrong state of editing, close #195
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:island/models/file.dart';
|
import 'package:island/models/file.dart';
|
||||||
import 'package:island/models/post.dart';
|
import 'package:island/models/post.dart';
|
||||||
import 'package:island/screens/posts/compose.dart';
|
import 'package:island/screens/posts/compose.dart';
|
||||||
|
import 'package:island/screens/posts/post_detail.dart';
|
||||||
import 'package:island/services/compose_storage_db.dart';
|
import 'package:island/services/compose_storage_db.dart';
|
||||||
import 'package:island/widgets/content/sheet.dart';
|
import 'package:island/widgets/content/sheet.dart';
|
||||||
import 'package:island/widgets/post/compose_card.dart';
|
import 'package:island/widgets/post/compose_card.dart';
|
||||||
@@ -50,19 +51,33 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
final restoredInitialState = useState<PostComposeInitialState?>(null);
|
final restoredInitialState = useState<PostComposeInitialState?>(null);
|
||||||
final prompted = useState(false);
|
final prompted = useState(false);
|
||||||
|
|
||||||
final repliedPost = initialState?.replyingTo ?? originalPost?.repliedPost;
|
// Fetch full post data if we're editing a post
|
||||||
|
final fullPostData =
|
||||||
|
originalPost != null
|
||||||
|
? ref.watch(postProvider(originalPost!.id))
|
||||||
|
: const AsyncValue.data(null);
|
||||||
|
|
||||||
|
// Use the full post data if available, otherwise fall back to originalPost
|
||||||
|
final effectiveOriginalPost = fullPostData.when(
|
||||||
|
data: (fullPost) => fullPost ?? originalPost,
|
||||||
|
loading: () => originalPost,
|
||||||
|
error: (_, _) => originalPost,
|
||||||
|
);
|
||||||
|
|
||||||
|
final repliedPost =
|
||||||
|
initialState?.replyingTo ?? effectiveOriginalPost?.repliedPost;
|
||||||
final forwardedPost =
|
final forwardedPost =
|
||||||
initialState?.forwardingTo ?? originalPost?.forwardedPost;
|
initialState?.forwardingTo ?? effectiveOriginalPost?.forwardedPost;
|
||||||
|
|
||||||
// Create compose state
|
// Create compose state
|
||||||
final ComposeState state = useMemoized(
|
final ComposeState state = useMemoized(
|
||||||
() => ComposeLogic.createState(
|
() => ComposeLogic.createState(
|
||||||
originalPost: originalPost,
|
originalPost: effectiveOriginalPost,
|
||||||
forwardedPost: forwardedPost,
|
forwardedPost: forwardedPost,
|
||||||
repliedPost: repliedPost,
|
repliedPost: repliedPost,
|
||||||
postType: 0,
|
postType: 0,
|
||||||
),
|
),
|
||||||
[originalPost, forwardedPost, repliedPost],
|
[effectiveOriginalPost, forwardedPost, repliedPost],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add a listener to the entire state to trigger rebuilds
|
// Add a listener to the entire state to trigger rebuilds
|
||||||
@@ -112,7 +127,7 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
ref,
|
ref,
|
||||||
state,
|
state,
|
||||||
context,
|
context,
|
||||||
originalPost: originalPost,
|
originalPost: effectiveOriginalPost,
|
||||||
repliedPost: repliedPost,
|
repliedPost: repliedPost,
|
||||||
forwardedPost: forwardedPost,
|
forwardedPost: forwardedPost,
|
||||||
onSuccess: () {
|
onSuccess: () {
|
||||||
@@ -139,8 +154,13 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
height: 24,
|
height: 24,
|
||||||
child: const CircularProgressIndicator(strokeWidth: 2),
|
child: const CircularProgressIndicator(strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: Icon(originalPost != null ? Symbols.edit : Symbols.upload),
|
: Icon(
|
||||||
tooltip: originalPost != null ? 'postUpdate'.tr() : 'postPublish'.tr(),
|
effectiveOriginalPost != null ? Symbols.edit : Symbols.upload,
|
||||||
|
),
|
||||||
|
tooltip:
|
||||||
|
effectiveOriginalPost != null
|
||||||
|
? 'postUpdate'.tr()
|
||||||
|
: 'postPublish'.tr(),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -148,7 +168,7 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
titleText: 'postCompose'.tr(),
|
titleText: 'postCompose'.tr(),
|
||||||
actions: actions,
|
actions: actions,
|
||||||
child: PostComposeCard(
|
child: PostComposeCard(
|
||||||
originalPost: originalPost,
|
originalPost: effectiveOriginalPost,
|
||||||
initialState: restoredInitialState.value ?? initialState,
|
initialState: restoredInitialState.value ?? initialState,
|
||||||
onCancel: () => Navigator.of(context).pop(),
|
onCancel: () => Navigator.of(context).pop(),
|
||||||
onSubmit: () {
|
onSubmit: () {
|
||||||
|
|||||||
Reference in New Issue
Block a user