Fullscreen history sidebar

This commit is contained in:
tomasz-io 2024-10-08 14:39:59 +02:00
parent 71a517be23
commit ef88320ac5
6 changed files with 214 additions and 212 deletions

View file

@ -1,8 +1,4 @@
import {
ArrowLeftIcon,
PencilSquareIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline";
import { SessionInfo } from "core";
import MiniSearch from "minisearch";
import React, { Fragment, useEffect, useState } from "react";
@ -12,16 +8,12 @@ import styled from "styled-components";
import {
defaultBorderRadius,
Input,
lightGray,
vscBackground,
vscBadgeBackground,
vscForeground,
vscInputBackground,
} from "../components";
import ButtonWithTooltip from "../components/ButtonWithTooltip";
} from ".";
import ButtonWithTooltip from "./ButtonWithTooltip";
import useHistory from "../hooks/useHistory";
import { useNavigationListener } from "../hooks/useNavigationListener";
import { getFontSize } from "../util";
const SearchBarContainer = styled.div`
display: flex;
@ -71,7 +63,7 @@ const SectionHeader = styled.tr`
user-select: none;
padding: 4px;
background-color: ${vscInputBackground};
width: 100%;
width: calc(100% - 8px);
font-weight: bold;
text-align: center;
align-items: center;
@ -81,15 +73,6 @@ const SectionHeader = styled.tr`
height: 1.5em;
`;
const TdDiv = styled.div`
cursor: pointer;
flex-grow: 1;
padding-left: 1rem;
padding-right: 1rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
`;
function TableRow({
session,
date,
@ -132,17 +115,18 @@ function TableRow({
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<div className="flex justify-between items-center w-full">
<TdDiv
onClick={async () => {
// Save current session
saveSession();
await loadSession(session.sessionId);
navigate("/");
}}
>
<div className="text-md w-100">
{editing ? (
<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%" }}
@ -152,15 +136,17 @@ function TableRow({
onKeyUp={(e) => handleKeyUp(e)}
onBlur={() => setEditing(false)}
/>
) : (
JSON.stringify(session.title).slice(1, -1)
)}
</div>
</div>
) : (
<span className="truncate max-w-60 block">
{JSON.stringify(session.title).slice(1, -1)}
</span>
)}
<div style={{ color: "#9ca3af" }}>
{lastPartOfPath(session.workspaceDirectory || "")}
<div className="flex" style={{ color: "#9ca3af" }}>
<span>{lastPartOfPath(session.workspaceDirectory || "")}</span>
{!hovered && (
<span className="inline-block float-right">
<span className="inline-block ml-auto">
{date.toLocaleString("en-US", {
year: "2-digit",
month: "2-digit",
@ -172,31 +158,29 @@ function TableRow({
</span>
)}
</div>
</TdDiv>
</div>
{hovered && (
<ButtonWithTooltip
className="mr-2"
text="Edit"
onClick={async () => {
setEditing(true);
}}
>
<PencilSquareIcon width="1.3em" height="1.3em" />
</ButtonWithTooltip>
)}
{hovered && (
<ButtonWithTooltip
className="mr-2"
text="Delete"
onClick={async () => {
deleteSession(session.sessionId);
onDelete(session.sessionId);
}}
>
<TrashIcon width="1.3em" height="1.3em" />
</ButtonWithTooltip>
<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>
@ -208,10 +192,7 @@ function lastPartOfPath(path: string): string {
return path.split(sep).pop() || path;
}
function History() {
useNavigationListener();
const navigate = useNavigate();
export function History() {
const [sessions, setSessions] = useState<SessionInfo[]>([]);
const [filteredAndSortedSessions, setFilteredAndSortedSessions] = useState<
SessionInfo[]
@ -227,9 +208,6 @@ function History() {
const searchInputRef = React.useRef<HTMLInputElement>(null);
const stickyHistoryHeaderRef = React.useRef<HTMLDivElement>(null);
const [headerHeight, setHeaderHeight] = useState(0);
const dispatch = useDispatch();
const { getHistory } = useHistory(dispatch);
@ -297,138 +275,90 @@ function History() {
);
}, [sessions, searchTerm, minisearch]);
useEffect(() => {
setHeaderHeight(stickyHistoryHeaderRef.current?.clientHeight || 100);
}, [stickyHistoryHeaderRef.current]);
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 className="overflow-y-scroll" style={{ fontSize: getFontSize() }}>
<div
ref={stickyHistoryHeaderRef}
className="sticky top-0"
style={{ backgroundColor: vscBackground }}
>
<div
className="items-center flex m-0 p-0"
<div>
<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={{
borderBottom: `0.5px solid ${lightGray}`,
fontSize: "11px",
backgroundColor:
searchTerm !== "" ? vscInputBackground : vscBadgeBackground,
}}
onClick={() => {
if (searchInputRef.current.value === "") {
searchInputRef.current.value = "*";
setSearchTerm("*");
} else {
searchInputRef.current.value = "";
setSearchTerm("");
}
}}
>
<ArrowLeftIcon
width="1.2em"
height="1.2em"
onClick={() => navigate("/")}
className="inline-block ml-4 cursor-pointer"
/>
<h3 className="text-lg font-bold m-2 inline-block">History</h3>
{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>
{/* {workspacePaths && workspacePaths.length > 0 && (
<CheckDiv
checked={filteringByWorkspace}
onClick={() => setFilteringByWorkspace((prev) => !prev)}
title={`Show only sessions from ${lastPartOfPath(
workspacePaths[workspacePaths.length - 1]
)}/`}
/>
)} */}
</div>
)}
<div>
<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 style={{ top: `${headerHeight - 1}px` }}>
Today
</SectionHeader>
)}
{date < yesterday &&
date > lastWeek &&
prevDate > yesterday && (
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
This Week
</SectionHeader>
)}
{date < lastWeek &&
date > lastMonth &&
prevDate > lastWeek && (
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
This Month
</SectionHeader>
)}
{date < lastMonth && prevDate > lastMonth && (
<SectionHeader style={{ top: `${headerHeight - 1}px` }}>
Older
</SectionHeader>
<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>
<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>
);
}
export default History;

View file

@ -24,43 +24,43 @@ import {
lightGray,
vscBackground,
vscForeground,
} from "../components";
import { ChatScrollAnchor } from "../components/ChatScrollAnchor";
import StepContainer from "../components/gui/StepContainer";
import TimelineItem from "../components/gui/TimelineItem";
import ContinueInputBox from "../components/mainInput/ContinueInputBox";
import { defaultInputModifiers } from "../components/mainInput/inputModifiers";
import { TutorialCard } from "../components/mainInput/TutorialCard";
} from "../../components";
import { ChatScrollAnchor } from "../../components/ChatScrollAnchor";
import StepContainer from "../../components/gui/StepContainer";
import TimelineItem from "../../components/gui/TimelineItem";
import ContinueInputBox from "../../components/mainInput/ContinueInputBox";
import { defaultInputModifiers } from "../../components/mainInput/inputModifiers";
import { TutorialCard } from "../../components/mainInput/TutorialCard";
import {
OnboardingCard,
useOnboardingCard,
} from "../components/OnboardingCard";
import { IdeMessengerContext } from "../context/IdeMessenger";
import useChatHandler from "../hooks/useChatHandler";
import useHistory from "../hooks/useHistory";
import { useTutorialCard } from "../hooks/useTutorialCard";
import { useWebviewListener } from "../hooks/useWebviewListener";
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
} from "../../components/OnboardingCard";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import useChatHandler from "../../hooks/useChatHandler";
import useHistory from "../../hooks/useHistory";
import { useTutorialCard } from "../../hooks/useTutorialCard";
import { useWebviewListener } from "../../hooks/useWebviewListener";
import { defaultModelSelector } from "../../redux/selectors/modelSelectors";
import {
clearLastResponse,
deleteMessage,
newSession,
setInactive,
} from "../redux/slices/stateSlice";
} from "../../redux/slices/stateSlice";
import {
setDialogEntryOn,
setDialogMessage,
setShowDialog,
} from "../redux/slices/uiStateSlice";
import { RootState } from "../redux/store";
} from "../../redux/slices/uiStateSlice";
import { RootState } from "../../redux/store";
import {
getFontSize,
getMetaKeyLabel,
isJetBrains,
isMetaEquivalentKeyPressed,
} from "../util";
import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial";
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
} from "../../util";
import { FREE_TRIAL_LIMIT_REQUESTS } from "../../util/freeTrial";
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
const TopGuiDiv = styled.div<{
showScrollbar?: boolean;
@ -144,7 +144,7 @@ function fallbackRender({ error, resetErrorBoundary }: any) {
);
}
function GUI() {
export function Chat() {
const posthog = usePostHog();
const dispatch = useDispatch();
const ideMessenger = useContext(IdeMessengerContext);
@ -528,5 +528,3 @@ function GUI() {
</>
);
}
export default GUI;

View file

@ -0,0 +1,22 @@
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">
<History />
</Aside>
<main className="overflow-y-auto flex-1 flex flex-col">
<Chat />
</main>
</div>
);
}

View file

@ -0,0 +1,37 @@
import { useNavigate } from "react-router-dom";
import { lightGray, vscBackground } from "../../components";
import { useNavigationListener } from "../../hooks/useNavigationListener";
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
export const HistoryHeader = () => {
useNavigationListener();
const navigate = useNavigate();
return (
<div className="sticky top-0" style={{ backgroundColor: vscBackground }}>
<div
className="items-center flex m-0 p-0"
style={{
borderBottom: `0.5px solid ${lightGray}`,
}}
>
<ArrowLeftIcon
width="1.2em"
height="1.2em"
onClick={() => navigate("/")}
className="inline-block ml-4 cursor-pointer"
/>
<h3 className="text-lg font-bold m-2 inline-block">History</h3>
</div>
{/* {workspacePaths && workspacePaths.length > 0 && (
<CheckDiv
checked={filteringByWorkspace}
onClick={() => setFilteringByWorkspace((prev) => !prev)}
title={`Show only sessions from ${lastPartOfPath(
workspacePaths[workspacePaths.length - 1]
)}/`}
/>
)} */}
</div>
);
};

View file

@ -0,0 +1,12 @@
import { History } from "../../components/History";
import { getFontSize } from "../../util";
import { HistoryHeader } from "./HistoryHeader";
export default function HistoryPage() {
return (
<div className="overflow-y-scroll" style={{ fontSize: getFontSize() }}>
<HistoryHeader />
<History />
</div>
);
}

View file

@ -10,12 +10,15 @@ module.exports = {
theme: {
// Note that these breakpoints are primarily optimized for the input toolbar
screens: {
xxs: "170px", // Smallest width for Primary Sidebar in VS Code
"2xs": "170px", // Smallest width for Primary Sidebar in VS Code
xs: "250px", // Avg default sidebar width in VS Code
sm: "330px",
md: "460px",
lg: "590px",
xl: "720px",
"2xl": "860px",
"3xl": "1000px",
"4xl": "1140px",
},
extend: {
animation: {