Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(hooks): address real react-hooks rule violations (#628)

Gabriel Stein8be2e1e53717
diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsx
index 7f1012240..d7a3f3924 100644
--- a/src/components/ControlPanel.tsx
+++ b/src/components/ControlPanel.tsx
@@ -103,8 +103,20 @@ export default function ControlPanel() {
} = useDialogs();
useEffect(() => {
- loadTranscriptions();
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
+ (async () => {
+ try {
+ setIsLoading(true);
+ await initializeTranscriptions();
+ } catch {
+ showAlertDialog({
+ title: t("controlPanel.history.couldNotLoadTitle"),
+ description: t("controlPanel.history.couldNotLoadDescription"),
+ });
+ } finally {
+ setIsLoading(false);
+ }
+ })();
+ }, [showAlertDialog, t]);
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
@@ -283,20 +295,6 @@ export default function ControlPanel() {
window.electronAPI?.restoreFromMeetingMode?.();
}, []);
- const loadTranscriptions = async () => {
- try {
- setIsLoading(true);
- await initializeTranscriptions();
- } catch (error) {
- showAlertDialog({
- title: t("controlPanel.history.couldNotLoadTitle"),
- description: t("controlPanel.history.couldNotLoadDescription"),
- });
- } finally {
- setIsLoading(false);
- }
- };
-
const copyToClipboard = useCallback(
async (text: string) => {
try {
diff --git a/src/components/notes/ActionManagerDialog.tsx b/src/components/notes/ActionManagerDialog.tsx
index 5f1fc98cd..08f46f24c 100644
--- a/src/components/notes/ActionManagerDialog.tsx
+++ b/src/components/notes/ActionManagerDialog.tsx
@@ -25,6 +25,13 @@ export default function ActionManagerDialog({ open, onOpenChange }: ActionManage
const [isCreating, setIsCreating] = useState(false);
const nameInputRef = useRef<HTMLInputElement>(null);
+ const resetForm = () => {
+ setName("");
+ setDescription("");
+ setPrompt("");
+ setEditingId(null);
+ };
+
useEffect(() => {
if (open) {
initializeActions();
@@ -47,13 +54,6 @@ export default function ActionManagerDialog({ open, onOpenChange }: ActionManage
}
}, [open, actions, selectedId, isCreating]);
- const resetForm = () => {
- setName("");
- setDescription("");
- setPrompt("");
- setEditingId(null);
- };
-
const handleSelectAction = (action: ActionItem) => {
setSelectedId(action.id);
setEditingId(action.id);
diff --git a/src/components/notes/PersonalNotesView.tsx b/src/components/notes/PersonalNotesView.tsx
index 3aa1bbf9b..f8e1db851 100644
--- a/src/components/notes/PersonalNotesView.tsx
+++ b/src/components/notes/PersonalNotesView.tsx
@@ -96,10 +96,17 @@ export default function PersonalNotesView({
const saveTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const enhancedSaveTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const activeNoteRef = useRef<number | null>(null);
+ const [syncedNoteId, setSyncedNoteIdState] = useState<number | null>(null);
const localContentRef = useRef(localContent);
- localContentRef.current = localContent;
const localTitleRef = useRef(localTitle);
- localTitleRef.current = localTitle;
+ useEffect(() => {
+ localContentRef.current = localContent;
+ localTitleRef.current = localTitle;
+ }, [localContent, localTitle]);
+ const markNoteAsSynced = (id: number | null) => {
+ activeNoteRef.current = id;
+ setSyncedNoteIdState(id);
+ };
const { toast } = useToast();
const isCloudMode = useSettingsStore(selectIsCloudReasoningMode);
const effectiveModelId = useSettingsStore((s) => s.reasoningModel);
@@ -126,6 +133,11 @@ export default function PersonalNotesView({
lockSpeaker,
} = useMeetingTranscription();
const recordingNoteIdRef = useRef<number | null>(null);
+ const [recordingNoteId, setRecordingNoteId] = useState<number | null>(null);
+ const setActiveRecordingNoteId = (id: number | null) => {
+ recordingNoteIdRef.current = id;
+ setRecordingNoteId(id);
+ };
const {
folders,
@@ -169,7 +181,7 @@ export default function PersonalNotesView({
}, [activeNote?.calendar_event_id]);
const startRecording = useCallback(async () => {
- recordingNoteIdRef.current = activeNoteRef.current;
+ setActiveRecordingNoteId(activeNoteRef.current);
const note = notes.find((n) => n.id === activeNoteRef.current);
const seedSegments = note?.transcript ? parseTranscriptSegments(note.transcript) : [];
await startTranscription({ seedSegments, noteId: activeNoteRef.current });
@@ -196,7 +208,7 @@ export default function PersonalNotesView({
clearTimeout(enhancedSaveTimeoutRef.current);
enhancedSaveTimeoutRef.current = null;
}
- activeNoteRef.current = activeNote.id;
+ markNoteAsSynced(activeNote.id);
setLocalTitle(activeNote.title);
setLocalContent(activeNote.content);
setLocalEnhancedContent(activeNote.enhanced_content ?? null);
@@ -217,7 +229,7 @@ export default function PersonalNotesView({
clearTimeout(enhancedSaveTimeoutRef.current);
enhancedSaveTimeoutRef.current = null;
}
- activeNoteRef.current = null;
+ markNoteAsSynced(null);
setLocalTitle("");
setLocalContent("");
setLocalEnhancedContent(null);
@@ -475,7 +487,7 @@ export default function PersonalNotesView({
useEffect(() => {
if (!meetingRecordingRequest || activeNoteId !== meetingRecordingRequest.noteId) return;
- recordingNoteIdRef.current = meetingRecordingRequest.noteId;
+ setActiveRecordingNoteId(meetingRecordingRequest.noteId);
const note = notes.find((n) => n.id === meetingRecordingRequest.noteId);
const seedSegments = note?.transcript ? parseTranscriptSegments(note.transcript) : [];
startTranscription({ seedSegments, noteId: meetingRecordingRequest.noteId });
@@ -505,7 +517,7 @@ export default function PersonalNotesView({
if (noteId && transcript) {
window.electronAPI.updateNote(noteId, { transcript });
}
- recordingNoteIdRef.current = null;
+ setActiveRecordingNoteId(null);
}
prevTranscribingRef.current = isTranscribing;
}, [isTranscribing, realtimeTranscript, realtimeSegments]);
@@ -524,8 +536,8 @@ export default function PersonalNotesView({
return () => clearInterval(interval);
}, [isTranscribing, realtimeSegments]);
- const isLocalSynced = activeNoteRef.current === activeNote?.id;
- const isActiveNoteRecording = isTranscribing && recordingNoteIdRef.current === activeNote?.id;
+ const isLocalSynced = syncedNoteId === activeNote?.id;
+ const isActiveNoteRecording = isTranscribing && recordingNoteId === activeNote?.id;
const editorNote = activeNote
? {
...activeNote,