优化历史会话排序逻辑,按首条消息时间排序
This commit is contained in:
@@ -73,7 +73,6 @@ const getSessionGroupLabel = (timestamp: number) => {
|
||||
};
|
||||
|
||||
export const AgentHistoryPanel = ({
|
||||
|
||||
sessions,
|
||||
activeSessionId,
|
||||
isHydrating = false,
|
||||
@@ -95,11 +94,25 @@ export const AgentHistoryPanel = ({
|
||||
return sessions.filter((session) => session.title.toLowerCase().includes(normalizedKeyword));
|
||||
}, [keyword, sessions]);
|
||||
|
||||
const sortedFilteredSessions = React.useMemo(
|
||||
() =>
|
||||
[...filteredSessions].sort((left, right) => {
|
||||
const createdAtDiff = right.createdAt - left.createdAt;
|
||||
if (createdAtDiff !== 0) return createdAtDiff;
|
||||
|
||||
const updatedAtDiff = right.updatedAt - left.updatedAt;
|
||||
if (updatedAtDiff !== 0) return updatedAtDiff;
|
||||
|
||||
return right.id.localeCompare(left.id);
|
||||
}),
|
||||
[filteredSessions],
|
||||
);
|
||||
|
||||
const groupedSessions = React.useMemo(() => {
|
||||
const groups = new Map<string, ChatSessionSummary[]>();
|
||||
|
||||
filteredSessions.forEach((session) => {
|
||||
const label = getSessionGroupLabel(session.updatedAt);
|
||||
sortedFilteredSessions.forEach((session) => {
|
||||
const label = getSessionGroupLabel(session.createdAt);
|
||||
const existing = groups.get(label);
|
||||
if (existing) {
|
||||
existing.push(session);
|
||||
@@ -109,7 +122,7 @@ export const AgentHistoryPanel = ({
|
||||
});
|
||||
|
||||
return Array.from(groups.entries());
|
||||
}, [filteredSessions]);
|
||||
}, [sortedFilteredSessions]);
|
||||
|
||||
const pendingDeleteSession = filteredSessions.find(
|
||||
(session) => session.id === pendingDeleteSessionId,
|
||||
@@ -390,7 +403,7 @@ export const AgentHistoryPanel = ({
|
||||
{session.title}
|
||||
</Typography>
|
||||
<Typography variant="caption" color="text.secondary" sx={{ mt: 0.5, display: "block" }}>
|
||||
{formatRelativeDate(session.updatedAt)}
|
||||
{formatRelativeDate(session.createdAt)}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user