summaryrefslogtreecommitdiff
path: root/extension/react-app/src/redux
diff options
context:
space:
mode:
Diffstat (limited to 'extension/react-app/src/redux')
-rw-r--r--extension/react-app/src/redux/hooks.ts21
-rw-r--r--extension/react-app/src/redux/selectors/debugContextSelectors.ts29
-rw-r--r--extension/react-app/src/redux/slices/configSlice.ts4
-rw-r--r--extension/react-app/src/redux/slices/debugContexSlice.ts149
-rw-r--r--extension/react-app/src/redux/slices/serverStateReducer.ts53
-rw-r--r--extension/react-app/src/redux/slices/uiStateSlice.ts26
-rw-r--r--extension/react-app/src/redux/store.ts16
7 files changed, 88 insertions, 210 deletions
diff --git a/extension/react-app/src/redux/hooks.ts b/extension/react-app/src/redux/hooks.ts
deleted file mode 100644
index a6aef869..00000000
--- a/extension/react-app/src/redux/hooks.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { useCallback } from "react";
-import { useDispatch, useSelector } from "react-redux";
-import { RootStore } from "./store";
-import { selectDebugContextValue } from "./selectors/debugContextSelectors";
-import { updateValue } from "./slices/debugContexSlice";
-import { SerializedDebugContext } from "../../../src/client";
-
-export function useDebugContextValue(
- key: keyof SerializedDebugContext,
- defaultValue: any
-): [any, (value: any) => void] {
- const dispatch = useDispatch();
- const state =
- useSelector((state: RootStore) => selectDebugContextValue(state, key)) ||
- defaultValue;
- const boundAction = useCallback(
- (value: any) => dispatch(updateValue({ key, value })),
- [dispatch, key]
- );
- return [state, boundAction];
-}
diff --git a/extension/react-app/src/redux/selectors/debugContextSelectors.ts b/extension/react-app/src/redux/selectors/debugContextSelectors.ts
deleted file mode 100644
index 89201bb7..00000000
--- a/extension/react-app/src/redux/selectors/debugContextSelectors.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { RootStore } from "../store";
-
-const selectDebugContext = (state: RootStore) => {
- return {
- ...state.debugState.debugContext,
- rangesInFiles: state.debugState.debugContext.rangesInFiles.filter(
- (_, index) => state.debugState.rangesMask[index]
- ),
- };
-};
-
-const selectAllRangesInFiles = (state: RootStore) => {
- return state.debugState.debugContext.rangesInFiles;
-};
-
-const selectRangesMask = (state: RootStore) => {
- return state.debugState.rangesMask;
-};
-
-const selectDebugContextValue = (state: RootStore, key: string) => {
- return (state.debugState.debugContext as any)[key];
-};
-
-export {
- selectDebugContext,
- selectDebugContextValue,
- selectAllRangesInFiles,
- selectRangesMask,
-};
diff --git a/extension/react-app/src/redux/slices/configSlice.ts b/extension/react-app/src/redux/slices/configSlice.ts
index 57c4f860..59c76066 100644
--- a/extension/react-app/src/redux/slices/configSlice.ts
+++ b/extension/react-app/src/redux/slices/configSlice.ts
@@ -50,7 +50,7 @@ export const configSlice = createSlice({
) => ({
...state,
dataSwitchOn: action.payload,
- })
+ }),
},
});
@@ -60,6 +60,6 @@ export const {
setWorkspacePath,
setSessionId,
setVscMediaUrl,
- setDataSwitchOn
+ setDataSwitchOn,
} = configSlice.actions;
export default configSlice.reducer;
diff --git a/extension/react-app/src/redux/slices/debugContexSlice.ts b/extension/react-app/src/redux/slices/debugContexSlice.ts
deleted file mode 100644
index 647440d5..00000000
--- a/extension/react-app/src/redux/slices/debugContexSlice.ts
+++ /dev/null
@@ -1,149 +0,0 @@
-import { createSlice } from "@reduxjs/toolkit";
-import { RangeInFile, SerializedDebugContext } from "../../../../src/client";
-import { RootStore } from "../store";
-
-export const debugStateSlice = createSlice({
- name: "debugState",
- initialState: {
- debugContext: {
- rangesInFiles: [],
- filesystem: {},
- traceback: undefined,
- description: undefined,
- },
- rangesMask: [],
- } as RootStore["debugState"],
- reducers: {
- updateValue: (
- state: RootStore["debugState"],
- action: {
- type: string;
- payload: { key: keyof SerializedDebugContext; value: any };
- }
- ) => {
- return {
- ...state,
- debugContext: {
- ...state.debugContext,
- [action.payload.key]: action.payload.value,
- },
- };
- },
- addRangeInFile: (
- state: RootStore["debugState"],
- action: {
- type: string;
- payload: {
- rangeInFile: RangeInFile;
- canUpdateLast: boolean;
- };
- }
- ) => {
- let rangesInFiles = state.debugContext.rangesInFiles;
- // If identical to existing range, don't add. Ideally you check for overlap of ranges.
- for (let range of rangesInFiles) {
- if (
- range.filepath === action.payload.rangeInFile.filepath &&
- range.range.start.line ===
- action.payload.rangeInFile.range.start.line &&
- range.range.end.line === action.payload.rangeInFile.range.end.line
- ) {
- return state;
- }
- }
-
- if (
- action.payload.canUpdateLast &&
- rangesInFiles.length > 0 &&
- rangesInFiles[rangesInFiles.length - 1].filepath ===
- action.payload.rangeInFile.filepath
- ) {
- return {
- ...state,
- debugContext: {
- ...state.debugContext,
- rangesInFiles: [
- ...rangesInFiles.slice(0, rangesInFiles.length - 1),
- action.payload.rangeInFile,
- ],
- },
- };
- } else {
- return {
- ...state,
- debugContext: {
- ...state.debugContext,
- rangesInFiles: [
- ...state.debugContext.rangesInFiles,
- action.payload.rangeInFile,
- ],
- },
- rangesMask: [...state.rangesMask, true],
- };
- }
- },
- deleteRangeInFileAt: (
- state: RootStore["debugState"],
- action: {
- type: string;
- payload: number;
- }
- ) => {
- return {
- ...state,
- debugContext: {
- ...state.debugContext,
- rangesInFiles: state.debugContext.rangesInFiles.filter(
- (_, index) => index !== action.payload
- ),
- },
- rangesMask: state.rangesMask.filter(
- (_, index) => index !== action.payload
- ),
- };
- },
- toggleSelectionAt: (
- state: RootStore["debugState"],
- action: {
- type: string;
- payload: number;
- }
- ) => {
- return {
- ...state,
- rangesMask: state.rangesMask.map((_, index) =>
- index === action.payload
- ? !state.rangesMask[index]
- : state.rangesMask[index]
- ),
- };
- },
- updateFileSystem: (
- state: RootStore["debugState"],
- action: {
- type: string;
- payload: { [filepath: string]: string };
- }
- ) => {
- return {
- ...state,
- debugContext: {
- ...state.debugContext,
- filesystem: {
- ...state.debugContext.filesystem,
- ...action.payload,
- },
- },
- };
- },
- },
-});
-
-export const {
- updateValue,
- updateFileSystem,
- addRangeInFile,
- deleteRangeInFileAt,
- toggleSelectionAt,
-} = debugStateSlice.actions;
-export default debugStateSlice.reducer;
diff --git a/extension/react-app/src/redux/slices/serverStateReducer.ts b/extension/react-app/src/redux/slices/serverStateReducer.ts
new file mode 100644
index 00000000..4d9dc326
--- /dev/null
+++ b/extension/react-app/src/redux/slices/serverStateReducer.ts
@@ -0,0 +1,53 @@
+import { createSlice } from "@reduxjs/toolkit";
+import { FullState } from "../../../../schema/FullState";
+
+const initialState: FullState = {
+ history: {
+ timeline: [
+ {
+ step: {
+ name: "Welcome to Continue",
+ hide: false,
+ description: `- Highlight code section and ask a question or give instructions
+ - Use \`cmd+m\` (Mac) / \`ctrl+m\` (Windows) to open Continue
+ - Use \`/help\` to ask questions about how to use Continue`,
+ system_message: null,
+ chat_context: [],
+ manage_own_chat_context: false,
+ message: "",
+ },
+ depth: 0,
+ deleted: false,
+ active: false,
+ },
+ ],
+ current_index: 3,
+ } as any,
+ user_input_queue: [],
+ active: false,
+ slash_commands: [],
+ adding_highlighted_code: false,
+ selected_context_items: [],
+};
+
+export const serverStateSlice = createSlice({
+ name: "serverState",
+ initialState,
+ reducers: {
+ setServerState: (state, action) => {
+ return {
+ ...action.payload,
+ selected_context_items: action.payload.selected_context_items || [],
+ user_input_queue: action.payload.user_input_queue || [],
+ slash_commands: action.payload.slash_commands || [],
+ };
+ },
+ temporarilySetUserInputQueue: (state, action) => {
+ state.user_input_queue = action.payload;
+ },
+ },
+});
+
+export const { setServerState, temporarilySetUserInputQueue } =
+ serverStateSlice.actions;
+export default serverStateSlice.reducer;
diff --git a/extension/react-app/src/redux/slices/uiStateSlice.ts b/extension/react-app/src/redux/slices/uiStateSlice.ts
index 837d19e9..d34596c9 100644
--- a/extension/react-app/src/redux/slices/uiStateSlice.ts
+++ b/extension/react-app/src/redux/slices/uiStateSlice.ts
@@ -5,6 +5,10 @@ export const uiStateSlice = createSlice({
initialState: {
bottomMessage: undefined,
bottomMessageCloseTimeout: undefined,
+ showDialog: false,
+ dialogMessage: "",
+ dialogEntryOn: false,
+ displayBottomMessageOnBottom: true,
},
reducers: {
setBottomMessage: (state, action) => {
@@ -16,9 +20,27 @@ export const uiStateSlice = createSlice({
}
state.bottomMessageCloseTimeout = action.payload;
},
+ setDialogMessage: (state, action) => {
+ state.dialogMessage = action.payload;
+ },
+ setDialogEntryOn: (state, action) => {
+ state.dialogEntryOn = action.payload;
+ },
+ setShowDialog: (state, action) => {
+ state.showDialog = action.payload;
+ },
+ setDisplayBottomMessageOnBottom: (state, action) => {
+ state.displayBottomMessageOnBottom = action.payload;
+ },
},
});
-export const { setBottomMessage, setBottomMessageCloseTimeout } =
- uiStateSlice.actions;
+export const {
+ setBottomMessage,
+ setBottomMessageCloseTimeout,
+ setDialogMessage,
+ setDialogEntryOn,
+ setShowDialog,
+ setDisplayBottomMessageOnBottom,
+} = uiStateSlice.actions;
export default uiStateSlice.reducer;
diff --git a/extension/react-app/src/redux/store.ts b/extension/react-app/src/redux/store.ts
index d49513e5..59339060 100644
--- a/extension/react-app/src/redux/store.ts
+++ b/extension/react-app/src/redux/store.ts
@@ -1,10 +1,11 @@
import { configureStore } from "@reduxjs/toolkit";
-import debugStateReducer from "./slices/debugContexSlice";
import chatReducer from "./slices/chatSlice";
import configReducer from "./slices/configSlice";
import miscReducer from "./slices/miscSlice";
import uiStateReducer from "./slices/uiStateSlice";
-import { RangeInFile, SerializedDebugContext } from "../../../src/client";
+import { RangeInFile } from "../../../src/client";
+import { FullState } from "../../../schema/FullState";
+import serverStateReducer from "./slices/serverStateReducer";
export interface ChatMessage {
role: "system" | "user" | "assistant";
@@ -12,10 +13,6 @@ export interface ChatMessage {
}
export interface RootStore {
- debugState: {
- debugContext: SerializedDebugContext;
- rangesMask: boolean[];
- };
config: {
workspacePath: string | undefined;
apiUrl: string;
@@ -35,16 +32,21 @@ export interface RootStore {
uiState: {
bottomMessage: JSX.Element | undefined;
bottomMessageCloseTimeout: NodeJS.Timeout | undefined;
+ displayBottomMessageOnBottom: boolean;
+ showDialog: boolean;
+ dialogMessage: string | JSX.Element;
+ dialogEntryOn: boolean;
};
+ serverState: FullState;
}
const store = configureStore({
reducer: {
- debugState: debugStateReducer,
chat: chatReducer,
config: configReducer,
misc: miscReducer,
uiState: uiStateReducer,
+ serverState: serverStateReducer,
},
});