From f14d2e7b2f955f5995cd85d55e3e28ee897f943e Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 19 Feb 2024 17:42:55 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20search=20bar=20for=20history=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/media/welcome.md | 6 +-- gui/src/pages/history.tsx | 61 +++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/extensions/vscode/media/welcome.md b/extensions/vscode/media/welcome.md index a9e7e381c..618c175ae 100644 --- a/extensions/vscode/media/welcome.md +++ b/extensions/vscode/media/welcome.md @@ -8,10 +8,10 @@ Continue is currently in the left sidebar, but we recommend moving it to the rig ## 🔑 Most important shortcuts -Cmd/Ctrl + M = Select code +Cmd/Ctrl + L = Select code -Cmd/Ctrl + Shift + M = Select code for follow-up +Cmd/Ctrl + Shift + L = Select code for follow-up -Cmd/Ctrl + Shift + L = Quick edit +Cmd/Ctrl + I = Quick edit Cmd/Ctrl + Shift + R = Automatically debug terminal diff --git a/gui/src/pages/history.tsx b/gui/src/pages/history.tsx index 585499fae..b276f1ce9 100644 --- a/gui/src/pages/history.tsx +++ b/gui/src/pages/history.tsx @@ -1,16 +1,41 @@ import { ArrowLeftIcon, TrashIcon } from "@heroicons/react/24/outline"; import { PersistedSessionInfo, SessionInfo } from "core"; +import MiniSearch from "minisearch"; import React, { Fragment, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; import { useNavigate } from "react-router-dom"; import styled from "styled-components"; -import { lightGray, vscBackground, vscInputBackground } from "../components"; +import { + defaultBorderRadius, + lightGray, + vscBackground, + vscBadgeBackground, + vscForeground, + vscInputBackground, +} from "../components"; import HeaderButtonWithText from "../components/HeaderButtonWithText"; import useHistory from "../hooks/useHistory"; import { useNavigationListener } from "../hooks/useNavigationListener"; import { newSession } from "../redux/slices/stateSlice"; import { getFontSize } from "../util"; +const SearchBar = styled.input` + padding: 4px 8px; + border-radius: ${defaultBorderRadius}; + border: 0.5px solid #888; + outline: none; + width: 90vw; + max-width: 500px; + margin: 8px auto; + display: block; + background-color: ${vscInputBackground}; + color: ${vscForeground}; + &:focus { + border: 0.5px solid ${vscBadgeBackground}; + outline: none; + } +`; + const Tr = styled.tr` &:hover { background-color: ${vscInputBackground}; @@ -149,15 +174,38 @@ function History() { const dispatch = useDispatch(); const { getHistory } = useHistory(dispatch); + const [minisearch, setMinisearch] = useState< + MiniSearch<{ title: string; sessionId: string }> + >( + new MiniSearch({ + fields: ["title"], + storeFields: ["title", "sessionId", "id"], + }) + ); + const [searchTerm, setSearchTerm] = useState(""); + useEffect(() => { const fetchSessions = async () => { const sessions = await getHistory(); setSessions(sessions); + minisearch.addAll( + sessions.map((session) => ({ + title: session.title, + sessionId: session.sessionId, + id: session.sessionId, + })) + ); }; fetchSessions(); }, []); useEffect(() => { + const sessionIds = minisearch + .search(searchTerm, { + fuzzy: 0.1, + }) + .map((result) => result.id); + setFilteredAndSortedSessions( sessions .filter((session) => { @@ -170,13 +218,17 @@ function History() { } return workspacePaths.includes(session.workspaceDirectory); }) + // Filter by search term + .filter((session) => { + return searchTerm === "" || sessionIds.includes(session.sessionId); + }) .sort( (a, b) => parseDate(b.dateCreated).getTime() - parseDate(a.dateCreated).getTime() ) ); - }, [filteringByWorkspace, sessions]); + }, [filteringByWorkspace, sessions, searchTerm, minisearch]); useEffect(() => { setHeaderHeight(stickyHistoryHeaderRef.current?.clientHeight || 100); @@ -236,6 +288,11 @@ function History() { )}
+ setSearchTerm(e.target.value)} + /> {filteredAndSortedSessions.map((session, index) => {