fixed msg.

This commit is contained in:
Livinglist
2022-02-27 19:52:42 -08:00
parent 1719036d18
commit ddb437cd60
4 changed files with 46 additions and 58 deletions

View File

@ -16,7 +16,7 @@ class EditState extends Equatable {
final Item? replyingTo; final Item? replyingTo;
final Item? itemBeingEdited; final Item? itemBeingEdited;
bool get showReplyBox => replyingTo != null; bool get showReplyBox => replyingTo != null || itemBeingEdited != null;
EditState copyWith({String? text}) { EditState copyWith({String? text}) {
return EditState( return EditState(

View File

@ -31,9 +31,6 @@ class PostCubit extends Cubit<PostState> {
emit(state.copyWith(status: PostStatus.loading)); emit(state.copyWith(status: PostStatus.loading));
final successful = await _postRepository.edit(id: id, text: text); final successful = await _postRepository.edit(id: id, text: text);
// final successful =
// await Future<bool>.delayed(const Duration(seconds: 2), () => true);
if (successful) { if (successful) {
emit(state.copyWith(status: PostStatus.successful)); emit(state.copyWith(status: PostStatus.successful));
} else { } else {

View File

@ -143,15 +143,13 @@ class _StoryScreenState extends State<StoryScreen> {
return BlocConsumer<PostCubit, PostState>( return BlocConsumer<PostCubit, PostState>(
listener: (context, postState) { listener: (context, postState) {
if (postState.status == PostStatus.successful) { if (postState.status == PostStatus.successful) {
editCubit.onReplySubmittedSuccessfully(); final verb =
editCubit.state.replyingTo == null ? 'updated' : 'submitted';
final msg = 'Comment $verb! ${(happyFaces..shuffle()).first}';
focusNode.unfocus(); focusNode.unfocus();
HapticFeedback.lightImpact(); HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(SnackBar( showSnackBar(content: msg);
content: Text( editCubit.onReplySubmittedSuccessfully();
'Comment submitted! ${(happyFaces..shuffle()).first}',
),
backgroundColor: Colors.orange,
));
context.read<PostCubit>().reset(); context.read<PostCubit>().reset();
} else if (postState.status == PostStatus.failure) { } else if (postState.status == PostStatus.failure) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
@ -179,10 +177,12 @@ class _StoryScreenState extends State<StoryScreen> {
builder: (context, state) { builder: (context, state) {
return BlocConsumer<EditCubit, EditState>( return BlocConsumer<EditCubit, EditState>(
listenWhen: (previous, current) { listenWhen: (previous, current) {
return previous.replyingTo != current.replyingTo; return previous.replyingTo != current.replyingTo ||
previous.itemBeingEdited != current.itemBeingEdited;
}, },
listener: (context, editState) { listener: (context, editState) {
if (editState.replyingTo != null) { if (editState.replyingTo != null ||
editState.itemBeingEdited != null) {
if (editState.text == null) { if (editState.text == null) {
commentEditingController.clear(); commentEditingController.clear();
} else { } else {
@ -198,6 +198,7 @@ class _StoryScreenState extends State<StoryScreen> {
}, },
builder: (context, editState) { builder: (context, editState) {
final replyingTo = editCubit.state.replyingTo; final replyingTo = editCubit.state.replyingTo;
final editing = editCubit.state.itemBeingEdited;
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
@ -507,11 +508,7 @@ class _StoryScreenState extends State<StoryScreen> {
if (cmt.deleted || cmt.dead) { if (cmt.deleted || cmt.dead) {
return; return;
} }
if (cmt != replyingTo) {
commentEditingController.clear(); commentEditingController.clear();
}
editCubit.onEditTapped(cmt); editCubit.onEditTapped(cmt);
focusNode.requestFocus(); focusNode.requestFocus();
}, },
@ -557,6 +554,7 @@ class _StoryScreenState extends State<StoryScreen> {
child: ReplyBox( child: ReplyBox(
focusNode: focusNode, focusNode: focusNode,
textEditingController: commentEditingController, textEditingController: commentEditingController,
editing: editing,
replyingTo: replyingTo, replyingTo: replyingTo,
isLoading: postState.status == PostStatus.loading, isLoading: postState.status == PostStatus.loading,
onSendTapped: onSendTapped, onSendTapped: onSendTapped,
@ -781,10 +779,7 @@ class _StoryScreenState extends State<StoryScreen> {
}).then((yesTapped) { }).then((yesTapped) {
if (yesTapped ?? false) { if (yesTapped ?? false) {
context.read<AuthBloc>().add(AuthFlag(item: item)); context.read<AuthBloc>().add(AuthFlag(item: item));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( showSnackBar(content: 'Comment flagged!');
content: Text('Comment flagged!'),
backgroundColor: Colors.orange,
));
} }
}); });
} }
@ -853,10 +848,7 @@ class _StoryScreenState extends State<StoryScreen> {
} else { } else {
context.read<BlocklistCubit>().addToBlocklist(item.by); context.read<BlocklistCubit>().addToBlocklist(item.by);
} }
ScaffoldMessenger.of(context).showSnackBar(SnackBar( showSnackBar(content: 'User ${isBlocked ? 'unblocked' : 'blocked'}!');
content: Text('User ${isBlocked ? 'unblocked' : 'blocked'}!'),
backgroundColor: Colors.orange,
));
} }
}); });
} }
@ -897,12 +889,7 @@ class _StoryScreenState extends State<StoryScreen> {
listener: (context, state) { listener: (context, state) {
if (state.isLoggedIn) { if (state.isLoggedIn) {
Navigator.pop(context); Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar( showSnackBar(content: 'Logged in successfully! $happyFace');
SnackBar(
content: Text('Logged in successfully! $happyFace'),
backgroundColor: Colors.orange,
),
);
} }
}, },
builder: (context, state) { builder: (context, state) {

View File

@ -11,6 +11,7 @@ class ReplyBox extends StatefulWidget {
required this.focusNode, required this.focusNode,
required this.textEditingController, required this.textEditingController,
required this.replyingTo, required this.replyingTo,
required this.editing,
required this.onSendTapped, required this.onSendTapped,
required this.onCloseTapped, required this.onCloseTapped,
required this.onChanged, required this.onChanged,
@ -20,6 +21,7 @@ class ReplyBox extends StatefulWidget {
final FocusNode focusNode; final FocusNode focusNode;
final TextEditingController textEditingController; final TextEditingController textEditingController;
final Item? replyingTo; final Item? replyingTo;
final Item? editing;
final VoidCallback onSendTapped; final VoidCallback onSendTapped;
final VoidCallback onCloseTapped; final VoidCallback onCloseTapped;
final ValueChanged<String> onChanged; final ValueChanged<String> onChanged;
@ -66,14 +68,15 @@ class _ReplyBoxState extends State<ReplyBox> {
), ),
child: Text( child: Text(
widget.replyingTo == null widget.replyingTo == null
? '' ? 'Editing'
: 'Replying ' : 'Replying '
'${widget.replyingTo?.by}', '${widget.replyingTo?.by}',
style: const TextStyle(color: Colors.grey), style: const TextStyle(color: Colors.grey),
), ),
), ),
const Spacer(), const Spacer(),
if (widget.replyingTo != null && !widget.isLoading) ...[ if (!widget.isLoading) ...[
if (widget.replyingTo != null) ...[
AnimatedOpacity( AnimatedOpacity(
opacity: expanded ? 1 : 0, opacity: expanded ? 1 : 0,
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
@ -102,6 +105,7 @@ class _ReplyBoxState extends State<ReplyBox> {
}); });
}, },
), ),
],
IconButton( IconButton(
key: const Key('close'), key: const Key('close'),
icon: const Icon( icon: const Icon(