Elffuss BraidHub

kikocis/continue public

ef0e06d64dae · 2.0 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 = percent > 80 ? "bg-warning" : "bg-description";
18
19 return (
20 <div>
21 <Tooltip
22 id="context-status"
23 closeEvents={{
24 // blur: false,
25 mouseleave: true,
26 click: true,
27 mouseup: false,
28 }}
29 clickable
30 >
31 <div className="flex flex-col gap-0">
32 <span> {`${percent}% of context filled`}</span>
33 {isPruned && <span>Old messages are being removed</span>}
34 {history.length > 0 && (
35 <span
36 className="cursor-pointer underline"
37 onClick={() => {
38 dispatch(
39 saveCurrentSession({
40 openNewSession: true,
41 generateTitle: false,
42 }),
43 );
44 }}
45 >
46 New Session
47 </span>
48 )}
49 </div>
50 </Tooltip>
51 <div
52 data-tooltip-id="context-status"
53 className="border-description-muted relative h-[10px] w-[5px] rounded-[1px] border-[0.5px] border-solid"
54 >
55 {/* <div className="absolute bottom-full left-1/4 h-[1px] w-1/2 border-[0.5px] border-solid" /> */}
56 <div
57 className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`}
58 style={{ height: `${percent}%` }}
59 ></div>
60 </div>
61 </div>
62 );
63};
64
65export default ContextStatus;