🐛 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,12 +33,17 @@ 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,8 +58,7 @@ 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);
|
||||||
|
|
||||||
@@ -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() {
|
||||||
@@ -147,8 +156,7 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
(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,
|
||||||
@@ -157,8 +165,7 @@ class PostComposeSheet extends HookConsumerWidget {
|
|||||||
: Icon(
|
: Icon(
|
||||||
effectiveOriginalPost != null ? Symbols.edit : Symbols.upload,
|
effectiveOriginalPost != null ? Symbols.edit : Symbols.upload,
|
||||||
),
|
),
|
||||||
tooltip:
|
tooltip: effectiveOriginalPost != null
|
||||||
effectiveOriginalPost != null
|
|
||||||
? 'postUpdate'.tr()
|
? 'postUpdate'.tr()
|
||||||
: 'postPublish'.tr(),
|
: 'postPublish'.tr(),
|
||||||
),
|
),
|
||||||
@@ -192,8 +199,7 @@ 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,
|
||||||
@@ -226,8 +232,7 @@ 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