Merge branch 'master' into feature/more-settings

This commit is contained in:
Marcin Wojnarowski 2021-04-21 13:30:04 +02:00 committed by GitHub
commit bc957ab7b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 11 deletions

View File

@ -6,6 +6,7 @@
- Show scores setting toggle - Show scores setting toggle
- Default listing type for the home tab setting - Default listing type for the home tab setting
- Import Lemmy settings: long press an account in account settings then choose the import option - Import Lemmy settings: long press an account in account settings then choose the import option
- Editing comments
## v0.4.2 - 2021-04-12 ## v0.4.2 - 2021-04-12

View File

@ -132,6 +132,25 @@ class CommentWidget extends HookWidget {
); );
} }
handleEdit() async {
final editedComment = await showCupertinoModalPopup<CommentView>(
context: context,
builder: (_) => WriteComment.edit(
comment: comment.comment,
post: comment.post,
),
);
if (editedComment != null) {
commentTree.comment = editedComment;
// TODO: workaround to force this widget to rebuild
// TODO: These problems should go away once we move to an actual state management lib
// TODO: work being done here should also help: https://github.com/krawieck/lemmur/tree/fix/better-local-updates
(context as Element).markNeedsBuild();
Navigator.of(context).pop();
}
}
void _openMoreMenu(BuildContext context) { void _openMoreMenu(BuildContext context) {
pop() => Navigator.of(context).pop(); pop() => Navigator.of(context).pop();
@ -176,6 +195,12 @@ class CommentWidget extends HookWidget {
pop(); pop();
}, },
), ),
if (isMine)
ListTile(
leading: const Icon(Icons.edit),
title: const Text('Edit'),
onTap: handleEdit,
),
if (isMine) if (isMine)
ListTile( ListTile(
leading: Icon(isDeleted.value ? Icons.restore : Icons.delete), leading: Icon(isDeleted.value ? Icons.restore : Icons.delete),

View File

@ -8,22 +8,30 @@ import '../l10n/l10n.dart';
import 'markdown_mode_icon.dart'; import 'markdown_mode_icon.dart';
import 'markdown_text.dart'; import 'markdown_text.dart';
/// Modal for writing a comment to a given post/comment (aka reply) /// Modal for writing/editing a comment to a given post/comment (aka reply)
/// on submit pops the navigator stack with a [CommentView] /// on submit pops the navigator stack with a [CommentView]
/// or `null` if cancelled /// or `null` if cancelled
class WriteComment extends HookWidget { class WriteComment extends HookWidget {
final Post post; final Post post;
final Comment? comment; final Comment? comment;
final bool _isEdit;
const WriteComment.toPost(this.post) : comment = null; const WriteComment.toPost(this.post)
: comment = null,
_isEdit = false;
const WriteComment.toComment({ const WriteComment.toComment({
required Comment this.comment, required Comment this.comment,
required this.post, required this.post,
}); }) : _isEdit = false;
const WriteComment.edit({
required Comment this.comment,
required this.post,
}) : _isEdit = true;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final controller = useTextEditingController(); final controller =
useTextEditingController(text: _isEdit ? comment?.content : null);
final showFancy = useState(false); final showFancy = useState(false);
final delayed = useDelayedLoading(); final delayed = useDelayedLoading();
final loggedInAction = useLoggedInAction(post.instanceHost); final loggedInAction = useLoggedInAction(post.instanceHost);
@ -56,12 +64,22 @@ class WriteComment extends HookWidget {
delayed.start(); delayed.start();
try { try {
final res = await api.run(CreateComment( final res = await () {
content: controller.text, if (_isEdit) {
postId: post.id, return api.run(EditComment(
parentId: comment?.id, commentId: comment!.id,
auth: token.raw, content: controller.text,
)); auth: token.raw,
));
} else {
return api.run(CreateComment(
content: controller.text,
postId: post.id,
parentId: comment?.id,
auth: token.raw,
));
}
}();
Navigator.of(context).pop(res.commentView); Navigator.of(context).pop(res.commentView);
// ignore: avoid_catches_without_on_clauses // ignore: avoid_catches_without_on_clauses
} catch (e) { } catch (e) {
@ -120,7 +138,9 @@ class WriteComment extends HookWidget {
delayed.pending ? () {} : loggedInAction(handleSubmit), delayed.pending ? () {} : loggedInAction(handleSubmit),
child: delayed.loading child: delayed.loading
? const CircularProgressIndicator() ? const CircularProgressIndicator()
: Text(L10n.of(context)!.post), : Text(_isEdit
? L10n.of(context)!.edit
: L10n.of(context)!.post),
) )
], ],
), ),