-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to regenerate the answer after switching model (#98)
- Loading branch information
Showing
9 changed files
with
75 additions
and
82 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
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,28 @@ | ||
import { useEffect, useState } from 'react' | ||
import { defaultConfig, getUserConfig } from '../config/index.mjs' | ||
import Browser from 'webextension-polyfill' | ||
|
||
export function useConfig(initFn) { | ||
const [config, setConfig] = useState(defaultConfig) | ||
useEffect(() => { | ||
getUserConfig().then((config) => { | ||
setConfig(config) | ||
if (initFn) initFn() | ||
}) | ||
}, []) | ||
useEffect(() => { | ||
const listener = (changes) => { | ||
const changedItems = Object.keys(changes) | ||
let newConfig = {} | ||
for (const key of changedItems) { | ||
newConfig[key] = changes[key].newValue | ||
} | ||
setConfig({ ...config, ...newConfig }) | ||
} | ||
Browser.storage.local.onChanged.addListener(listener) | ||
return () => { | ||
Browser.storage.local.onChanged.removeListener(listener) | ||
} | ||
}, [config]) | ||
return config | ||
} |
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