Skip to content

Commit

Permalink
fix(reply): Fix reply hint and action
Browse files Browse the repository at this point in the history
* Clear hint text when message posted.
* Clear saved hint text in reply bar controller when user pressed
  clear hint button.
* Do NOT clear hint text or reply action when editor closed.
  • Loading branch information
realth000 committed Aug 18, 2024
1 parent 9dd3468 commit 113f6d6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/widgets/reply_bar/reply_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ final class _ReplyBarState extends State<_ReplyBar> with LoggerMixin {
focusNode.requestFocus();
}

void _clearTextAndHint() {
setState(() {
_hintText = null;
_replyAction = null;
});
// Clear saved hint text in controller so text not restore
// when next time opens.
widget.controller._hintText = null;
}

void _checkEditorContent() {
final empty = _replyRichController.isEmpty;
if (empty && canSendReply) {
Expand Down Expand Up @@ -419,12 +429,7 @@ final class _ReplyBarState extends State<_ReplyBar> with LoggerMixin {
color: outlineColor,
size: 16,
),
onPressed: () {
setState(() {
_hintText = null;
_replyAction = null;
});
},
onPressed: _clearTextAndHint,
),
],
),
Expand Down Expand Up @@ -546,13 +551,7 @@ final class _ReplyBarState extends State<_ReplyBar> with LoggerMixin {
_replyRichController
..removeListener(_checkEditorContent)
..dispose();
// Mark controller state is disposed.
widget.controller._unbind(
clearParameters: switch (widget.replyType) {
ReplyTypes.notice => false,
ReplyTypes.thread || ReplyTypes.chat || ReplyTypes.chatHistory => true,
},
);
widget.controller._unbind(clearParameters: false);
super.dispose();
}

Expand All @@ -562,10 +561,10 @@ final class _ReplyBarState extends State<_ReplyBar> with LoggerMixin {
listener: (context, state) {
// Clear text one time when user send request succeed.
if (state.status == ReplyStatus.success && state.needClearText) {
// TODO: Implement
_replyRichController.clear();
// Reset flag because we only want to clear the sent text.
context.read<ReplyBloc>().add(ReplyResetClearTextStateTriggered());
_clearTextAndHint();
}
},
child: BlocBuilder<ReplyBloc, ReplyState>(
Expand Down

0 comments on commit 113f6d6

Please sign in to comment.