Post draft

This commit is contained in:
2024-07-09 21:23:38 +08:00
parent 10ed44d2e2
commit a0fe3f918e
14 changed files with 396 additions and 65 deletions

View File

@ -8,30 +8,30 @@ import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/posts/post_item.dart';
import 'package:solian/widgets/posts/tags_field.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:textfield_tags/textfield_tags.dart';
import 'package:badges/badges.dart' as badges;
class PostPublishingArguments {
class PostPublishArguments {
final Post? edit;
final Post? reply;
final Post? repost;
final Realm? realm;
PostPublishingArguments({this.edit, this.reply, this.repost, this.realm});
PostPublishArguments({this.edit, this.reply, this.repost, this.realm});
}
class PostPublishingScreen extends StatefulWidget {
class PostPublishScreen extends StatefulWidget {
final Post? edit;
final Post? reply;
final Post? repost;
final Realm? realm;
const PostPublishingScreen({
const PostPublishScreen({
super.key,
this.edit,
this.reply,
@ -40,10 +40,10 @@ class PostPublishingScreen extends StatefulWidget {
});
@override
State<PostPublishingScreen> createState() => _PostPublishingScreenState();
State<PostPublishScreen> createState() => _PostPublishScreenState();
}
class _PostPublishingScreenState extends State<PostPublishingScreen> {
class _PostPublishScreenState extends State<PostPublishScreen> {
final _contentController = TextEditingController();
final _tagsController = StringTagController();
@ -51,6 +51,8 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
List<int> _attachments = List.empty();
bool _isDraft = false;
void showAttachments() {
showModalBottomSheet(
context: context,
@ -77,6 +79,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
'tags': _tagsController.getTags?.map((x) => {'alias': x}).toList() ??
List.empty(),
'attachments': _attachments,
'is_draft': _isDraft,
if (widget.edit != null) 'alias': widget.edit!.alias,
if (widget.reply != null) 'reply_to': widget.reply!.id,
if (widget.repost != null) 'repost_to': widget.repost!.id,
@ -102,6 +105,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
if (widget.edit != null) {
_contentController.text = widget.edit!.content;
_attachments = widget.edit!.attachments ?? List.empty();
_isDraft = widget.edit!.isDraft ?? false;
}
}
@ -117,8 +121,6 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
@override
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
final notifyBannerActions = [
TextButton(
onPressed: cancelAction,
@ -130,14 +132,18 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
color: Theme.of(context).colorScheme.surface,
child: Scaffold(
appBar: AppBar(
title: AppBarTitle('postPublishing'.tr),
title: AppBarTitle('postPublish'.tr),
centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [
TextButton(
onPressed: _isBusy ? null : () => applyPost(),
child: Text('postAction'.tr.toUpperCase()),
child: Text(
_isDraft
? 'draftSave'.tr.toUpperCase()
: 'postAction'.tr.toUpperCase(),
),
)
],
),
@ -194,22 +200,6 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
).paddingOnly(bottom: 8),
],
),
FutureBuilder(
future: auth.getProfile(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListTile(
leading: AccountAvatar(
content: snapshot.data?.body!['avatar'],
radius: 22),
title: Text(snapshot.data?.body!['nick']),
subtitle: Text('postIdentityNotify'.tr),
);
} else {
return Container();
}
},
),
if (widget.realm != null)
MaterialBanner(
leading: const Icon(Icons.group),
@ -247,6 +237,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
left: 0,
right: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TagsField(
initialTags:
@ -257,17 +248,30 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
const Divider(thickness: 0.3, height: 0.3),
SizedBox(
height: 56,
child: Row(
child: ListView(
scrollDirection: Axis.horizontal,
children: [
TextButton(
style: TextButton.styleFrom(
shape: const CircleBorder(),
IconButton(
icon: _isDraft
? const Icon(Icons.drive_file_rename_outline)
: const Icon(Icons.public),
color: _isDraft
? Colors.grey.shade600
: Colors.green.shade700,
onPressed: () {
setState(() => _isDraft = !_isDraft);
},
),
badges.Badge(
badgeContent: Text(_attachments.length.toString()),
showBadge: _attachments.isNotEmpty,
child: IconButton(
icon: const Icon(Icons.camera_alt),
onPressed: () => showAttachments(),
),
child: const Icon(Icons.camera_alt),
onPressed: () => showAttachments(),
)
],
),
).paddingSymmetric(horizontal: 6, vertical: 8),
),
],
),