Elffuss BraidHub

kikocis/continue public

95c91a48de4e · 1.8 KiBRawPermalink
1import { useContext } from "react";
2import { IdeMessengerContext } from "../../context/IdeMessenger";
3import { useAppDispatch, useAppSelector } from "../../redux/hooks";
4import { exitEditMode } from "../../redux/thunks/editMode";
5import AcceptRejectDiffButtons from "../AcceptRejectDiffButtons";
6import { useMainEditor } from "./TipTapEditor";
7
8const EditModeDetails = () => {
9 const isStreaming = useAppSelector((store) => store.session.isStreaming);
10 const mode = useAppSelector((store) => store.session.mode);
11 const dispatch = useAppDispatch();
12 const editApplyState = useAppSelector(
13 (store) => store.editModeState.applyState,
14 );
15 const { mainEditor } = useMainEditor();
16 const ideMessenger = useContext(IdeMessengerContext);
17
18 if (mode !== "edit") {
19 return null;
20 }
21 if (isStreaming) {
22 return null;
23 }
24 if (editApplyState.status === "done") {
25 const plural = editApplyState.numDiffs === 1 ? "" : "s";
26 return (
27 <>
28 <div className="flex flex-col items-center justify-center pb-1 pt-3 text-xs italic text-gray-400">
29 <span className="">{`${editApplyState.numDiffs} diff${plural} remaining`}</span>
30 </div>
31 <AcceptRejectDiffButtons
32 applyStates={[editApplyState]}
33 onAcceptOrReject={async (outcome) => {
34 if (outcome === "acceptDiff") {
35 await dispatch(exitEditMode({}));
36 ideMessenger.post("focusEditor", undefined);
37 } else {
38 mainEditor?.commands.focus();
39 }
40 }}
41 />
42 </>
43 );
44 }
45
46 // Will only still show if not all accepted
47 if (editApplyState.status === "closed") {
48 return (
49 <div>
50 <span></span>
51 </div>
52 );
53 }
54
55 // Not started/streaming
56 return null;
57};
58
59export default EditModeDetails;