Skip to content

Commit b23411a

Browse files
committed
Fix remaining console errors and warnings
- Added default props to VoiceInput component to prevent setIsListening errors - Added type checking for setIsListening function calls - Fixed React keys warning in DocumentGenerator template mapping - Added better error handling for voice input functionality - Restarted dev server to clear hot reload cache issues - All console errors and warnings should now be resolved
1 parent fd21076 commit b23411a

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

frontend/src/components/DocumentGenerator.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,15 @@ In production, this would be a real PDF document.`;
613613
label="Select Template"
614614
onChange={(e) => handleTemplateSelect(e.target.value)}
615615
>
616-
{templates.map((template) => (
617-
<MenuItem key={template.id} value={template.id}>
618-
{template.name}
619-
</MenuItem>
620-
))}
616+
{templates.map((template) => {
617+
const templateId = typeof template === 'string' ? template : template.id;
618+
const templateName = templateMetadata[templateId]?.name || templateId;
619+
return (
620+
<MenuItem key={templateId} value={templateId}>
621+
{templateName}
622+
</MenuItem>
623+
);
624+
})}
621625
</Select>
622626
</FormControl>
623627

frontend/src/components/VoiceInput.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Mic as MicIcon, MicOff as MicOffIcon } from '@mui/icons-material';
1010
import { useTranslation } from 'react-i18next';
1111

12-
const VoiceInput = ({ onTranscript, isListening, setIsListening }) => {
12+
const VoiceInput = ({ onTranscript, isListening = false, setIsListening = () => {} }) => {
1313
const { t } = useTranslation();
1414
const [error, setError] = useState(null);
1515
const [recognition, setRecognition] = useState(null);
@@ -33,11 +33,15 @@ const VoiceInput = ({ onTranscript, isListening, setIsListening }) => {
3333

3434
recognitionInstance.onerror = (event) => {
3535
setError(event.error);
36-
setIsListening(false);
36+
if (typeof setIsListening === 'function') {
37+
setIsListening(false);
38+
}
3739
};
3840

3941
recognitionInstance.onend = () => {
40-
setIsListening(false);
42+
if (typeof setIsListening === 'function') {
43+
setIsListening(false);
44+
}
4145
};
4246

4347
setRecognition(recognitionInstance);
@@ -56,12 +60,19 @@ const VoiceInput = ({ onTranscript, isListening, setIsListening }) => {
5660
return;
5761
}
5862

59-
if (isListening) {
60-
recognition.stop();
61-
} else {
62-
setError(null);
63-
recognition.start();
64-
setIsListening(true);
63+
try {
64+
if (isListening) {
65+
recognition.stop();
66+
} else {
67+
setError(null);
68+
recognition.start();
69+
if (typeof setIsListening === 'function') {
70+
setIsListening(true);
71+
}
72+
}
73+
} catch (err) {
74+
console.error('Error toggling voice input:', err);
75+
setError('voice_input_error');
6576
}
6677
};
6778

0 commit comments

Comments
 (0)