-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Chat page retains the display of the last conversation #2301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,16 @@ function getChatLog(id: string, refresh?: boolean) { | |
log.asyncGetChatLogClient(id, page, left_loading).then((res: any) => { | ||
chatLogData.value = res.data.records | ||
if (refresh) { | ||
currentChatName.value = chatLogData.value?.[0].abstract | ||
currentChatName.value = chatLogData.value?.[0]?.abstract | ||
} else { | ||
paginationConfig.value.current_page = 1 | ||
paginationConfig.value.total = 0 | ||
currentRecordList.value = [] | ||
currentChatId.value = chatLogData.value?.[0]?.id || 'new' | ||
currentChatName.value = chatLogData.value?.[0]?.abstract || t('chat.createChat') | ||
if (currentChatId.value !== 'new') { | ||
getChatRecord() | ||
} | ||
} | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code ReviewThe provided
Here’s an improved version of the function incorporating these considerations: function getChatLog(id: string, refresh?: boolean) {
const fetchMoreLogs = async (page: number): Promise<void> => {
await log.asyncGetChatLogClient(id, page, left_loading)
.then(({ data: { records } }) => {
chatLogData.value.push(...records);
if (!refresh && !records.length) {
paginationConfig.value.current_page = 1;
paginationConfig.value.total = 0;
currentRecordList.value = [];
currentChatId.value = '';
currentChatName.value = t('chat.createChat');
return;
}
// Pagination handling
paginationConfig.value.current_page++;
paginationConfig.value.total = records.length; // Assuming total length is correctly calculated by backend
// Default values for next record set
if (paginationConfig.value.current_page <= paginationConfig.value.last_page) {
fetchMoreLogs(paginationConfig.value.current_page);
}
})
.catch((error) => {
console.error("Error fetching chat log:", error); // Log errors for debugging
// Handle specific error cases here if necessary
});
};
log.asyncGetChatLogClient(id, left_loading).then(({ data: { records } }) => {
chatLogData.value = records;
if (refresh) {
currentChatName.value = chatLogData.value?.[0]?.abstract || t('chat.createChat');
} else {
paginationConfig.value.current_page = 1;
paginationConfig.value.total = records.length;
currentRecordList.value = [];
currentChatId.value = chatLogData.value?.[0]?.id || '';
// Start fetching additional pages if necessary
if (paginationConfig.value.total > 0) {
fetchMoreLogs(2);
}
// Set initial chat name
currentChatName.value = chatLogData.value?.[0]?.abstract || t('chat.createChat');
}
// Optionally, call getChatRecord() here if needed initially
})
} Key Changes:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet seems to be part of a function that retrieves chat logs. Here are some potential issues and optimizations:
State Management: Ensure that
chatLogData.value
,paginationConfig.current_page
,paginationConfig.total
,currentRecordList.value
, andcurrentChatId.value
are correctly defined and updated throughout the application.Pagination Reset: You should handle cases where no records are fetched (
res.data.records.length === 0
) before resetting pagination configuration and lists.Error Handling:
asyncGetChatLogClient
..catch()
to handle network or API errors gracefully.Function Calls after Data Update**:
getChatRecord()
are not dependent on data being loaded asynchronously.Code Clarity:
Here’s a revised version with suggested improvements:
Additional Tips: