✨ Editable post
This commit is contained in:
@ -79,7 +79,7 @@ class _AuthorizedAccountScreen extends StatelessWidget {
|
||||
subtitle: Text('accountProfileEditSubtitle').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Symbols.contact_page),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed('accountProfileEdit');
|
||||
},
|
||||
@ -89,7 +89,7 @@ class _AuthorizedAccountScreen extends StatelessWidget {
|
||||
subtitle: Text('accountPublishersSubtitle').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Symbols.face),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed('accountPublishers');
|
||||
},
|
||||
@ -99,7 +99,7 @@ class _AuthorizedAccountScreen extends StatelessWidget {
|
||||
subtitle: Text('accountLogoutSubtitle').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Symbols.logout),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () {
|
||||
context
|
||||
.showConfirmDialog(
|
||||
@ -147,7 +147,7 @@ class _UnauthorizedAccountScreen extends StatelessWidget {
|
||||
subtitle: Text('screenAuthLoginSubtitle').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Symbols.login),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed('authLogin');
|
||||
},
|
||||
@ -157,7 +157,7 @@ class _UnauthorizedAccountScreen extends StatelessWidget {
|
||||
subtitle: Text('screenAuthRegisterSubtitle').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Symbols.person_add),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed('authRegister');
|
||||
},
|
||||
|
@ -121,7 +121,7 @@ class _PublisherNewPersonalState extends State<_PublisherNewPersonal> {
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _isBusy ? null : _performAction,
|
||||
icon: const Icon(Icons.add),
|
||||
icon: const Icon(Symbols.add),
|
||||
label: Text('create').tr(),
|
||||
),
|
||||
).padding(horizontal: 2),
|
||||
|
@ -96,7 +96,7 @@ class _PublisherScreenState extends State<PublisherScreen> {
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.edit),
|
||||
const Icon(Symbols.edit),
|
||||
const Gap(16),
|
||||
Text('edit').tr(),
|
||||
],
|
||||
|
@ -12,8 +12,8 @@ import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
final Map<int, (String label, IconData icon, bool isOtp)> _factorLabelMap = {
|
||||
0: ('authFactorPassword'.tr(), Icons.password, false),
|
||||
1: ('authFactorEmail'.tr(), Icons.email, true),
|
||||
0: ('authFactorPassword'.tr(), Symbols.password, false),
|
||||
1: ('authFactorEmail'.tr(), Symbols.email, true),
|
||||
};
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
@ -225,7 +225,7 @@ class _LoginCheckScreenState extends State<_LoginCheckScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('next').tr(),
|
||||
const Icon(Icons.chevron_right),
|
||||
const Icon(Symbols.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -320,7 +320,7 @@ class _LoginPickerScreenState extends State<_LoginPickerScreen> {
|
||||
),
|
||||
),
|
||||
secondary: Icon(
|
||||
_factorLabelMap[x.type]?.$2 ?? Icons.question_mark,
|
||||
_factorLabelMap[x.type]?.$2 ?? Symbols.question_mark,
|
||||
),
|
||||
title: Text(
|
||||
_factorLabelMap[x.type]?.$1 ?? 'unknown'.tr(),
|
||||
@ -355,7 +355,7 @@ class _LoginPickerScreenState extends State<_LoginPickerScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('next'.tr()),
|
||||
const Icon(Icons.chevron_right),
|
||||
const Icon(Symbols.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -505,7 +505,7 @@ class _LoginLookupScreenState extends State<_LoginLookupScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('next').tr(),
|
||||
const Icon(Icons.chevron_right),
|
||||
const Icon(Symbols.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -538,7 +538,7 @@ class _LoginLookupScreenState extends State<_LoginLookupScreen> {
|
||||
children: [
|
||||
Text('termAcceptLink'.tr()),
|
||||
const Gap(4),
|
||||
const Icon(Icons.launch, size: 14),
|
||||
const Icon(Symbols.launch, size: 14),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
|
@ -146,7 +146,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('next').tr(),
|
||||
const Icon(Icons.chevron_right),
|
||||
const Icon(Symbols.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -27,7 +27,7 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
||||
final List<SnPost> _posts = List.empty(growable: true);
|
||||
int? _postCount;
|
||||
|
||||
void _fetchPosts() async {
|
||||
Future<void> _fetchPosts() async {
|
||||
if (_postCount != null && _posts.length >= _postCount!) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
@ -75,9 +75,6 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('screenExplore').tr(),
|
||||
),
|
||||
floatingActionButtonLocation: ExpandableFab.location,
|
||||
floatingActionButton: ExpandableFab(
|
||||
key: _fabKey,
|
||||
@ -155,15 +152,31 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: InfiniteList(
|
||||
itemCount: _posts.length,
|
||||
isLoading: _isBusy,
|
||||
hasReachedMax: _postCount != null && _posts.length >= _postCount!,
|
||||
onFetchData: _fetchPosts,
|
||||
itemBuilder: (context, idx) {
|
||||
return PostItem(data: _posts[idx]);
|
||||
body: RefreshIndicator(
|
||||
displacement: 40 + MediaQuery.of(context).padding.top,
|
||||
onRefresh: () {
|
||||
_posts.clear();
|
||||
return _fetchPosts();
|
||||
},
|
||||
separatorBuilder: (context, index) => const Divider(),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
title: Text('screenExplore').tr(),
|
||||
floating: true,
|
||||
snap: true,
|
||||
),
|
||||
SliverInfiniteList(
|
||||
itemCount: _posts.length,
|
||||
isLoading: _isBusy,
|
||||
hasReachedMax: _postCount != null && _posts.length >= _postCount!,
|
||||
onFetchData: _fetchPosts,
|
||||
itemBuilder: (context, idx) {
|
||||
return PostItem(data: _posts[idx]);
|
||||
},
|
||||
separatorBuilder: (context, index) => const Divider(),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
@ -12,7 +13,9 @@ import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/types/attachment.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/account/account_image.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:surface/widgets/post/post_media_pending_list.dart';
|
||||
import 'package:surface/widgets/post/post_meta_editor.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
@ -20,7 +23,16 @@ import 'package:provider/provider.dart';
|
||||
|
||||
class PostEditorScreen extends StatefulWidget {
|
||||
final String mode;
|
||||
const PostEditorScreen({super.key, required this.mode});
|
||||
final int? postEditId;
|
||||
final int? postReplyId;
|
||||
final int? postRepostId;
|
||||
const PostEditorScreen({
|
||||
super.key,
|
||||
required this.mode,
|
||||
required this.postEditId,
|
||||
required this.postReplyId,
|
||||
required this.postRepostId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PostEditorScreen> createState() => _PostEditorScreenState();
|
||||
@ -33,6 +45,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
};
|
||||
|
||||
bool _isBusy = false;
|
||||
bool _isLoading = false;
|
||||
|
||||
SnPublisher? _publisher;
|
||||
List<SnPublisher>? _publishers;
|
||||
@ -40,7 +53,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
final List<XFile> _selectedMedia = List.empty(growable: true);
|
||||
final List<SnAttachment> _attachments = List.empty(growable: true);
|
||||
|
||||
void _fetchPublishers() async {
|
||||
Future<void> _fetchPublishers() async {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final resp = await sn.client.get('/cgi/co/publishers');
|
||||
_publishers = List<SnPublisher>.from(
|
||||
@ -51,6 +64,63 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
SnPost? _editingOg;
|
||||
SnPost? _replyingTo;
|
||||
SnPost? _repostingTo;
|
||||
|
||||
Future<void> _fetchRelatedPost() async {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final attach = context.read<SnAttachmentProvider>();
|
||||
|
||||
try {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
if (widget.postEditId != null) {
|
||||
final resp = await sn.client.get('/cgi/co/posts/${widget.postEditId}');
|
||||
final post = SnPost.fromJson(resp.data);
|
||||
final attachments = await attach
|
||||
.getMultiple(post.body['attachments']?.cast<String>() ?? []);
|
||||
_title = post.body['title'];
|
||||
_description = post.body['description'];
|
||||
_contentController.text = post.body['content'] ?? '';
|
||||
_attachments.addAll(attachments);
|
||||
|
||||
_editingOg = post.copyWith(
|
||||
preload: SnPostPreload(
|
||||
attachments: attachments,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.postReplyId != null) {
|
||||
final resp = await sn.client.get('/cgi/co/posts/${widget.postReplyId}');
|
||||
final post = SnPost.fromJson(resp.data);
|
||||
_replyingTo = post.copyWith(
|
||||
preload: SnPostPreload(
|
||||
attachments: await attach
|
||||
.getMultiple(post.body['attachments']?.cast<String>() ?? []),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.postRepostId != null) {
|
||||
final resp =
|
||||
await sn.client.get('/cgi/co/posts/${widget.postRepostId}');
|
||||
final post = SnPost.fromJson(resp.data);
|
||||
_repostingTo = post.copyWith(
|
||||
preload: SnPostPreload(
|
||||
attachments: await attach
|
||||
.getMultiple(post.body['attachments']?.cast<String>() ?? []),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
String? _title;
|
||||
String? _description;
|
||||
|
||||
@ -110,24 +180,35 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
// Posting the content
|
||||
try {
|
||||
final baseProgressVal = _progress!;
|
||||
await sn.client.post('/cgi/co/${widget.mode}', data: {
|
||||
'publisher': _publisher!.id,
|
||||
'content': _contentController.value.text,
|
||||
'title': _title,
|
||||
'description': _description,
|
||||
'attachments': _attachments.map((e) => e.rid).toList(),
|
||||
}, onSendProgress: (count, total) {
|
||||
setState(() {
|
||||
_progress =
|
||||
baseProgressVal + (count / total) * (kPostingProgressWeight / 2);
|
||||
});
|
||||
}, onReceiveProgress: (count, total) {
|
||||
setState(() {
|
||||
_progress = baseProgressVal +
|
||||
(kPostingProgressWeight / 2) +
|
||||
(count / total) * (kPostingProgressWeight / 2);
|
||||
});
|
||||
});
|
||||
await sn.client.request(
|
||||
[
|
||||
'/cgi/co/${widget.mode}',
|
||||
if (widget.postEditId != null) '${widget.postEditId}',
|
||||
].join('/'),
|
||||
data: {
|
||||
'publisher': _publisher!.id,
|
||||
'content': _contentController.value.text,
|
||||
'title': _title,
|
||||
'description': _description,
|
||||
'attachments': _attachments.map((e) => e.rid).toList(),
|
||||
},
|
||||
onSendProgress: (count, total) {
|
||||
setState(() {
|
||||
_progress = baseProgressVal +
|
||||
(count / total) * (kPostingProgressWeight / 2);
|
||||
});
|
||||
},
|
||||
onReceiveProgress: (count, total) {
|
||||
setState(() {
|
||||
_progress = baseProgressVal +
|
||||
(kPostingProgressWeight / 2) +
|
||||
(count / total) * (kPostingProgressWeight / 2);
|
||||
});
|
||||
},
|
||||
options: Options(
|
||||
method: widget.postEditId != null ? 'PUT' : 'POST',
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
} catch (err) {
|
||||
@ -177,6 +258,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
context.showErrorDialog('Unknown post type');
|
||||
Navigator.pop(context);
|
||||
}
|
||||
_fetchRelatedPost();
|
||||
_fetchPublishers();
|
||||
}
|
||||
|
||||
@ -221,6 +303,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
items: <DropdownMenuItem<SnPublisher>>[
|
||||
...(_publishers?.map(
|
||||
(item) => DropdownMenuItem<SnPublisher>(
|
||||
enabled: _editingOg == null,
|
||||
value: item,
|
||||
child: Row(
|
||||
children: [
|
||||
@ -302,9 +385,36 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
padding: EdgeInsets.only(
|
||||
top: _editingOg == null ? 8 : 0,
|
||||
bottom: 8,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Editing Notice
|
||||
if (_editingOg != null)
|
||||
Column(
|
||||
children: [
|
||||
Theme(
|
||||
data: Theme.of(context)
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
minTileHeight: 48,
|
||||
leading:
|
||||
const Icon(Symbols.edit_note).padding(left: 4),
|
||||
title: Text('postEditingNotice')
|
||||
.fontSize(15)
|
||||
.tr(args: ['@${_editingOg!.publisher.name}']),
|
||||
children: <Widget>[
|
||||
PostItem(data: _editingOg!),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
const Gap(8)
|
||||
],
|
||||
),
|
||||
// Content Input Area
|
||||
TextField(
|
||||
controller: _contentController,
|
||||
maxLines: null,
|
||||
@ -338,6 +448,7 @@ class _PostEditorScreenState extends State<PostEditorScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LoadingIndicator(isActive: _isBusy),
|
||||
if (_isBusy && _progress != null)
|
||||
TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0, end: 1),
|
||||
|
Reference in New Issue
Block a user