Fix chat autocomplete not updating (#267)

This commit is contained in:
Tommy
2023-06-02 20:12:28 -04:00
committed by GitHub
parent 8c994363c0
commit 843931c079
3 changed files with 41 additions and 12 deletions

View File

@ -127,6 +127,9 @@ abstract class ChatStoreBase with Store {
@readonly
var _autoScroll = true;
@readonly
var _inputText = '';
@readonly
var _showSendButton = false;
@ -204,12 +207,13 @@ abstract class ChatStoreBase with Store {
// Add a listener to the textfield that will show/hide the autocomplete bar if focused.
// Will also rebuild the autocomplete bar when typing, refreshing the results as the user types.
textController.addListener(() => _showEmoteAutocomplete =
!_showMentionAutocomplete &&
textFieldFocusNode.hasFocus &&
textController.text.split(' ').last.isNotEmpty);
textController.addListener(() {
_inputText = textController.text;
_showEmoteAutocomplete = !_showMentionAutocomplete &&
textFieldFocusNode.hasFocus &&
textController.text.split(' ').last.isNotEmpty;
_showSendButton = textController.text.isNotEmpty;
_showMentionAutocomplete = textFieldFocusNode.hasFocus &&
textController.text.split(' ').last.startsWith('@');

View File

@ -119,6 +119,24 @@ mixin _$ChatStore on ChatStoreBase, Store {
});
}
late final _$_inputTextAtom =
Atom(name: 'ChatStoreBase._inputText', context: context);
String get inputText {
_$_inputTextAtom.reportRead();
return super._inputText;
}
@override
String get _inputText => inputText;
@override
set _inputText(String value) {
_$_inputTextAtom.reportWrite(value, super._inputText, () {
super._inputText = value;
});
}
late final _$_showSendButtonAtom =
Atom(name: 'ChatStoreBase._showSendButton', context: context);

View File

@ -39,16 +39,23 @@ class ChatBottomBar extends StatelessWidget {
...chatStore.assetsStore.ffzEmotes,
...chatStore.assetsStore.sevenTVEmotes
]
.where((emote) => emote.name.toLowerCase().contains(
chatStore.textController.text.split(' ').last.toLowerCase()))
.where(
(emote) => emote.name.toLowerCase().contains(
chatStore.inputText.split(' ').last.toLowerCase(),
),
)
.toList();
final matchingChatters = chatStore.chatDetailsStore.chatUsers
.where((chatter) => chatter.contains(chatStore.textController.text
.split(' ')
.last
.replaceFirst('@', '')
.toLowerCase()))
.where(
(chatter) => chatter.contains(
chatStore.inputText
.split(' ')
.last
.replaceFirst('@', '')
.toLowerCase(),
),
)
.toList();
return Column(