Skip to content

Commit

Permalink
When viewing comment context and replying to a comment from that view…
Browse files Browse the repository at this point in the history
…. The same comment context will be reloaded instead of the full comments.
  • Loading branch information
ajsosa committed Jul 22, 2023
1 parent f6de722 commit 268e1d8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/post/bloc/post_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class PostBloc extends Bloc<PostEvent, PostState> {

// for now, refresh the post and refetch the comments
// @todo: insert the new comment in place without requiring a refetch
add(GetPostEvent(postView: state.postView!));
add(GetPostEvent(postView: state.postView!, selectedCommentId: event.selectedCommentId, selectedCommentPath: event.selectedCommentPath));
return emit(state.copyWith(status: PostStatus.success));
} catch (e) {
return emit(state.copyWith(status: PostStatus.failure, errorMessage: e.toString()));
Expand Down
4 changes: 3 additions & 1 deletion lib/post/bloc/post_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class SaveCommentEvent extends PostEvent {
class CreateCommentEvent extends PostEvent {
final String content;
final int? parentCommentId;
final int? selectedCommentId;
final String? selectedCommentPath;

const CreateCommentEvent({required this.content, this.parentCommentId});
const CreateCommentEvent({required this.content, this.parentCommentId, this.selectedCommentId, this.selectedCommentPath});
}

class EditCommentEvent extends PostEvent {
Expand Down
1 change: 1 addition & 0 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class _PostPageState extends State<PostPage> {
postView: state.postView!,
comments: state.comments,
selectedCommentId: state.selectedCommentId,
selectedCommentPath: state.selectedCommentPath,
viewFullCommentsRefreshing: state.viewAllCommentsRefresh,
scrollController: _scrollController,
hasReachedCommentEnd: state.hasReachedCommentEnd),
Expand Down
3 changes: 3 additions & 0 deletions lib/post/pages/post_page_success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PostPageSuccess extends StatefulWidget {
final PostViewMedia postView;
final List<CommentViewTree> comments;
final int? selectedCommentId;
final String? selectedCommentPath;

final ScrollController scrollController;
final bool hasReachedCommentEnd;
Expand All @@ -25,6 +26,7 @@ class PostPageSuccess extends StatefulWidget {
required this.scrollController,
this.hasReachedCommentEnd = false,
this.selectedCommentId,
this.selectedCommentPath,
this.viewFullCommentsRefreshing = false,
});

Expand Down Expand Up @@ -65,6 +67,7 @@ class _PostPageSuccessState extends State<PostPageSuccess> {
child: CommentSubview(
viewFullCommentsRefreshing: widget.viewFullCommentsRefreshing,
selectedCommentId: widget.selectedCommentId,
selectedCommentPath: widget.selectedCommentPath,
now: DateTime.now().toUtc(),
scrollController: widget.scrollController,
postViewMedia: widget.postView,
Expand Down
4 changes: 3 additions & 1 deletion lib/post/utils/comment_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void triggerCommentAction({
required VoteType voteType,
bool? saved,
required CommentViewTree commentViewTree,
int? selectedCommentId,
String? selectedCommentPath,
}) {
switch (swipeAction) {
case SwipeAction.upvote:
Expand Down Expand Up @@ -44,7 +46,7 @@ void triggerCommentAction({
BlocProvider<PostBloc>.value(value: postBloc),
BlocProvider<ThunderBloc>.value(value: thunderBloc),
],
child: CreateCommentModal(commentView: commentViewTree, isEdit: swipeAction == SwipeAction.edit),
child: CreateCommentModal(commentView: commentViewTree, isEdit: swipeAction == SwipeAction.edit, selectedCommentId: selectedCommentId, selectedCommentPath: selectedCommentPath),
),
),
);
Expand Down
5 changes: 5 additions & 0 deletions lib/post/widgets/comment_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CommentCard extends StatefulWidget {

final Set collapsedCommentSet;
final int? selectCommentId;
final String? selectedCommentPath;
final Function(int, bool) onDeleteAction;

final DateTime now;
Expand All @@ -39,6 +40,7 @@ class CommentCard extends StatefulWidget {
required this.now,
this.collapsedCommentSet = const {},
this.selectCommentId,
this.selectedCommentPath,
required this.onDeleteAction,
});

Expand Down Expand Up @@ -171,6 +173,8 @@ class _CommentCardState extends State<CommentCard> with SingleTickerProviderStat
voteType: myVote ?? VoteType.none,
saved: saved,
commentViewTree: widget.commentViewTree,
selectedCommentId: widget.selectCommentId,
selectedCommentPath: widget.selectedCommentPath,
),
}
},
Expand Down Expand Up @@ -414,6 +418,7 @@ class _CommentCardState extends State<CommentCard> with SingleTickerProviderStat
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => CommentCard(
selectedCommentPath: widget.selectedCommentPath,
selectCommentId: widget.selectCommentId,
now: widget.now,
commentViewTree: widget.commentViewTree.replies[index],
Expand Down
3 changes: 3 additions & 0 deletions lib/post/widgets/comment_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CommentSubview extends StatefulWidget {

final PostViewMedia? postViewMedia;
final int? selectedCommentId;
final String? selectedCommentPath;
final ScrollController? scrollController;

final bool hasReachedCommentEnd;
Expand All @@ -36,6 +37,7 @@ class CommentSubview extends StatefulWidget {
required this.onSaveAction,
this.postViewMedia,
this.selectedCommentId,
this.selectedCommentPath,
this.scrollController,
this.hasReachedCommentEnd = false,
this.viewFullCommentsRefreshing = false,
Expand Down Expand Up @@ -136,6 +138,7 @@ class _CommentSubviewState extends State<CommentSubview> with SingleTickerProvid
CommentCard(
now: widget.now,
selectCommentId: widget.selectedCommentId,
selectedCommentPath: widget.selectedCommentPath,
commentViewTree: widget.comments[index - 1],
collapsedCommentSet: collapsedCommentSet,
collapsed: collapsedCommentSet.contains(widget.comments[index - 1].commentView!.comment.id) || widget.level == 2,
Expand Down
7 changes: 6 additions & 1 deletion lib/post/widgets/create_comment_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class CreateCommentModal extends StatefulWidget {
final PostView? postView;
final CommentViewTree? commentView;

final int? selectedCommentId;
final String? selectedCommentPath;

final Comment? comment; // This is passed in from inbox
final String? parentCommentAuthor; // This is passed in from inbox

Expand All @@ -29,6 +32,8 @@ class CreateCommentModal extends StatefulWidget {
this.comment,
this.parentCommentAuthor,
this.isEdit = false,
this.selectedCommentId,
this.selectedCommentPath,
});

@override
Expand Down Expand Up @@ -168,7 +173,7 @@ class _CreateCommentModalState extends State<CreateCommentModal> {
if (widget.comment != null) {
context.read<InboxBloc>().add(CreateInboxCommentReplyEvent(content: _bodyTextController.text, parentCommentId: widget.comment!.id, postId: widget.comment!.postId));
} else {
context.read<PostBloc>().add(CreateCommentEvent(content: _bodyTextController.text, parentCommentId: widget.commentView?.commentView!.comment.id));
context.read<PostBloc>().add(CreateCommentEvent(content: _bodyTextController.text, parentCommentId: widget.commentView?.commentView!.comment.id, selectedCommentId: widget.selectedCommentId, selectedCommentPath: widget.selectedCommentPath));
}
},
icon: isLoading
Expand Down

0 comments on commit 268e1d8

Please sign in to comment.