-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Scheffler
committed
Mar 18, 2023
1 parent
7ed6071
commit f8a12b4
Showing
11 changed files
with
249 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createContext, useContext, useEffect, useState, ReactNode } from 'react'; | ||
|
||
interface Config { | ||
openaiApiKey: string; | ||
openaiModel: string; | ||
} | ||
|
||
const ConfigContext = createContext<Config>({ | ||
openaiApiKey: '', | ||
openaiModel: '', | ||
}); | ||
|
||
export const ConfigProvider = ({ children }: { children: ReactNode }) => { | ||
const [config, setConfig] = useState<Config>({ | ||
openaiApiKey: '', | ||
openaiModel: '', | ||
}); | ||
|
||
useEffect(() => { | ||
const script = document.getElementById('config'); | ||
|
||
if (script && script.textContent) { | ||
try { | ||
const configData = JSON.parse(script.textContent); | ||
setConfig(configData); | ||
} catch (error) { | ||
console.error('Failed to parse config', error); | ||
} | ||
} | ||
}, []); | ||
|
||
return ( | ||
<ConfigContext.Provider value={config}> | ||
{children} | ||
</ConfigContext.Provider> | ||
); | ||
}; | ||
|
||
export const useConfig = () => useContext(ConfigContext); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.