Fix voice dictation provider selection bug (#3862)
This commit is contained in:
@@ -97,6 +97,23 @@ export default function DictationSection() {
|
|||||||
checkOpenAIKey();
|
checkOpenAIKey();
|
||||||
}, [getProviders]);
|
}, [getProviders]);
|
||||||
|
|
||||||
|
const handleDropdownToggle = async () => {
|
||||||
|
const newShowState = !showProviderDropdown;
|
||||||
|
setShowProviderDropdown(newShowState);
|
||||||
|
|
||||||
|
if (newShowState) {
|
||||||
|
try {
|
||||||
|
const providers = await getProviders(true);
|
||||||
|
const openAIProvider = providers.find((p) => p.name === 'openai');
|
||||||
|
const isConfigured = !!openAIProvider?.is_configured;
|
||||||
|
setHasOpenAIKey(isConfigured);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking OpenAI configuration:', error);
|
||||||
|
setHasOpenAIKey(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const saveSettings = (newSettings: DictationSettings) => {
|
const saveSettings = (newSettings: DictationSettings) => {
|
||||||
setSettings(newSettings);
|
setSettings(newSettings);
|
||||||
localStorage.setItem(DICTATION_SETTINGS_KEY, JSON.stringify(newSettings));
|
localStorage.setItem(DICTATION_SETTINGS_KEY, JSON.stringify(newSettings));
|
||||||
@@ -171,7 +188,7 @@ export default function DictationSection() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowProviderDropdown(!showProviderDropdown)}
|
onClick={handleDropdownToggle}
|
||||||
className="flex items-center gap-2 px-3 py-1.5 text-sm border border-borderSubtle rounded-md hover:border-borderStandard transition-colors text-textStandard bg-background-default"
|
className="flex items-center gap-2 px-3 py-1.5 text-sm border border-borderSubtle rounded-md hover:border-borderStandard transition-colors text-textStandard bg-background-default"
|
||||||
>
|
>
|
||||||
{getProviderLabel(settings.provider)}
|
{getProviderLabel(settings.provider)}
|
||||||
@@ -182,12 +199,7 @@ export default function DictationSection() {
|
|||||||
<div className="absolute right-0 mt-1 w-48 bg-background-default border border-borderStandard rounded-md shadow-lg z-10">
|
<div className="absolute right-0 mt-1 w-48 bg-background-default border border-borderStandard rounded-md shadow-lg z-10">
|
||||||
<button
|
<button
|
||||||
onClick={() => handleProviderChange('openai')}
|
onClick={() => handleProviderChange('openai')}
|
||||||
disabled={!hasOpenAIKey}
|
className="w-full px-3 py-2 text-left text-sm transition-colors first:rounded-t-md hover:bg-bgSubtle text-textStandard"
|
||||||
className={`w-full px-3 py-2 text-left text-sm transition-colors first:rounded-t-md ${
|
|
||||||
hasOpenAIKey
|
|
||||||
? 'hover:bg-bgSubtle text-textStandard'
|
|
||||||
: 'text-textSubtle cursor-not-allowed'
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
OpenAI Whisper
|
OpenAI Whisper
|
||||||
{!hasOpenAIKey && <span className="text-xs ml-1">(not configured)</span>}
|
{!hasOpenAIKey && <span className="text-xs ml-1">(not configured)</span>}
|
||||||
|
|||||||
Reference in New Issue
Block a user