Elffuss BraidHub

kikocis/continue public

fd84b2d5fd91 · 2.2 KiBRawPermalink
1import { Tooltip } from "react-tooltip";
2import { useAppDispatch, useAppSelector } from "../../redux/hooks";
3import { saveCurrentSession } from "../../redux/thunks/session";
4
5const ContextStatus = () => {
6 const dispatch = useAppDispatch();
7 const contextPercentage = useAppSelector(
8 (state) => state.session.contextPercentage,
9 );
10 const history = useAppSelector((state) => state.session.history);
11 const percent = Math.round((contextPercentage ?? 0) * 100);
12 const isPruned = useAppSelector((state) => state.session.isPruned);
13 if (!isPruned && percent < 60) {
14 return null;
15 }
16
17 const barColorClass = isPruned
18 ? "bg-error"
19 : percent > 80
20 ? "bg-warning"
21 : "bg-description";
22
23 return (
24 <div>
25 <Tooltip
26 id="context-status"
27 closeEvents={{
28 // blur: false,
29 mouseleave: true,
30 click: true,
31 mouseup: false,
32 }}
33 clickable
34 >
35 <div className="flex flex-col gap-0">
36 <span className="inline-block">
37 {`${percent}% of context filled`}
38 </span>
39 {isPruned && (
40 <span className="inline-block">
41 {`Oldest messages are being removed`}
42 </span>
43 )}
44 {history.length > 0 && (
45 <div>
46 <span className="inline-block">Start a</span>{" "}
47 <span
48 className="inline-block cursor-pointer underline"
49 onClick={() => {
50 dispatch(
51 saveCurrentSession({
52 openNewSession: true,
53 generateTitle: false,
54 }),
55 );
56 }}
57 >
58 New Session
59 </span>
60 </div>
61 )}
62 </div>
63 </Tooltip>
64 <div
65 data-tooltip-id="context-status"
66 className="border-description-muted relative h-[10px] w-[5px] rounded-[1px] border-[0.5px] border-solid"
67 >
68 <div
69 className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`}
70 style={{ height: `${percent}%` }}
71 ></div>
72 </div>
73 </div>
74 );
75};
76
77export default ContextStatus;