|
|
@@ -1,7 +1,5 @@
|
|
|
import React, { createContext, useCallback, useContext, useEffect, useState } from "react"
|
|
|
import { useEvent } from "react-use"
|
|
|
-import { merge } from "lodash"
|
|
|
-
|
|
|
import { ApiConfigMeta, ExtensionMessage, ExtensionState } from "../../../src/shared/ExtensionMessage"
|
|
|
import { ApiConfiguration } from "../../../src/shared/api"
|
|
|
import { vscode } from "../utils/vscode"
|
|
|
@@ -71,6 +69,32 @@ export interface ExtensionStateContextType extends ExtensionState {
|
|
|
|
|
|
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
|
|
|
|
|
|
+export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState) => {
|
|
|
+ const {
|
|
|
+ apiConfiguration: prevApiConfiguration,
|
|
|
+ customModePrompts: prevCustomModePrompts,
|
|
|
+ customSupportPrompts: prevCustomSupportPrompts,
|
|
|
+ experiments: prevExperiments,
|
|
|
+ ...prevRest
|
|
|
+ } = prevState
|
|
|
+
|
|
|
+ const {
|
|
|
+ apiConfiguration: newApiConfiguration,
|
|
|
+ customModePrompts: newCustomModePrompts,
|
|
|
+ customSupportPrompts: newCustomSupportPrompts,
|
|
|
+ experiments: newExperiments,
|
|
|
+ ...newRest
|
|
|
+ } = newState
|
|
|
+
|
|
|
+ const apiConfiguration = { ...prevApiConfiguration, ...newApiConfiguration }
|
|
|
+ const customModePrompts = { ...prevCustomModePrompts, ...newCustomModePrompts }
|
|
|
+ const customSupportPrompts = { ...prevCustomSupportPrompts, ...newCustomSupportPrompts }
|
|
|
+ const experiments = { ...prevExperiments, ...newExperiments }
|
|
|
+ const rest = { ...prevRest, ...newRest }
|
|
|
+
|
|
|
+ return { ...rest, apiConfiguration, customModePrompts, customSupportPrompts, experiments }
|
|
|
+}
|
|
|
+
|
|
|
export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
|
const [state, setState] = useState<ExtensionState>({
|
|
|
version: "",
|
|
|
@@ -253,6 +277,3 @@ export const useExtensionState = () => {
|
|
|
}
|
|
|
return context
|
|
|
}
|
|
|
-
|
|
|
-export const mergeExtensionState = (prevState: ExtensionState, newState: ExtensionState): ExtensionState =>
|
|
|
- merge({}, prevState, newState)
|