From e8db9309d2f035519f836dd8aeb374c0f5ebed9b Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 17 Oct 2024 20:49:44 +0700 Subject: [PATCH] improv: history ui --- extensions/vscode/package.json | 11 --- extensions/vscode/src/commands.ts | 34 +-------- gui/src/components/History/index.tsx | 108 +++++++++------------------ gui/src/pages/gui/index.tsx | 12 +-- 4 files changed, 43 insertions(+), 122 deletions(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index bd74f59fc..e25c050b3 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -189,12 +189,6 @@ "icon": "$(fullscreen)", "group": "Continue" }, - { - "command": "continue.toggleNewWindow", - "category": "Continue", - "title": "Open New Window", - "icon": "$(link-external)" - }, { "command": "continue.openConfigJson", "category": "Continue", @@ -458,11 +452,6 @@ "command": "continue.toggleFullScreen", "group": "navigation@3", "when": "view == continue.continueGUIView" - }, - { - "command": "continue.toggleNewWindow", - "group": "navigation@4", - "when": "view == continue.continueGUIView" } ], "editor/title": [ diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 36245b6ab..babc695e3 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -483,21 +483,12 @@ const commandsMap: ( "continue.applyCodeFromChat": () => { sidebar.webviewProtocol.request("applyCodeFromChat", undefined); }, - "continue.toggleFullScreen": ({ - newWindow, - }: { newWindow?: boolean } = {}) => { + "continue.toggleFullScreen": () => { focusGUI(); // Check if full screen is already open by checking open tabs const fullScreenTab = getFullScreenTab(); - // Check if the active editor is the Continue GUI View - if (fullScreenTab && fullScreenTab.isActive) { - //Full screen open and focused - close it - vscode.commands.executeCommand("workbench.action.closeActiveEditor"); //this will trigger the onDidDispose listener below - return; - } - if (fullScreenTab && fullScreenPanel) { //Full screen open, but not focused - focus it fullScreenPanel.reveal(); @@ -537,17 +528,7 @@ const commandsMap: ( extensionContext.subscriptions, ); - if (newWindow) { - vscode.commands.executeCommand( - "workbench.action.copyEditorToNewWindow", - ); - } - }, - "continue.toggleNewWindow": () => { - focusGUI(); - vscode.commands.executeCommand("continue.toggleFullScreen", { - newWindow: true, - }); + vscode.commands.executeCommand("workbench.action.copyEditorToNewWindow"); }, "continue.openConfigJson": () => { ide.openFile(getConfigJsonPath()); @@ -651,8 +632,8 @@ const commandsMap: ( currentStatus === StatusBarStatus.Paused ? StatusBarStatus.Enabled : currentStatus === StatusBarStatus.Disabled - ? StatusBarStatus.Paused - : StatusBarStatus.Disabled; + ? StatusBarStatus.Paused + : StatusBarStatus.Disabled; } else { // Toggle between Disabled and Enabled targetStatus = @@ -670,9 +651,6 @@ const commandsMap: ( { label: "$(screen-full) Open full screen chat (Cmd+K Cmd+M)", }, - { - label: "$(link-external) Open chat in a new window", - }, { label: quickPickStatusText(targetStatus), }, @@ -724,10 +702,6 @@ const commandsMap: ( "$(screen-full) Open full screen chat (Cmd+K Cmd+M)" ) { vscode.commands.executeCommand("continue.toggleFullScreen"); - } else if ( - selectedOption === "$(link-external) Open chat in a new window" - ) { - vscode.commands.executeCommand("continue.toggleNewWindow"); } else if (selectedOption === "$(question) Open help center") { focusGUI(); vscode.commands.executeCommand("continue.navigateTo", "/more"); diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index 26da632e5..7ed525626 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -1,19 +1,12 @@ import { SessionInfo } from "core"; import MiniSearch from "minisearch"; -import React, { Fragment, useEffect, useState } from "react"; +import React, { Fragment, useEffect, useMemo, useState } from "react"; import { useDispatch } from "react-redux"; -import { - vscBadgeBackground, - vscButtonBackground, - vscButtonForeground, - vscEditorBackground, - vscForeground, - vscInputBackground, - vscInputBorder, -} from ".."; + import useHistory from "../../hooks/useHistory"; import { getFontSize } from "../../util"; import { HistoryTableRow } from "./HistoryTableRow"; +import { XMarkIcon } from "@heroicons/react/24/solid"; const parseDate = (date: string): Date => { let dateObj = new Date(date); @@ -28,11 +21,6 @@ const HEADER_CLASS = export function History() { const [sessions, setSessions] = useState([]); - const [filteredAndSortedSessions, setFilteredAndSortedSessions] = useState< - SessionInfo[] - >([]); - const apiUrl = window.serverUrl; - const workspacePaths = window.workspacePaths || []; const deleteSessionInUI = async (sessionId: string) => { setSessions((prev) => @@ -45,15 +33,14 @@ export function History() { const dispatch = useDispatch(); const { getHistory, lastSessionId } = useHistory(dispatch); - const [minisearch, setMinisearch] = useState< - MiniSearch<{ title: string; sessionId: string }> - >( - new MiniSearch({ + const [searchTerm, setSearchTerm] = useState(""); + + const minisearch = useMemo(() => { + return new MiniSearch({ fields: ["title"], storeFields: ["title", "sessionId", "id"], - }), - ); - const [searchTerm, setSearchTerm] = useState(""); + }); + }, []); useEffect(() => { const fetchSessions = async () => { @@ -70,43 +57,22 @@ export function History() { fetchSessions(); }, [lastSessionId]); - useEffect(() => { - // When searchTerm is empty only show sessions from the current workspace - let filteringByWorkspace = searchTerm === ""; - - // When the searchTerm is wildcard (asterisk) then show ALL sessions, otherwise use minisearch to search for user input + const filteredAndSortedSessions: SessionInfo[] = useMemo(() => { const sessionIds = minisearch - .search(searchTerm === "*" ? "" : searchTerm, { + .search(searchTerm, { fuzzy: 0.1, }) .map((result) => result.id); - setFilteredAndSortedSessions( - sessions - .filter((session) => { - if ( - !filteringByWorkspace || - typeof workspacePaths === "undefined" || - typeof session.workspaceDirectory === "undefined" - ) { - return true; - } - return workspacePaths.includes(session.workspaceDirectory); - }) - // Filter by search term - .filter((session) => { - return ( - searchTerm === "*" || - filteringByWorkspace || - sessionIds.includes(session.sessionId) - ); - }) - .sort( - (a, b) => - parseDate(b.dateCreated).getTime() - - parseDate(a.dateCreated).getTime(), - ), - ); + return sessions + .filter((session) => { + return searchTerm === "" || sessionIds.includes(session.sessionId); + }) + .sort( + (a, b) => + parseDate(b.dateCreated).getTime() - + parseDate(a.dateCreated).getTime(), + ); }, [sessions, searchTerm, minisearch]); const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); @@ -116,38 +82,36 @@ export function History() { return (
-
+
setSearchTerm(e.target.value)} /> - { - if (searchInputRef.current.value === "") { - searchInputRef.current.value = "*"; - setSearchTerm("*"); - } else { - searchInputRef.current.value = ""; + {searchTerm && ( + { setSearchTerm(""); - } - }} - > - {searchTerm === "" ? "Show All" : "Clear"} - + if (searchInputRef.current) { + searchInputRef.current.focus(); + } + }} + /> + )}
{filteredAndSortedSessions.length === 0 && ( -
+
No past sessions found. To start a new session, either click the "+" button or use the keyboard shortcut: Option + Command + N
)} - +
{filteredAndSortedSessions.map((session, index) => { const prevDate = @@ -184,7 +148,7 @@ export function History() {

- + All session data is saved in ~/.continue/sessions
diff --git a/gui/src/pages/gui/index.tsx b/gui/src/pages/gui/index.tsx index 53e184027..2f37027ee 100644 --- a/gui/src/pages/gui/index.tsx +++ b/gui/src/pages/gui/index.tsx @@ -1,20 +1,14 @@ import { Chat } from "./Chat"; import { History } from "../../components/History"; -import styled from "styled-components"; -import { vscSidebarBorder } from "../../components"; - -export const Aside = styled.aside` - border-right: 1px solid ${vscSidebarBorder}; -`; export default function GUI() { return (
- -
+