Skip to content

Commit

Permalink
added ability to reply to comments
Browse files Browse the repository at this point in the history
hjiangsu committed Jun 22, 2023
1 parent 17f5362 commit 8ef1be3
Showing 10 changed files with 93 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Unreleased
### Added
- Added basic ability to post to a community with Markdown
- Added basic ability to create a comment in a post
- Added basic ability to create a comment in a post and to reply to other comments
- Added settings option to enable or disable the in-app update notifications
- Added the instance name to various parts of the app to distinguish communities across instances
- Added blur to NSFW images - contribution from @guigs4
2 changes: 1 addition & 1 deletion lib/community/pages/community_page.dart
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
],
),
drawer: (widget.communityId != null || widget.communityName != null) ? null : const CommunityDrawer(),
floatingActionButton: (state.communityId != null || widget.communityName != null)
floatingActionButton: ((state.communityId != null || widget.communityName != null) && isUserLoggedIn)
? FloatingActionButton(
onPressed: () {
CommunityBloc communityBloc = context.read<CommunityBloc>();
2 changes: 1 addition & 1 deletion lib/community/widgets/community_header.dart
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ class CommunityHeader extends StatelessWidget {
const SizedBox(width: 8.0),
IconText(
icon: const Icon(Icons.sensors_rounded),
text: communityInfo?.online.toString() ?? '0',
text: (communityInfo?.online != null) ? '${communityInfo?.online}' : '-',
),
],
),
1 change: 1 addition & 0 deletions lib/post/bloc/post_bloc.dart
Original file line number Diff line number Diff line change
@@ -307,6 +307,7 @@ class PostBloc extends Bloc<PostEvent, PostState> {
auth: account!.jwt!,
content: event.content,
postId: state.postView!.post.id,
parentId: event.parentCommentId,
),
);

2 changes: 1 addition & 1 deletion lib/post/bloc/post_event.dart
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ class SaveCommentEvent extends PostEvent {

class CreateCommentEvent extends PostEvent {
final String content;
final String? parentCommentId;
final int? parentCommentId;

const CreateCommentEvent({required this.content, this.parentCommentId});
}
50 changes: 27 additions & 23 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:thunder/community/bloc/community_bloc.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/models/post_view_media.dart';

import 'package:thunder/post/bloc/post_bloc.dart';
@@ -17,33 +18,36 @@ class PostPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isUserLoggedIn = context.read<AuthBloc>().state.isLoggedIn;

return Scaffold(
appBar: AppBar(),
floatingActionButton: FloatingActionButton(
onPressed: () {
PostBloc postBloc = context.read<PostBloc>();
floatingActionButton: isUserLoggedIn
? FloatingActionButton(
onPressed: () {
PostBloc postBloc = context.read<PostBloc>();

showModalBottomSheet(
isScrollControlled: true,
context: context,
showDragHandle: true,
builder: (context) {
return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom + 40),
child: FractionallySizedBox(
heightFactor: 0.6,
child: BlocProvider<PostBloc>.value(
value: postBloc,
child: CreateCommentModal(postView: postView),
),
),
);
},
);
},
child: const Icon(Icons.reply_rounded),
),
showModalBottomSheet(
isScrollControlled: true,
context: context,
showDragHandle: true,
builder: (context) {
return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom + 40),
child: FractionallySizedBox(
heightFactor: 0.6,
child: BlocProvider<PostBloc>.value(
value: postBloc,
child: CreateCommentModal(postView: postView),
),
),
);
},
);
},
child: const Icon(Icons.reply_rounded),
)
: null,
body: SafeArea(
child: BlocConsumer<PostBloc, PostState>(
listener: (context, state) {
24 changes: 19 additions & 5 deletions lib/post/widgets/comment_card.dart
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:thunder/account/bloc/account_bloc.dart';
import 'package:thunder/community/pages/community_page.dart';
import 'package:thunder/post/widgets/create_comment_modal.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/instance.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -124,12 +125,25 @@ class _CommentCardState extends State<CommentCard> {
}

if (swipeAction == SwipeAction.reply) {
SnackBar snackBar = const SnackBar(
content: Text('Replying is not yet available'),
behavior: SnackBarBehavior.floating,
PostBloc postBloc = context.read<PostBloc>();

showModalBottomSheet(
isScrollControlled: true,
context: context,
showDragHandle: true,
builder: (context) {
return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom + 40),
child: FractionallySizedBox(
heightFactor: 0.7,
child: BlocProvider<PostBloc>.value(
value: postBloc,
child: CreateCommentModal(commentView: widget.commentViewTree),
),
),
);
},
);
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

if (swipeAction == SwipeAction.save) {
38 changes: 35 additions & 3 deletions lib/post/widgets/create_comment_modal.dart
Original file line number Diff line number Diff line change
@@ -8,14 +8,16 @@ import 'package:markdown_editable_textinput/markdown_text_input.dart';
import 'package:lemmy/lemmy.dart';

import 'package:thunder/community/bloc/community_bloc.dart';
import 'package:thunder/core/models/comment_view_tree.dart';
import 'package:thunder/post/bloc/post_bloc.dart';

const List<Widget> postTypes = <Widget>[Text('Text'), Text('Image'), Text('Link')];

class CreateCommentModal extends StatefulWidget {
final PostView? postView;
final CommentViewTree? commentView;

const CreateCommentModal({super.key, this.postView});
const CreateCommentModal({super.key, this.postView, this.commentView});

@override
State<CreateCommentModal> createState() => _CreateCommentModalState();
@@ -26,6 +28,8 @@ class _CreateCommentModalState extends State<CreateCommentModal> {
bool isClearButtonDisabled = false;
bool isSubmitButtonDisabled = true;

final ScrollController _scrollController = ScrollController();

// final List<bool> _selectedPostType = <bool>[true, false, false];

String description = '';
@@ -52,7 +56,35 @@ class _CreateCommentModalState extends State<CreateCommentModal> {
children: <Widget>[
Text('Create Comment', style: theme.textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 12.0),
// Text(widget.communityInfo?.communityView.community.name ?? 'N/A', style: theme.textTheme.titleLarge),
if (widget.commentView != null) Text('Replying to ${widget.commentView?.creator.name ?? 'N/A'}', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w400)),
if (widget.commentView != null)
Container(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
margin: const EdgeInsets.symmetric(vertical: 8.0),
constraints: const BoxConstraints(maxHeight: 150.0),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(border: Border.all(color: theme.dividerColor), borderRadius: BorderRadius.circular(8.0), color: theme.cardColor),
child: Scrollbar(
controller: _scrollController,
trackVisibility: true,
radius: const Radius.circular(16.0),
child: SingleChildScrollView(
controller: _scrollController,
child: MarkdownBody(
data: widget.commentView?.comment.content ?? 'N/A',
onTapLink: (text, url, title) {},
styleSheet: MarkdownStyleSheet.fromTheme(theme).copyWith(
a: theme.textTheme.bodyMedium,
p: theme.textTheme.bodyMedium,
blockquoteDecoration: const BoxDecoration(
color: Colors.transparent,
border: Border(left: BorderSide(color: Colors.grey, width: 4)),
),
),
),
),
),
),
// Text(
// fetchInstanceNameFromUrl(widget.communityInfo?.communityView.community.actorId) ?? 'N/A',
// style: theme.textTheme.titleMedium?.copyWith(
@@ -154,7 +186,7 @@ class _CreateCommentModalState extends State<CreateCommentModal> {
onPressed: isSubmitButtonDisabled
? null
: () {
context.read<PostBloc>().add(CreateCommentEvent(content: _bodyTextController.text));
context.read<PostBloc>().add(CreateCommentEvent(content: _bodyTextController.text, parentCommentId: widget.commentView?.comment.id));
Navigator.of(context).pop();
},
child: const Text('Submit'),
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -396,8 +396,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "0.1.5-alpha"
resolved-ref: "70027fd1c7637a20757770bdee8cca54dea75b1e"
ref: "0.1.7-alpha"
resolved-ref: da0025e063e1514a282ab3623f3130958817dad2
url: "https://github.com/hjiangsu/lemmy-dart.git"
source: git
version: "1.0.0"
@@ -438,10 +438,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.15"
material_color_utilities:
dependency: transitive
description:
@@ -819,10 +819,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: daadc9baabec998b062c9091525aa95786508b1c48e9c30f1f891b8bf6ff2e64
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.5.2"
translator:
dependency: transitive
description:
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ dependencies:
lemmy:
git:
url: https://github.com/hjiangsu/lemmy-dart.git
ref: 0.1.5-alpha
ref: 0.1.7-alpha
cupertino_icons: ^1.0.2
bloc: ^8.1.2
flutter_bloc: ^8.1.3

0 comments on commit 8ef1be3

Please sign in to comment.