Skip to content

Commit

Permalink
chore: more ai ui fixes (#6799)
Browse files Browse the repository at this point in the history
* chore: more ai ui fixes

* fix: messages arriving out of order

* chore: don't drop focus when clicking on sample questions
  • Loading branch information
richardshiue authored Nov 15, 2024
1 parent 2256835 commit 521d74e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
// Loading messages
startLoadingPrevMessage: () async {
Int64? beforeMessageId;
final oldestMessage = _getOlderstMessage();
final oldestMessage = _getOldestMessage();
if (oldestMessage != null) {
try {
beforeMessageId = Int64.parseInt(oldestMessage.id);
Expand All @@ -107,8 +107,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
Log.debug("did load previous messages: ${messages.length}");
final onetimeMessages = _getOnetimeMessages();
final allMessages = _permanentMessages();
final uniqueMessages = {...allMessages, ...messages}.toList()
..sort((a, b) => b.id.compareTo(a.id));
final uniqueMessages = {...allMessages, ...messages}.toList();

uniqueMessages.insertAll(0, onetimeMessages);

Expand All @@ -123,8 +122,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
didLoadLatestMessages: (List<Message> messages) {
final onetimeMessages = _getOnetimeMessages();
final allMessages = _permanentMessages();
final uniqueMessages = {...allMessages, ...messages}.toList()
..sort((a, b) => b.id.compareTo(a.id));
final uniqueMessages = {...allMessages, ...messages}.toList();
uniqueMessages.insertAll(0, onetimeMessages);
emit(
state.copyWith(
Expand Down Expand Up @@ -351,7 +349,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
return messages;
}

Message? _getOlderstMessage() {
Message? _getOldestMessage() {
// get the last message that is not a one-time message
final message = state.messages.lastWhereOrNull((element) {
return !(element.metadata?.containsKey(onetimeShotType) == true);
Expand Down
12 changes: 7 additions & 5 deletions frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ class _ChatContentPage extends StatelessWidget {
.add(const ChatEvent.startLoadingPrevMessage());
}
},
emptyState: ChatWelcomePage(
userProfile: userProfile,
onSelectedQuestion: (question) => context
.read<ChatBloc>()
.add(ChatEvent.sendMessage(message: question)),
emptyState: TextFieldTapRegion(
child: ChatWelcomePage(
userProfile: userProfile,
onSelectedQuestion: (question) => context
.read<ChatBloc>()
.add(ChatEvent.sendMessage(message: question)),
),
),
messageWidthRatio: AIChatUILayout.messageWidthRatio,
textMessageBuilder: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class _MobileAIPromptInputState extends State<MobileAIPromptInput> {
child: IntrinsicHeight(
child: Row(
children: [
const HSpace(6.0),
const HSpace(8.0),
Expanded(child: _inputTextField(context)),
_mentionButton(),
const HSpace(6.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> {
shrinkWrap: true,
// the editor is not editable in the chat
editable: false,
disableKeyboardService: true,
editorStyle: editorStyle,
editorScrollController: scrollController,
blockComponentBuilders: blockBuilders,
Expand Down

0 comments on commit 521d74e

Please sign in to comment.