✨ Post drafts
This commit is contained in:
@ -192,6 +192,21 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text('postDraftBox').tr(),
|
||||
const Gap(20),
|
||||
FloatingActionButton(
|
||||
heroTag: null,
|
||||
tooltip: 'postDraftBox'.tr(),
|
||||
onPressed: () {
|
||||
GoRouter.of(context).pushNamed('postDraftBox');
|
||||
_fabKey.currentState!.toggle();
|
||||
},
|
||||
child: const Icon(Symbols.box_edit),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: NestedScrollView(
|
||||
@ -293,9 +308,11 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
.tr()
|
||||
: category.name,
|
||||
maxLines: 1,
|
||||
).textColor(Theme.of(context)
|
||||
.appBarTheme
|
||||
.foregroundColor!),
|
||||
).textColor(
|
||||
Theme.of(context)
|
||||
.appBarTheme
|
||||
.foregroundColor!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -321,9 +338,11 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
child: Text(
|
||||
'postChannel$channel',
|
||||
maxLines: 1,
|
||||
).tr().textColor(Theme.of(context)
|
||||
.appBarTheme
|
||||
.foregroundColor),
|
||||
).tr().textColor(
|
||||
Theme.of(context)
|
||||
.appBarTheme
|
||||
.foregroundColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
88
lib/screens/post/post_draft.dart
Normal file
88
lib/screens/post/post_draft.dart
Normal file
@ -0,0 +1,88 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:surface/providers/post.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/loading_indicator.dart';
|
||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||
import 'package:surface/widgets/post/post_item.dart';
|
||||
import 'package:very_good_infinite_list/very_good_infinite_list.dart';
|
||||
|
||||
class PostDraftBox extends StatefulWidget {
|
||||
const PostDraftBox({super.key});
|
||||
|
||||
@override
|
||||
State<PostDraftBox> createState() => _PostDraftBoxState();
|
||||
}
|
||||
|
||||
class _PostDraftBoxState extends State<PostDraftBox> {
|
||||
bool _isBusy = false;
|
||||
final List<SnPost> _posts = List.empty(growable: true);
|
||||
int? _totalCount;
|
||||
|
||||
Future<void> _fetchPosts() async {
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final pt = context.read<SnPostContentProvider>();
|
||||
final resp = await pt.listPosts(
|
||||
take: 10,
|
||||
offset: _posts.length,
|
||||
isDraft: true,
|
||||
);
|
||||
final out = resp.$1;
|
||||
_totalCount = resp.$2;
|
||||
if (!mounted) return;
|
||||
_posts.addAll(out);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('postDraftBox').tr(),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
LoadingIndicator(isActive: _isBusy),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () {
|
||||
_posts.clear();
|
||||
return _fetchPosts();
|
||||
},
|
||||
child: InfiniteList(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
hasReachedMax:
|
||||
_totalCount != null && _posts.length >= _totalCount!,
|
||||
itemCount: _posts.length,
|
||||
onFetchData: () => _fetchPosts(),
|
||||
itemBuilder: (context, idx) {
|
||||
final ele = _posts[idx];
|
||||
return OpenablePostItem(
|
||||
data: ele,
|
||||
onChanged: (data) {
|
||||
_posts[idx] = data;
|
||||
},
|
||||
onDeleted: () {
|
||||
_posts.clear();
|
||||
_fetchPosts();
|
||||
},
|
||||
);
|
||||
},
|
||||
separatorBuilder: (_, __) => const Gap(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -138,6 +138,15 @@ class _PostEditorScreenState extends State<PostEditorScreen>
|
||||
],
|
||||
scope: HotKeyScope.inapp,
|
||||
);
|
||||
final HotKey _saveDraftHotKey = HotKey(
|
||||
key: PhysicalKeyboardKey.keyS,
|
||||
modifiers: [
|
||||
(!kIsWeb && Platform.isMacOS)
|
||||
? HotKeyModifier.meta
|
||||
: HotKeyModifier.control
|
||||
],
|
||||
scope: HotKeyScope.inapp,
|
||||
);
|
||||
|
||||
void _registerHotKey() {
|
||||
if (kIsWeb || Platform.isAndroid || Platform.isIOS) return;
|
||||
@ -153,6 +162,11 @@ class _PostEditorScreenState extends State<PostEditorScreen>
|
||||
]);
|
||||
setState(() {});
|
||||
});
|
||||
hotKeyManager.register(_saveDraftHotKey, keyDownHandler: (_) async {
|
||||
if (mounted) {
|
||||
_writeController.sendPost(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _showPublisherPopup() {
|
||||
@ -218,6 +232,7 @@ class _PostEditorScreenState extends State<PostEditorScreen>
|
||||
_writeController.dispose();
|
||||
if (!kIsWeb && !(Platform.isAndroid || Platform.isIOS)) {
|
||||
hotKeyManager.unregister(_pasteHotKey);
|
||||
hotKeyManager.unregister(_saveDraftHotKey);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
@ -269,6 +284,20 @@ class _PostEditorScreenState extends State<PostEditorScreen>
|
||||
: 'untitled'.tr(),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: _writeController.editingDraft
|
||||
? const Icon(Icons.save)
|
||||
: const Icon(Symbols.save_as),
|
||||
onPressed: () {
|
||||
_writeController.sendPost(context, saveAsDraft: true).then(
|
||||
(_) {
|
||||
if (!context.mounted) return;
|
||||
context.showSnackbar('postDraftSaved'.tr());
|
||||
HapticFeedback.mediumImpact();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Symbols.tune),
|
||||
onPressed: _writeController.isBusy ? null : _updateMeta,
|
||||
@ -296,7 +325,8 @@ class _PostEditorScreenState extends State<PostEditorScreen>
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
if (_writeController.editingPost != null)
|
||||
if (_writeController.editingPost != null &&
|
||||
!_writeController.editingDraft)
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4, bottom: 4, left: 20, right: 20),
|
||||
|
Reference in New Issue
Block a user