Merge pull request #2542 from continuedev/tomasz/better-history-ui
Better history UI
This commit is contained in:
commit
d213b395c9
8 changed files with 312 additions and 417 deletions
|
|
@ -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": [
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -1,365 +0,0 @@
|
|||
import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { 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 {
|
||||
defaultBorderRadius,
|
||||
Input,
|
||||
vscBadgeBackground,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
} from ".";
|
||||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
import useHistory from "../hooks/useHistory";
|
||||
import { getFontSize } from "../util";
|
||||
|
||||
const SearchBarContainer = styled.div`
|
||||
display: flex;
|
||||
max-width: 500px;
|
||||
padding: 0 8px 0 8px;
|
||||
margin: 0 auto;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
`;
|
||||
|
||||
const SearchBar = styled.input`
|
||||
padding: 4px 8px;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
border: 0.5px solid #888;
|
||||
outline: none;
|
||||
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};
|
||||
}
|
||||
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
border-bottom: 1px solid ${vscInputBackground};
|
||||
border-top: 1px solid ${vscInputBackground};
|
||||
`;
|
||||
|
||||
const parseDate = (date: string): Date => {
|
||||
let dateObj = new Date(date);
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
dateObj = new Date(parseInt(date));
|
||||
}
|
||||
return dateObj;
|
||||
};
|
||||
|
||||
const SectionHeader = styled.tr`
|
||||
display: flex;
|
||||
user-select: none;
|
||||
padding: 4px;
|
||||
background-color: ${vscInputBackground};
|
||||
width: calc(100% - 8px);
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
position: sticky;
|
||||
height: 1.5em;
|
||||
`;
|
||||
|
||||
function TableRow({
|
||||
session,
|
||||
date,
|
||||
onDelete,
|
||||
}: {
|
||||
session: SessionInfo;
|
||||
date: Date;
|
||||
onDelete: (sessionId: string) => void;
|
||||
}) {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const apiUrl = window.serverUrl;
|
||||
const workspacePaths = window.workspacePaths || [""];
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [sessionTitleEditValue, setSessionTitleEditValue] = useState(
|
||||
session.title,
|
||||
);
|
||||
|
||||
const { saveSession, deleteSession, loadSession, getSession, updateSession } =
|
||||
useHistory(dispatch);
|
||||
|
||||
const handleKeyUp = async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Enter") {
|
||||
if (sessionTitleEditValue !== session.title) {
|
||||
session.title = sessionTitleEditValue;
|
||||
const persistedSessionInfo = await getSession(session.sessionId);
|
||||
persistedSessionInfo.title = sessionTitleEditValue;
|
||||
await updateSession(persistedSessionInfo);
|
||||
setEditing(false);
|
||||
}
|
||||
} else if (e.key === "Escape") {
|
||||
setEditing(false);
|
||||
setSessionTitleEditValue(session.title);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<td
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
>
|
||||
<div
|
||||
className="flex max-w-full box-border px-4 py-2"
|
||||
onClick={async () => {
|
||||
// Save current session
|
||||
saveSession();
|
||||
await loadSession(session.sessionId);
|
||||
navigate("/");
|
||||
}}
|
||||
>
|
||||
<div className="cursor-pointer flex-1">
|
||||
{editing ? (
|
||||
<div className="text-md">
|
||||
<Input
|
||||
type="text"
|
||||
style={{ width: "100%" }}
|
||||
ref={(titleInput) => titleInput && titleInput.focus()}
|
||||
value={sessionTitleEditValue}
|
||||
onChange={(e) => setSessionTitleEditValue(e.target.value)}
|
||||
onKeyUp={(e) => handleKeyUp(e)}
|
||||
onBlur={() => setEditing(false)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<span className="truncate max-w-60 block">
|
||||
{JSON.stringify(session.title).slice(1, -1)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="flex" style={{ color: "#9ca3af" }}>
|
||||
<span>{lastPartOfPath(session.workspaceDirectory || "")}</span>
|
||||
{!hovered && (
|
||||
<span className="inline-block ml-auto">
|
||||
{date.toLocaleString("en-US", {
|
||||
year: "2-digit",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
hour12: true,
|
||||
})}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{hovered && (
|
||||
<div className="ml-auto pl-2 gap-x-2 flex">
|
||||
<ButtonWithTooltip
|
||||
text="Edit"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
setEditing(true);
|
||||
}}
|
||||
>
|
||||
<PencilSquareIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
<ButtonWithTooltip
|
||||
text="Delete"
|
||||
onClick={async () => {
|
||||
deleteSession(session.sessionId);
|
||||
onDelete(session.sessionId);
|
||||
}}
|
||||
>
|
||||
<TrashIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
function lastPartOfPath(path: string): string {
|
||||
const sep = path.includes("/") ? "/" : "\\";
|
||||
return path.split(sep).pop() || path;
|
||||
}
|
||||
|
||||
export function History() {
|
||||
const [sessions, setSessions] = useState<SessionInfo[]>([]);
|
||||
const [filteredAndSortedSessions, setFilteredAndSortedSessions] = useState<
|
||||
SessionInfo[]
|
||||
>([]);
|
||||
const apiUrl = window.serverUrl;
|
||||
const workspacePaths = window.workspacePaths || [];
|
||||
|
||||
const deleteSessionInUI = async (sessionId: string) => {
|
||||
setSessions((prev) =>
|
||||
prev.filter((session) => session.sessionId !== sessionId),
|
||||
);
|
||||
};
|
||||
|
||||
const searchInputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { getHistory, lastSessionId } = 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();
|
||||
}, [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 sessionIds = minisearch
|
||||
.search(searchTerm === "*" ? "" : 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(),
|
||||
),
|
||||
);
|
||||
}, [sessions, searchTerm, minisearch]);
|
||||
|
||||
const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24);
|
||||
const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7);
|
||||
const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
|
||||
const earlier = new Date(0);
|
||||
|
||||
return (
|
||||
<div style={{ fontSize: getFontSize() }}>
|
||||
<SearchBarContainer className="space-x-2">
|
||||
<SearchBar
|
||||
className="flex-1 w-full"
|
||||
ref={searchInputRef}
|
||||
placeholder="Search past sessions"
|
||||
type="text"
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
<span
|
||||
className="block text-center px-2 py-1.5 rounded-md w-12 mx-1 my-2 select-none cursor-pointer"
|
||||
style={{
|
||||
fontSize: "11px",
|
||||
backgroundColor:
|
||||
searchTerm !== "" ? vscInputBackground : vscBadgeBackground,
|
||||
}}
|
||||
onClick={() => {
|
||||
if (searchInputRef.current.value === "") {
|
||||
searchInputRef.current.value = "*";
|
||||
setSearchTerm("*");
|
||||
} else {
|
||||
searchInputRef.current.value = "";
|
||||
setSearchTerm("");
|
||||
}
|
||||
}}
|
||||
>
|
||||
{searchTerm === "" ? "Show All" : "Clear"}
|
||||
</span>
|
||||
</SearchBarContainer>
|
||||
|
||||
{filteredAndSortedSessions.length === 0 && (
|
||||
<div className="text-center m-4">
|
||||
No past sessions found. To start a new session, either click the "+"
|
||||
button or use the keyboard shortcut: <b>Option + Command + N</b>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<table className="w-full border-spacing-0 border-collapse">
|
||||
<tbody>
|
||||
{filteredAndSortedSessions.map((session, index) => {
|
||||
const prevDate =
|
||||
index > 0
|
||||
? parseDate(filteredAndSortedSessions[index - 1].dateCreated)
|
||||
: earlier;
|
||||
const date = parseDate(session.dateCreated);
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
{index === 0 && date > yesterday && (
|
||||
<SectionHeader>Today</SectionHeader>
|
||||
)}
|
||||
{date < yesterday &&
|
||||
date > lastWeek &&
|
||||
prevDate > yesterday && (
|
||||
<SectionHeader>This Week</SectionHeader>
|
||||
)}
|
||||
{date < lastWeek && date > lastMonth && prevDate > lastWeek && (
|
||||
<SectionHeader>This Month</SectionHeader>
|
||||
)}
|
||||
{date < lastMonth && prevDate > lastMonth && (
|
||||
<SectionHeader>Older</SectionHeader>
|
||||
)}
|
||||
|
||||
<Tr key={index}>
|
||||
<TableRow
|
||||
session={session}
|
||||
date={date}
|
||||
onDelete={() => deleteSessionInUI(session.sessionId)}
|
||||
></TableRow>
|
||||
</Tr>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<i className="text-sm ml-4">
|
||||
All session data is saved in ~/.continue/sessions
|
||||
</i>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
128
gui/src/components/History/HistoryTableRow.tsx
Normal file
128
gui/src/components/History/HistoryTableRow.tsx
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { SessionInfo } from "core";
|
||||
import React, { useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Input } from "..";
|
||||
import useHistory from "../../hooks/useHistory";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
|
||||
function lastPartOfPath(path: string): string {
|
||||
const sep = path.includes("/") ? "/" : "\\";
|
||||
return path.split(sep).pop() || path;
|
||||
}
|
||||
|
||||
export function HistoryTableRow({
|
||||
session,
|
||||
date,
|
||||
onDelete,
|
||||
}: {
|
||||
session: SessionInfo;
|
||||
date: Date;
|
||||
onDelete: (sessionId: string) => void;
|
||||
}) {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [sessionTitleEditValue, setSessionTitleEditValue] = useState(
|
||||
session.title,
|
||||
);
|
||||
|
||||
const { saveSession, deleteSession, loadSession, getSession, updateSession } =
|
||||
useHistory(dispatch);
|
||||
|
||||
const handleKeyUp = async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Enter") {
|
||||
if (sessionTitleEditValue !== session.title) {
|
||||
session.title = sessionTitleEditValue;
|
||||
const persistedSessionInfo = await getSession(session.sessionId);
|
||||
persistedSessionInfo.title = sessionTitleEditValue;
|
||||
await updateSession(persistedSessionInfo);
|
||||
}
|
||||
setEditing(false);
|
||||
} else if (e.key === "Escape") {
|
||||
setEditing(false);
|
||||
setSessionTitleEditValue(session.title);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td
|
||||
className="p-1"
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
>
|
||||
<div
|
||||
className="hover:bg-vsc-editor-background relative box-border flex max-w-full overflow-hidden rounded-lg p-3"
|
||||
onClick={async () => {
|
||||
// Save current session
|
||||
saveSession();
|
||||
await loadSession(session.sessionId);
|
||||
navigate("/");
|
||||
}}
|
||||
>
|
||||
<div className="flex-1 cursor-pointer space-y-1">
|
||||
{editing ? (
|
||||
<div className="text-md">
|
||||
<Input
|
||||
type="text"
|
||||
className="w-full"
|
||||
ref={(titleInput) => titleInput && titleInput.focus()}
|
||||
value={sessionTitleEditValue}
|
||||
onChange={(e) => setSessionTitleEditValue(e.target.value)}
|
||||
onKeyUp={(e) => handleKeyUp(e)}
|
||||
onBlur={() => setEditing(false)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-md block max-w-80 truncate text-base font-semibold">
|
||||
{JSON.stringify(session.title).slice(1, -1)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="flex" style={{ color: "#9ca3af" }}>
|
||||
<span>{lastPartOfPath(session.workspaceDirectory || "")}</span>
|
||||
{/* Uncomment to show the date */}
|
||||
{/* <span className="inline-block ml-auto">
|
||||
{date.toLocaleString("en-US", {
|
||||
year: "2-digit",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
hour12: true,
|
||||
})}
|
||||
</span> */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{hovered && !editing && (
|
||||
<div className="bg-vsc-background absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-2 rounded-full py-1.5 pl-4 pr-4 shadow-md">
|
||||
<ButtonWithTooltip
|
||||
text="Edit"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
setEditing(true);
|
||||
}}
|
||||
>
|
||||
<PencilSquareIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
<ButtonWithTooltip
|
||||
text="Delete"
|
||||
onClick={async () => {
|
||||
deleteSession(session.sessionId);
|
||||
onDelete(session.sessionId);
|
||||
}}
|
||||
>
|
||||
<TrashIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
156
gui/src/components/History/index.tsx
Normal file
156
gui/src/components/History/index.tsx
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
import { SessionInfo } from "core";
|
||||
import MiniSearch from "minisearch";
|
||||
import React, { Fragment, useEffect, useMemo, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
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);
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
dateObj = new Date(parseInt(date));
|
||||
}
|
||||
return dateObj;
|
||||
};
|
||||
|
||||
const HEADER_CLASS =
|
||||
"flex user-select-none pt-2 pb-3 opacity-75 text-center font-bold items-center justify-center sticky h-6";
|
||||
|
||||
export function History() {
|
||||
const [sessions, setSessions] = useState<SessionInfo[]>([]);
|
||||
|
||||
const deleteSessionInUI = async (sessionId: string) => {
|
||||
setSessions((prev) =>
|
||||
prev.filter((session) => session.sessionId !== sessionId),
|
||||
);
|
||||
};
|
||||
|
||||
const searchInputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { getHistory, lastSessionId } = useHistory(dispatch);
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
|
||||
const minisearch = useMemo(() => {
|
||||
return new MiniSearch({
|
||||
fields: ["title"],
|
||||
storeFields: ["title", "sessionId", "id"],
|
||||
});
|
||||
}, []);
|
||||
|
||||
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();
|
||||
}, [lastSessionId]);
|
||||
|
||||
const filteredAndSortedSessions: SessionInfo[] = useMemo(() => {
|
||||
const sessionIds = minisearch
|
||||
.search(searchTerm, {
|
||||
fuzzy: 0.1,
|
||||
})
|
||||
.map((result) => result.id);
|
||||
|
||||
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);
|
||||
const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7);
|
||||
const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
|
||||
const earlier = new Date(0);
|
||||
|
||||
return (
|
||||
<div style={{ fontSize: getFontSize() }}>
|
||||
<div className="relative mx-auto mb-2 mt-3 flex items-stretch justify-center space-x-2 px-2">
|
||||
<input
|
||||
className="bg-vsc-input-background text-vsc-foreground w-full flex-1 rounded-md border border-none py-1 pl-2 pr-8 text-base outline-none focus:outline-none"
|
||||
ref={searchInputRef}
|
||||
placeholder="Search past sessions"
|
||||
type="text"
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
{searchTerm && (
|
||||
<XMarkIcon
|
||||
className="text-vsc-foreground hover:bg-vsc-background duration-50 absolute right-3 top-1/2 h-5 w-5 -translate-y-1/2 transform cursor-pointer rounded-full p-0.5 transition-colors"
|
||||
onClick={() => {
|
||||
setSearchTerm("");
|
||||
if (searchInputRef.current) {
|
||||
searchInputRef.current.focus();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{filteredAndSortedSessions.length === 0 && (
|
||||
<div className="m-4 text-center">
|
||||
No past sessions found. To start a new session, either click the "+"
|
||||
button or use the keyboard shortcut: <b>Option + Command + N</b>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<table className="w-full border-collapse border-spacing-0">
|
||||
<tbody>
|
||||
{filteredAndSortedSessions.map((session, index) => {
|
||||
const prevDate =
|
||||
index > 0
|
||||
? parseDate(filteredAndSortedSessions[index - 1].dateCreated)
|
||||
: earlier;
|
||||
const date = parseDate(session.dateCreated);
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
{index === 0 && date > yesterday && (
|
||||
<tr className={HEADER_CLASS}>Today</tr>
|
||||
)}
|
||||
{date < yesterday &&
|
||||
date > lastWeek &&
|
||||
prevDate > yesterday && (
|
||||
<tr className={HEADER_CLASS}>This Week</tr>
|
||||
)}
|
||||
{date < lastWeek && date > lastMonth && prevDate > lastWeek && (
|
||||
<tr className={HEADER_CLASS}>This Month</tr>
|
||||
)}
|
||||
{date < lastMonth && prevDate > lastMonth && (
|
||||
<tr className={HEADER_CLASS}>Older</tr>
|
||||
)}
|
||||
|
||||
<HistoryTableRow
|
||||
key={session.sessionId}
|
||||
session={session}
|
||||
date={date}
|
||||
onDelete={() => deleteSessionInUI(session.sessionId)}
|
||||
/>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<i className="ml-4 text-sm">
|
||||
All session data is saved in ~/.continue/sessions
|
||||
</i>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<div className="flex overflow-scroll">
|
||||
<Aside className="overflow-y-auto w-96 hidden 4xl:block">
|
||||
<aside className="4xl:block border-vsc-input-border hidden w-96 overflow-y-auto border-0 border-r border-solid">
|
||||
<History />
|
||||
</Aside>
|
||||
</aside>
|
||||
|
||||
<main className="overflow-y-auto flex-1 flex flex-col">
|
||||
<main className="flex flex-1 flex-col overflow-y-auto">
|
||||
<Chat />
|
||||
</main>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { lightGray, vscBackground } from "../../components";
|
||||
import { useNavigationListener } from "../../hooks/useNavigationListener";
|
||||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { getFontSize } from "../../util";
|
||||
|
||||
export const HistoryHeader = () => {
|
||||
|
|
@ -10,7 +10,7 @@ export const HistoryHeader = () => {
|
|||
|
||||
return (
|
||||
<div
|
||||
className="sticky top-0"
|
||||
className="sticky top-0 z-10"
|
||||
style={{ backgroundColor: vscBackground, fontSize: getFontSize() }}
|
||||
>
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -27,6 +27,25 @@ module.exports = {
|
|||
colors: {
|
||||
"vsc-background": "rgb(var(--vsc-background) / <alpha-value>)",
|
||||
"secondary-dark": "rgb(var(--secondary-dark) / <alpha-value>)",
|
||||
"vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))",
|
||||
"vsc-quick-input-background":
|
||||
"var(--vscode-quickInput-background, var(--vscode-input-background, rgb(45 45 45)))",
|
||||
"vsc-background": "var(--vscode-sideBar-background, rgb(30 30 30))",
|
||||
"vsc-foreground": "var(--vscode-editor-foreground, #fff)",
|
||||
"vsc-button-background": "var(--vscode-button-background, #1bbe84)",
|
||||
"vsc-button-foreground": "var(--vscode-button-foreground, #ffffff)",
|
||||
"vsc-editor-background":
|
||||
"var(--vscode-editor-background, var(--vscode-sideBar-background, rgb(30 30 30)))",
|
||||
"vsc-list-active-background":
|
||||
"var(--vscode-list-activeSelectionBackground, #1bbe84)",
|
||||
"vsc-focus-border": "var(--vscode-focus-border, #1bbe84)",
|
||||
"vsc-list-active-foreground":
|
||||
"var(--vscode-quickInputList-focusForeground, var(--vscode-editor-foreground))",
|
||||
"vsc-input-border": "var(--vscode-input-border, #999998)",
|
||||
"vsc-input-border-focus": "var(--vscode-focusBorder, #999998)",
|
||||
"vsc-badge-background": "var(--vscode-badge-background, #1bbe84)",
|
||||
"vsc-badge-foreground": "var(--vscode-badge-foreground, #fff)",
|
||||
"vsc-sidebar-border": "var(--vscode-sideBar-border, transparent)",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue