Skip to content

Commit

Permalink
Merge branch 'priyashpatil-add-history-tittle-change' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Jun 11, 2024
2 parents 5935206 + c08b302 commit 683c122
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
1 change: 0 additions & 1 deletion core/util/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class HistoryManager {
if (sessionInfo.sessionId === session.sessionId) {
sessionInfo.title = session.title;
sessionInfo.workspaceDirectory = session.workspaceDirectory;
sessionInfo.dateCreated = String(Date.now());
found = true;
break;
}
Expand Down
17 changes: 10 additions & 7 deletions gui/src/hooks/useHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ function useHistory(dispatch: Dispatch) {
dispatch(newSession());
await new Promise((resolve) => setTimeout(resolve, 10));

let title = truncateText(
stripImages(stateCopy.history[0].message.content)
.split("\n")
.filter((l) => l.trim() !== "")
.slice(-1)[0] || "",
50,
);
let title =
stateCopy.title === "New Session"
? truncateText(
stripImages(stateCopy.history[0].message.content)
.split("\n")
.filter((l) => l.trim() !== "")
.slice(-1)[0] || "",
50,
)
: (await getSession(stateCopy.sessionId)).title; // to ensure titles are synced with updates from history page.

if (
false && // Causing maxTokens to be set to 20 for main requests sometimes, so disabling until resolved
Expand Down
63 changes: 56 additions & 7 deletions gui/src/pages/history.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ArrowLeftIcon, TrashIcon } from "@heroicons/react/24/outline";
import {
ArrowLeftIcon,
PencilSquareIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
import { SessionInfo } from "core";
import MiniSearch from "minisearch";
import React, { Fragment, useEffect, useState } from "react";
Expand All @@ -7,6 +11,7 @@ import { useNavigate } from "react-router-dom";
import styled from "styled-components";
import {
defaultBorderRadius,
Input,
lightGray,
vscBackground,
vscBadgeBackground,
Expand Down Expand Up @@ -91,8 +96,28 @@ function TableRow({
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 } = useHistory(dispatch);
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
Expand All @@ -104,15 +129,27 @@ function TableRow({
onClick={async () => {
// Save current session
saveSession();

await loadSession(session.sessionId);
navigate("/");
}}
>
<div className="text-md">
{JSON.stringify(session.title).slice(1, -1)}
<div className="text-md w-100">
{editing ? (
<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)}
/>
) : (
JSON.stringify(session.title).slice(1, -1)
)}
</div>
<div className="text-gray-400">

<div style={{ color: "#9ca3af" }}>
{date.toLocaleString("en-US", {
year: "2-digit",
month: "2-digit",
Expand All @@ -122,10 +159,22 @@ function TableRow({
hour12: true,
})}
{" | "}
{lastPartOfPath(session.workspaceDirectory || "")}/
{lastPartOfPath(session.workspaceDirectory || "")}
</div>
</TdDiv>

{hovered && (
<HeaderButtonWithText
className="mr-2"
text="Edit"
onClick={async () => {
setEditing(true);
}}
>
<PencilSquareIcon width="1.3em" height="1.3em" />
</HeaderButtonWithText>
)}

{hovered && (
<HeaderButtonWithText
className="mr-2"
Expand Down

0 comments on commit 683c122

Please sign in to comment.