Add "Scroll Up to Load More" and Fix Old Replies Issue in Chat Component. #12348
+154
−29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #11848
This PR introduces a new feature to load more messages by scrolling up, along with a bug fix that depends on this modification.
This PR is a resubmission as requested, as part of the now-closed #11850 .
New Feature
Chat
componentChat
component could only display the most recent 40 messages, making it impossible to view earlier messages. This update introduces an upward scrolling feature that allows users to load more historical messages when they scroll to the top of the chat window.Fixed
Modification Details
This pull request introduces several changes to the chat history feature, focusing on improving the scrolling experience and handling the loading of older messages. The most important changes include adding new properties and methods to handle infinite scrolling, updating context and hooks to support these changes, and ensuring proper integration across components.
Enhancements to Chat History Scrolling:
web/app/components/base/chat/chat-with-history/chat-wrapper.tsx
: AddedsetChatListSize
andhasMore
to the context and implementedonScrollToTop
to handle loading more messages when the user scrolls to the top. [1] [2] [3]Context and Hook Updates:
web/app/components/base/chat/chat-with-history/context.tsx
: AddedhasMore
andsetChatListSize
to theChatWithHistoryContextValue
type and initialized them in the context. [1] [2]web/app/components/base/chat/chat-with-history/hooks.tsx
: IntroduceduseSWRInfinite
for fetching chat history with pagination and added logic to determine if there are more messages to load. [1] [2] [3] [4] [5] [6]Component Integration:
web/app/components/base/chat/chat-with-history/index.tsx
: Passed the new context values (hasMore
andsetChatListSize
) to theChatWithHistory
component. [1] [2]web/app/components/base/chat/chat/index.tsx
: Updated theChat
component to handle theonScrollToTop
callback and display a message when all messages are loaded. [1] [2] [3] [4] [5] [6]Localization:
web/i18n/en-US/share-app.ts
andweb/i18n/zh-Hans/share-app.ts
: Added translations for the "Loaded all messages" message. [1] [2]API Adjustments:
web/service/share.ts
: Updated thefetchChatList
function to support pagination by accepting an optionalfirstId
parameter.Checklist
Important
Please review the checklist below before submitting your pull request.
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint gods