🐛 Fix article edit shows the post edit sheet
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
@@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:island/widgets/app_scaffold.dart';
|
import 'package:island/widgets/app_scaffold.dart';
|
||||||
import 'package:island/widgets/extended_refresh_indicator.dart';
|
import 'package:island/widgets/extended_refresh_indicator.dart';
|
||||||
import 'package:island/widgets/post/post_item.dart';
|
import 'package:island/widgets/post/post_item.dart';
|
||||||
|
import 'package:island/widgets/post/post_item_skeleton.dart';
|
||||||
import 'package:island/widgets/posts/post_filter.dart';
|
import 'package:island/widgets/posts/post_filter.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:island/pods/post/post_list.dart';
|
import 'package:island/pods/post/post_list.dart';
|
||||||
@@ -140,6 +141,12 @@ class PostSearchScreen extends HookConsumerWidget {
|
|||||||
).notifier,
|
).notifier,
|
||||||
isSliver: true,
|
isSliver: true,
|
||||||
isRefreshable: false,
|
isRefreshable: false,
|
||||||
|
footerSkeletonChild: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
),
|
||||||
|
child: const PostItemSkeleton(),
|
||||||
|
),
|
||||||
itemBuilder: (context, index, post) {
|
itemBuilder: (context, index, post) {
|
||||||
return Card(
|
return Card(
|
||||||
margin: EdgeInsets.symmetric(
|
margin: EdgeInsets.symmetric(
|
||||||
@@ -261,6 +268,10 @@ class PostSearchScreen extends HookConsumerWidget {
|
|||||||
).notifier,
|
).notifier,
|
||||||
isSliver: true,
|
isSliver: true,
|
||||||
isRefreshable: false,
|
isRefreshable: false,
|
||||||
|
footerSkeletonChild: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
child: const PostItemSkeleton(),
|
||||||
|
),
|
||||||
itemBuilder: (context, index, post) {
|
itemBuilder: (context, index, post) {
|
||||||
return Center(
|
return Center(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
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';
|
||||||
@@ -32,16 +33,21 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
SnPost? originalPost,
|
SnPost? originalPost,
|
||||||
PostComposeInitialState? initialState,
|
PostComposeInitialState? initialState,
|
||||||
}) {
|
}) {
|
||||||
|
// Check if editing an article
|
||||||
|
if (originalPost != null && originalPost.type == 1) {
|
||||||
|
context.pushNamed('articleEdit', pathParameters: {'id': originalPost.id});
|
||||||
|
return Future.value(true);
|
||||||
|
}
|
||||||
|
|
||||||
return showModalBottomSheet<bool>(
|
return showModalBottomSheet<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
builder:
|
builder: (context) => PostComposeSheet(
|
||||||
(context) => PostComposeSheet(
|
originalPost: originalPost,
|
||||||
originalPost: originalPost,
|
initialState: initialState,
|
||||||
initialState: initialState,
|
isBottomSheet: true,
|
||||||
isBottomSheet: true,
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,10 +58,9 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
final prompted = useState(false);
|
final prompted = useState(false);
|
||||||
|
|
||||||
// Fetch full post data if we're editing a post
|
// Fetch full post data if we're editing a post
|
||||||
final fullPostData =
|
final fullPostData = originalPost != null
|
||||||
originalPost != null
|
? ref.watch(postProvider(originalPost!.id))
|
||||||
? ref.watch(postProvider(originalPost!.id))
|
: const AsyncValue.data(null);
|
||||||
: const AsyncValue.data(null);
|
|
||||||
|
|
||||||
// Use the full post data if available, otherwise fall back to originalPost
|
// Use the full post data if available, otherwise fall back to originalPost
|
||||||
final effectiveOriginalPost = fullPostData.when(
|
final effectiveOriginalPost = fullPostData.when(
|
||||||
@@ -115,7 +120,11 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
}, [drafts, prompted.value]);
|
}, [drafts, prompted.value]);
|
||||||
|
|
||||||
// Dispose state when widget is disposed
|
// Dispose state when widget is disposed
|
||||||
useEffect(() => () => ComposeLogic.dispose(state), []);
|
useEffect(
|
||||||
|
() =>
|
||||||
|
() => ComposeLogic.dispose(state),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
// Helper methods for actions
|
// Helper methods for actions
|
||||||
void showSettingsSheet() {
|
void showSettingsSheet() {
|
||||||
@@ -145,22 +154,20 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
IconButton(
|
IconButton(
|
||||||
onPressed:
|
onPressed:
|
||||||
(state.submitting.value || state.currentPublisher.value == null)
|
(state.submitting.value || state.currentPublisher.value == null)
|
||||||
? null
|
? null
|
||||||
: performSubmit,
|
: performSubmit,
|
||||||
icon:
|
icon: state.submitting.value
|
||||||
state.submitting.value
|
? SizedBox(
|
||||||
? SizedBox(
|
width: 24,
|
||||||
width: 24,
|
height: 24,
|
||||||
height: 24,
|
child: const CircularProgressIndicator(strokeWidth: 2),
|
||||||
child: const CircularProgressIndicator(strokeWidth: 2),
|
)
|
||||||
)
|
: Icon(
|
||||||
: Icon(
|
effectiveOriginalPost != null ? Symbols.edit : Symbols.upload,
|
||||||
effectiveOriginalPost != null ? Symbols.edit : Symbols.upload,
|
),
|
||||||
),
|
tooltip: effectiveOriginalPost != null
|
||||||
tooltip:
|
? 'postUpdate'.tr()
|
||||||
effectiveOriginalPost != null
|
: 'postPublish'.tr(),
|
||||||
? 'postUpdate'.tr()
|
|
||||||
: 'postPublish'.tr(),
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -192,29 +199,28 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
final restore = await showDialog<bool>(
|
final restore = await showDialog<bool>(
|
||||||
context: ref.context,
|
context: ref.context,
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
builder:
|
builder: (context) => AlertDialog(
|
||||||
(context) => AlertDialog(
|
title: Text('restoreDraftTitle'.tr()),
|
||||||
title: Text('restoreDraftTitle'.tr()),
|
content: Column(
|
||||||
content: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text('restoreDraftMessage'.tr()),
|
||||||
Text('restoreDraftMessage'.tr()),
|
const SizedBox(height: 16),
|
||||||
const SizedBox(height: 16),
|
_buildCompactDraftPreview(context, latestDraft),
|
||||||
_buildCompactDraftPreview(context, latestDraft),
|
],
|
||||||
],
|
),
|
||||||
),
|
actions: [
|
||||||
actions: [
|
TextButton(
|
||||||
TextButton(
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
child: Text('no'.tr()),
|
||||||
child: Text('no'.tr()),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
|
||||||
child: Text('yes'.tr()),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
|
child: Text('yes'.tr()),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
if (restore == true) {
|
if (restore == true) {
|
||||||
// Delete the old draft
|
// Delete the old draft
|
||||||
@@ -226,10 +232,9 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
description: latestDraft.description,
|
description: latestDraft.description,
|
||||||
content: latestDraft.content,
|
content: latestDraft.content,
|
||||||
visibility: latestDraft.visibility,
|
visibility: latestDraft.visibility,
|
||||||
attachments:
|
attachments: latestDraft.attachments
|
||||||
latestDraft.attachments
|
.map((e) => UniversalFile.fromAttachment(e))
|
||||||
.map((e) => UniversalFile.fromAttachment(e))
|
.toList(),
|
||||||
.toList(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user