blob: 0142836f9ac03dcc2fb6a5e7cab006e8d6f92d45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
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";
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">
<h1 className="text-2xl font-bold m-4">History</h1>
<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">{session.date_created}</div>
</TdDiv>
</td>
</Tr>
))}
</tbody>
</table>
</div>
);
}
export default History;
|