From 0115d4a1452d6be3d1abd3f4fead76cf66d4ea05 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 13 Jul 2025 19:06:05 -0700 Subject: [PATCH] Revert "[QoL] Add Collapse Button to Sidebar History Panel (#6222)" --- gui/src/components/History/index.tsx | 203 ++++++++++++--------------- 1 file changed, 90 insertions(+), 113 deletions(-) diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index c392c050e..1f2e7331a 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -1,6 +1,6 @@ import { SessionMetadata } from "core"; import MiniSearch from "minisearch"; -import { +import React, { Fragment, useContext, useEffect, @@ -10,11 +10,7 @@ import { } from "react"; import Shortcut from "../gui/Shortcut"; -import { - ChevronLeftIcon, - ChevronRightIcon, - XMarkIcon, -} from "@heroicons/react/24/solid"; +import { XMarkIcon } from "@heroicons/react/24/solid"; import { useNavigate } from "react-router-dom"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; @@ -43,11 +39,10 @@ const HEADER_CLASS = export function History() { const dispatch = useAppDispatch(); const navigate = useNavigate(); - const searchInputRef = useRef(null); + const searchInputRef = React.useRef(null); const ideMessenger = useContext(IdeMessengerContext); const [searchTerm, setSearchTerm] = useState(""); - const [collapsed, setCollapsed] = useState(false); const minisearch = useRef( new MiniSearch({ @@ -81,25 +76,30 @@ export function History() { const platform = useMemo(() => getPlatform(), []); const filteredAndSortedSessions: SessionMetadata[] = useMemo(() => { + // 1. Exact phrase matching const exactResults = minisearch.search(searchTerm, { fuzzy: false, }); + // 2. Fuzzy matching with higher tolerance const fuzzyResults = minisearch.search(searchTerm, { fuzzy: 0.3, }); + // 3. Prefix matching for partial words const prefixResults = minisearch.search(searchTerm, { prefix: true, fuzzy: 0.2, }); + // Combine results, with exact matches having higher priority const allResults = [ ...exactResults.map((r) => ({ ...r, priority: 3 })), ...fuzzyResults.map((r) => ({ ...r, priority: 2 })), ...prefixResults.map((r) => ({ ...r, priority: 1 })), ]; + // Remove duplicates while preserving highest priority const uniqueResultsMap = new Map(); allResults.forEach((result) => { const existing = uniqueResultsMap.get(result.id); @@ -107,16 +107,16 @@ export function History() { uniqueResultsMap.set(result.id, result); } }); + const uniqueResults = Array.from(uniqueResultsMap.values()); - const sessionIds = Array.from(uniqueResultsMap.values()) + const sessionIds = uniqueResults .sort((a, b) => b.priority - a.priority || b.score - a.score) .map((result) => result.id); return allSessionMetadata - .filter( - (session) => - searchTerm === "" || sessionIds.includes(session.sessionId), - ) + .filter((session) => { + return searchTerm === "" || sessionIds.includes(session.sessionId); + }) .sort( (a, b) => parseDate(b.dateCreated).getTime() - @@ -136,9 +136,14 @@ export function History() { title={`Clear sessions`} text={`Are you sure you want to permanently delete all chat sessions, including the current chat session?`} onConfirm={async () => { + // optimistic update dispatch(setAllSessionMetadata([])); + + // actual update + refresh await ideMessenger.request("history/clear", undefined); void dispatch(refreshSessionMetadata({})); + + // start a new session dispatch(newSession()); navigate(ROUTES.HOME); }} @@ -151,27 +156,11 @@ export function History() { return (
- {/* Collapse Button */} - - - {/* Search Input */} )}
- - {!collapsed && ( - <> -
- {filteredAndSortedSessions.length === 0 && ( -
- {isSessionMetadataLoading ? ( - "Loading Sessions..." - ) : ( - <> - No past sessions found. To start a new session, either click - the "+" button or use the keyboard shortcut:{" "} - meta L - - )} -
+
+ {filteredAndSortedSessions.length === 0 && ( +
+ {isSessionMetadataLoading ? ( + "Loading Sessions..." + ) : ( + <> + No past sessions found. To start a new session, either click the + "+" button or use the keyboard shortcut:{" "} + meta L + )} - - - - {filteredAndSortedSessions.map((session, index) => { - const prevDate = - index > 0 - ? parseDate( - filteredAndSortedSessions[index - 1].dateCreated, - ) - : earlier; - const date = parseDate(session.dateCreated); - - return ( - - {index === 0 && date > yesterday && ( - - - - )} - {date < yesterday && - date > lastWeek && - prevDate > yesterday && ( - - - - )} - {date < lastWeek && - date > lastMonth && - prevDate > lastWeek && ( - - - - )} - {date < lastMonth && prevDate > lastMonth && ( - - - - )} - - - - ); - })} - -
Today
This Week
This Month
Older
+ )} -
- - {`Data is saved in ${ - platform === "windows" - ? "%USERPROFILE%/.continue" - : "~/.continue/sessions" - }`} - - - Clear session history - -
- - )} + + + {filteredAndSortedSessions.map((session, index) => { + const prevDate = + index > 0 + ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) + : earlier; + const date = parseDate(session.dateCreated); + return ( + + {index === 0 && date > yesterday && ( + + + + )} + {date < yesterday && + date > lastWeek && + prevDate > yesterday && ( +
+
+ + )} + {date < lastWeek && + date > lastMonth && + prevDate > lastWeek && ( +
+
+ + )} + {date < lastMonth && prevDate > lastMonth && ( +
+
+ + )} + + + + ); + })} + +
Today
This WeekThis MonthOlder
+
+
+ {`Data is saved in ${platform === "windows" ? "%USERPROFILE%/.continue" : "~/.continue/sessions"}`} + + Clear session history + +
); }