feat: add accept/reject all btns

This commit is contained in:
Test 2024-11-10 00:25:44 -08:00
parent 6e5236a58a
commit 011e2c2644
9 changed files with 98 additions and 16 deletions

View file

@ -62,6 +62,7 @@ export interface ApplyState {
streamId: string;
status?: "streaming" | "done" | "closed";
numDiffs?: number;
filepath?: string;
}
export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {

View file

@ -0,0 +1,61 @@
import { useContext } from "react";
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "../../redux/store";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { updateApplyState } from "../../redux/slices/uiStateSlice";
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
export default function AcceptRejectAllButtons() {
const dispatch = useDispatch();
const ideMessenger = useContext(IdeMessengerContext);
const applyStates = useSelector(
(state: RootState) => state.uiState.applyStates,
);
const pendingApplyStates = applyStates.filter(
(state) => state.status === "done",
);
const handleAcceptAll = async () => {
for (const applyState of pendingApplyStates) {
ideMessenger.post("acceptDiff", { filepath: applyState.filepath });
dispatch(
updateApplyState({
streamId: applyState.streamId,
status: "closed",
}),
);
}
};
const handleRejectAll = async () => {
for (const applyState of pendingApplyStates) {
ideMessenger.post("rejectDiff", { filepath: applyState.filepath });
dispatch(
updateApplyState({
streamId: applyState.streamId,
status: "closed",
}),
);
}
};
return (
<div className="flex justify-center gap-2 border-b border-gray-200/25 p-1 px-3">
<button
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
onClick={handleAcceptAll}
>
<CheckIcon className="mr-1 h-4 w-4" />
Accept all changes
</button>
<button
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
onClick={handleRejectAll}
>
<XMarkIcon className="mr-1 h-4 w-4" />
Reject all changes
</button>
</div>
);
}

View file

@ -10,6 +10,7 @@ import { newSession, setMessageAtIndex } from "../../redux/slices/stateSlice";
import { RootState } from "../../redux/store";
import ContextItemsPeek from "./ContextItemsPeek";
import TipTapEditor from "./TipTapEditor";
import AcceptRejectAllButtons from "./AcceptRejectAllButtons";
interface ContinueInputBoxProps {
isLastUserInput: boolean;
@ -76,6 +77,27 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
const [isGatheringContext, setIsGatheringContext] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
const applyStates = useSelector(
(state: RootState) => state.uiState.applyStates,
);
const isInMultifileEdit = useSelector(
(state: RootState) => state.state.isInMultifileEdit,
);
const isApplying =
applyStates.length > 0 &&
applyStates.some((state) => state.status === "streaming");
const shouldShowAcceptRejectButtons =
props.isMainInput && isInMultifileEdit && !active && !isApplying;
console.log(
`isMainInput: ${props.isMainInput} isInMultifileEdit: ${isInMultifileEdit} isApplying:${isApplying} active: ${active}`,
);
console.log(applyStates);
useWebviewListener(
"newSessionWithPrompt",
async (data) => {
@ -110,6 +132,8 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
return (
<div className={`mb-1 ${props.hidden ? "hidden" : ""}`}>
{shouldShowAcceptRejectButtons && <AcceptRejectAllButtons />}
<div className={`relative flex px-2`}>
<GradientBorder
loading={active && props.isLastUserInput ? 1 : 0}

View file

@ -55,7 +55,7 @@ export default function StepContainerPreToolbar(
const streamIdRef = useRef<string | null>(null);
const wasGeneratingRef = useRef(props.isGeneratingCodeBlock);
const isMultifileEdit = useSelector(
(state: RootState) => state.uiState.isInMultifileEdit,
(state: RootState) => state.state.isInMultifileEdit,
);
const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true);
const [codeBlockContent, setCodeBlockContent] = useState("");

View file

@ -26,6 +26,7 @@ export function useApplyCodeBlock({
dispatch(
updateApplyState({
streamId,
filepath,
status: "streaming",
}),
);

View file

@ -30,13 +30,11 @@ import {
resubmitAtIndex,
setInactive,
setIsGatheringContext,
setIsInMultifileEdit,
setMessageAtIndex,
streamUpdate,
} from "../redux/slices/stateSlice";
import {
resetNextCodeBlockToApplyIndex,
setIsInMultifileEdit,
} from "../redux/slices/uiStateSlice";
import { resetNextCodeBlockToApplyIndex } from "../redux/slices/uiStateSlice";
import { RootState } from "../redux/store";
import useHistory from "./useHistory";

View file

@ -10,7 +10,6 @@ import { newSession } from "../redux/slices/stateSlice";
import { RootState } from "../redux/store";
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
import { useLastSessionContext } from "../context/LastSessionContext";
import { setIsInMultifileEdit } from "../redux/slices/uiStateSlice";
const MAX_TITLE_LENGTH = 100;
@ -100,8 +99,6 @@ function useHistory(dispatch: Dispatch) {
workspaceDirectory: window.workspacePaths?.[0] || "",
};
dispatch(setIsInMultifileEdit(false));
return await ideMessenger.request("history/save", sessionInfo);
}

View file

@ -1,7 +1,6 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { JSONContent } from "@tiptap/react";
import {
ChatHistory,
ChatHistoryItem,
ChatMessage,
ContextItemId,
@ -46,6 +45,7 @@ type State = {
mainEditorContent?: JSONContent;
selectedProfileId: string;
configError: ConfigValidationError[] | undefined;
isInMultifileEdit: boolean;
};
const initialState: State = {
@ -81,6 +81,7 @@ const initialState: State = {
sessionId: v4(),
defaultModelTitle: "GPT-4",
selectedProfileId: "local",
isInMultifileEdit: false,
};
export const stateSlice = createSlice({
@ -301,6 +302,7 @@ export const stateSlice = createSlice({
state.active = false;
state.title = "New Session";
state.sessionId = v4();
state.isInMultifileEdit = false;
}
},
deleteContextWithIds: (
@ -442,6 +444,9 @@ export const stateSlice = createSlice({
selectedProfileId: payload,
};
},
setIsInMultifileEdit: (state, action: PayloadAction<boolean>) => {
state.isInMultifileEdit = action.payload;
},
},
});
@ -470,6 +475,7 @@ export const {
setSelectedProfileId,
deleteMessage,
setIsGatheringContext,
setIsInMultifileEdit,
} = stateSlice.actions;
export default stateSlice.reducer;

View file

@ -16,8 +16,6 @@ type UiState = {
* Syncs the sidebar with the accepted/rejected blocks in the editor. Reused for Edit as well.
*/
applyStates: ApplyState[];
isInMultifileEdit: boolean;
};
export const uiStateSlice = createSlice({
@ -29,7 +27,6 @@ export const uiStateSlice = createSlice({
nextCodeBlockToApplyIndex: 0,
onboardingCard: defaultOnboardingCardState,
applyStates: [],
isInMultifileEdit: false,
} as UiState,
reducers: {
setOnboardingCard: (
@ -77,11 +74,9 @@ export const uiStateSlice = createSlice({
} else {
curApplyState.status = payload.status ?? curApplyState.status;
curApplyState.numDiffs = payload.numDiffs ?? curApplyState.numDiffs;
curApplyState.filepath = payload.filepath ?? curApplyState.filepath;
}
},
setIsInMultifileEdit: (state, action: PayloadAction<boolean>) => {
state.isInMultifileEdit = action.payload;
},
},
});
@ -93,7 +88,6 @@ export const {
resetNextCodeBlockToApplyIndex,
incrementNextCodeBlockToApplyIndex,
updateApplyState,
setIsInMultifileEdit,
} = uiStateSlice.actions;
export default uiStateSlice.reducer;