From 011e2c264407ff72a0bc90980ec7d8250da4bbd6 Mon Sep 17 00:00:00 2001 From: Test Date: Sun, 10 Nov 2024 00:25:44 -0800 Subject: [PATCH] feat: add accept/reject all btns --- core/protocol/ideWebview.ts | 1 + .../mainInput/AcceptRejectAllButtons.tsx | 61 +++++++++++++++++++ .../components/mainInput/ContinueInputBox.tsx | 24 ++++++++ .../StepContainerPreToolbar.tsx | 2 +- .../markdown/utils/useApplyCodeBlock.ts | 1 + gui/src/hooks/useChatHandler.ts | 6 +- gui/src/hooks/useHistory.tsx | 3 - gui/src/redux/slices/stateSlice.ts | 8 ++- gui/src/redux/slices/uiStateSlice.ts | 8 +-- 9 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 gui/src/components/mainInput/AcceptRejectAllButtons.tsx diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index bfeba537f..eb992bb8e 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -62,6 +62,7 @@ export interface ApplyState { streamId: string; status?: "streaming" | "done" | "closed"; numDiffs?: number; + filepath?: string; } export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { diff --git a/gui/src/components/mainInput/AcceptRejectAllButtons.tsx b/gui/src/components/mainInput/AcceptRejectAllButtons.tsx new file mode 100644 index 000000000..bcb778cf1 --- /dev/null +++ b/gui/src/components/mainInput/AcceptRejectAllButtons.tsx @@ -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 ( +
+ + +
+ ); +} diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index 4a9ea0dfd..57b1f3c80 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -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(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 (
+ {shouldShowAcceptRejectButtons && } +
(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(""); diff --git a/gui/src/components/markdown/utils/useApplyCodeBlock.ts b/gui/src/components/markdown/utils/useApplyCodeBlock.ts index 9cbe2309a..cb016e1d8 100644 --- a/gui/src/components/markdown/utils/useApplyCodeBlock.ts +++ b/gui/src/components/markdown/utils/useApplyCodeBlock.ts @@ -26,6 +26,7 @@ export function useApplyCodeBlock({ dispatch( updateApplyState({ streamId, + filepath, status: "streaming", }), ); diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index db41686a2..0c9eb056e 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -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"; diff --git a/gui/src/hooks/useHistory.tsx b/gui/src/hooks/useHistory.tsx index 725e59726..8ebcd4581 100644 --- a/gui/src/hooks/useHistory.tsx +++ b/gui/src/hooks/useHistory.tsx @@ -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); } diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index c22d4bb1b..d7ccf422d 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -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) => { + state.isInMultifileEdit = action.payload; + }, }, }); @@ -470,6 +475,7 @@ export const { setSelectedProfileId, deleteMessage, setIsGatheringContext, + setIsInMultifileEdit, } = stateSlice.actions; export default stateSlice.reducer; diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index aaf225980..34fd29eb4 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -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) => { - state.isInMultifileEdit = action.payload; - }, }, }); @@ -93,7 +88,6 @@ export const { resetNextCodeBlockToApplyIndex, incrementNextCodeBlockToApplyIndex, updateApplyState, - setIsInMultifileEdit, } = uiStateSlice.actions; export default uiStateSlice.reducer;