diff options
author | Nate Sesti <33237525+sestinj@users.noreply.github.com> | 2023-08-06 22:54:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-06 22:54:51 -0700 |
commit | 74005855304412f0401e29c83c166e99a8ab0944 (patch) | |
tree | 4e8ddb61fd52068e839ca4ccab268e013405d545 /extension/react-app/src/pages/history.tsx | |
parent | a0d3f29ee237484c66b0efe243c79d902f2da993 (diff) | |
parent | 8ada89b0f66f9e746394ee64591359537fe0c7f0 (diff) | |
download | sncontinue-74005855304412f0401e29c83c166e99a8ab0944.tar.gz sncontinue-74005855304412f0401e29c83c166e99a8ab0944.tar.bz2 sncontinue-74005855304412f0401e29c83c166e99a8ab0944.zip |
Merge pull request #351 from continuedev/history
Session History
Diffstat (limited to 'extension/react-app/src/pages/history.tsx')
-rw-r--r-- | extension/react-app/src/pages/history.tsx | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/extension/react-app/src/pages/history.tsx b/extension/react-app/src/pages/history.tsx new file mode 100644 index 00000000..c3240a66 --- /dev/null +++ b/extension/react-app/src/pages/history.tsx @@ -0,0 +1,98 @@ +import React, { useContext, useEffect, useState } from "react"; +import { SessionInfo } from "../../../schema/SessionInfo"; +import { GUIClientContext } from "../App"; +import { useSelector } from "react-redux"; +import { RootStore } from "../redux/store"; +import { useNavigate } from "react-router-dom"; +import { secondaryDark, vscBackground } from "../components"; +import styled from "styled-components"; +import { ArrowLeftIcon } from "@heroicons/react/24/outline"; + +const Tr = styled.tr` + &:hover { + background-color: ${secondaryDark}; + } +`; + +const TdDiv = styled.div` + cursor: pointer; + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + border-bottom: 1px solid ${secondaryDark}; +`; + +function History() { + const navigate = useNavigate(); + const [sessions, setSessions] = useState<SessionInfo[]>([]); + const client = useContext(GUIClientContext); + const apiUrl = useSelector((state: RootStore) => state.config.apiUrl); + + useEffect(() => { + const fetchSessions = async () => { + console.log("fetching sessions from: ", apiUrl); + if (!apiUrl) { + return; + } + const response = await fetch(`${apiUrl}/sessions/list`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const json = await response.json(); + console.log(json); + setSessions(json); + }; + fetchSessions(); + }, [client]); + + return ( + <div className="w-full"> + <div className="items-center flex"> + <ArrowLeftIcon + width="1.4em" + height="1.4em" + onClick={() => navigate("/")} + className="inline-block ml-4 cursor-pointer" + /> + <h1 className="text-2xl font-bold m-4 inline-block">History</h1> + </div> + <table className="w-full"> + <tbody> + {sessions.map((session, index) => ( + <Tr key={index}> + <td> + <TdDiv + onClick={() => { + client?.loadSession(session.session_id); + navigate("/"); + }} + > + <div className="text-lg">{session.title}</div> + <div className="text-gray-400"> + {new Date( + parseInt(session.date_created) * 1000 + ).toLocaleString("en-US", { + weekday: "short", + year: "numeric", + month: "long", + day: "numeric", + hour: "numeric", + minute: "numeric", + })} + </div> + </TdDiv> + </td> + </Tr> + ))} + </tbody> + </table> + <br /> + <i className="text-sm ml-4"> + All session data is saved in ~/.continue/sessions + </i> + </div> + ); +} + +export default History; |