Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
refactor(notes): lift embedded chat hook to NoteEditor, simplify EmbeddedChat
Gabriel Stein942a7fd6a664
diff --git a/src/components/notes/EmbeddedChat.tsx b/src/components/notes/EmbeddedChat.tsxindex d6ddd1361..0ce8f9043 100644--- a/src/components/notes/EmbeddedChat.tsx+++ b/src/components/notes/EmbeddedChat.tsx@@ -1,24 +1,20 @@-import { useEffect, useCallback, forwardRef, useImperativeHandle } from "react";+import { useEffect, useCallback } from "react";import { useTranslation } from "react-i18next";import { X, PanelRight, PanelRightClose } from "lucide-react";import { cn } from "../lib/utils";import { ChatMessages } from "../chat/ChatMessages";import { ChatInput } from "../chat/ChatInput";-import { useEmbeddedChat } from "../../hooks/useEmbeddedChat";+import type { Message, AgentState } from "../chat/types";-type EmbeddedChatMode = "hidden" | "floating" | "sidebar";+export type EmbeddedChatMode = "hidden" | "floating" | "sidebar";interface EmbeddedChatProps {mode: EmbeddedChatMode;onModeChange: (mode: EmbeddedChatMode) => void;- noteId: number | null;- noteTitle: string;- noteContent: string;- noteTranscript?: string;-}--export interface EmbeddedChatHandle {- sendMessage: (text: string) => Promise<void>;+ messages: Message[];+ agentState: AgentState;+ onTextSubmit: (text: string) => void;+ onCancel: () => void;}function EmptyState() {@@ -32,129 +28,112 @@ function EmptyState() {);}-const EmbeddedChat = forwardRef<EmbeddedChatHandle, EmbeddedChatProps>(- function EmbeddedChat(- { mode, onModeChange, noteId, noteTitle, noteContent, noteTranscript },- ref- ) {- const { t } = useTranslation();- const { messages, agentState, sendMessage, cancelStream } = useEmbeddedChat({- noteId,- noteTitle,- noteContent,- noteTranscript,- });-- useImperativeHandle(ref, () => ({ sendMessage }), [sendMessage]);-- // Escape key closes floating panel- const handleKeyDown = useCallback(- (e: KeyboardEvent) => {- if (e.key === "Escape" && mode === "floating") {- onModeChange("hidden");- }- },- [mode, onModeChange]- );+export default function EmbeddedChat({+ mode,+ onModeChange,+ messages,+ agentState,+ onTextSubmit,+ onCancel,+}: EmbeddedChatProps) {+ const { t } = useTranslation();- useEffect(() => {- document.addEventListener("keydown", handleKeyDown);- return () => document.removeEventListener("keydown", handleKeyDown);- }, [handleKeyDown]);+ const handleKeyDown = useCallback(+ (e: KeyboardEvent) => {+ if (e.key === "Escape" && mode === "floating") {+ onModeChange("hidden");+ }+ },+ [mode, onModeChange]+ );- if (mode === "hidden") return null;+ useEffect(() => {+ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [handleKeyDown]);- const handleTextSubmit = (text: string) => {- sendMessage(text);- };+ if (mode === "hidden") return null;- const headerContent = (- <div className="h-9 flex items-center px-3 shrink-0">- <span className="text-xs font-medium text-foreground/50">- {t("embeddedChat.title")}- </span>- <div className="flex-1" />- <div className="flex items-center gap-0.5">- {mode === "floating" ? (- <button- onClick={() => onModeChange("sidebar")}- className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"- aria-label={t("embeddedChat.dock")}- >- <PanelRight size={13} />- </button>- ) : (- <button- onClick={() => onModeChange("floating")}- className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"- aria-label={t("embeddedChat.undock")}- >- <PanelRightClose size={13} />- </button>- )}+ const header = (+ <div className="h-9 flex items-center px-3 shrink-0">+ <span className="text-xs font-medium text-foreground/50">+ {t("embeddedChat.title")}+ </span>+ <div className="flex-1" />+ <div className="flex items-center gap-0.5">+ {mode === "floating" ? (+ <button+ onClick={() => onModeChange("sidebar")}+ className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"+ aria-label={t("embeddedChat.dock")}+ >+ <PanelRight size={13} />+ </button>+ ) : (<button- onClick={() => onModeChange("hidden")}+ onClick={() => onModeChange("floating")}className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"- aria-label={t("embeddedChat.close")}+ aria-label={t("embeddedChat.undock")}>- <X size={13} />+ <PanelRightClose size={13} /></button>- </div>+ )}+ <button+ onClick={() => onModeChange("hidden")}+ className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"+ aria-label={t("embeddedChat.close")}+ >+ <X size={13} />+ </button></div>- );+ </div>+ );- if (mode === "floating") {- return (- <div- className={cn(- "absolute bottom-20 right-4 z-20",- "w-[380px] max-h-[480px] min-h-[200px]",- "flex flex-col",- "bg-background/95 dark:bg-surface-2/95",- "border border-border/20 dark:border-white/8",- "rounded-xl",- "shadow-elevated",- "backdrop-blur-2xl",- "animate-[scale-in_200ms_ease-out]"- )}- >- {headerContent}- <ChatMessages messages={messages} emptyState={<EmptyState />} />- <ChatInput- agentState={agentState}- partialTranscript=""- onTextSubmit={handleTextSubmit}- onCancel={cancelStream}- showHotkey={false}- autoFocus={false}- />- </div>- );- }+ const chatContent = (+ <>+ {header}+ <ChatMessages messages={messages} emptyState={<EmptyState />} />+ <ChatInput+ agentState={agentState}+ partialTranscript=""+ onTextSubmit={onTextSubmit}+ onCancel={onCancel}+ showHotkey={false}+ autoFocus={false}+ />+ </>+ );- // sidebar mode+ if (mode === "floating") {return (<divclassName={cn(- "w-[340px] shrink-0",- "border-l border-border/15 dark:border-white/6",+ "absolute bottom-20 right-4 z-20",+ "w-95 max-h-120 min-h-50","flex flex-col",- "min-h-0"+ "bg-background/95 dark:bg-surface-2/95",+ "border border-border/20 dark:border-white/8",+ "rounded-xl",+ "shadow-elevated",+ "backdrop-blur-2xl",+ "animate-[scale-in_200ms_ease-out]")}>- {headerContent}- <ChatMessages messages={messages} emptyState={<EmptyState />} />- <ChatInput- agentState={agentState}- partialTranscript=""- onTextSubmit={handleTextSubmit}- onCancel={cancelStream}- showHotkey={false}- autoFocus={false}- />+ {chatContent}</div>);}-);-export default EmbeddedChat;+ return (+ <div+ className={cn(+ "w-85 shrink-0",+ "border-l border-border/15 dark:border-white/6",+ "flex flex-col",+ "min-h-0"+ )}+ >+ {chatContent}+ </div>+ );+}diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex 8c8c2a4c0..62a68f098 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -16,12 +16,11 @@ import type { NoteItem } from "../../types/electron";import type { ActionProcessingState } from "../../hooks/useActionProcessing";import ActionProcessingOverlay from "./ActionProcessingOverlay";import NoteBottomBar from "./NoteBottomBar";-import EmbeddedChat, { type EmbeddedChatHandle } from "./EmbeddedChat";+import EmbeddedChat, { type EmbeddedChatMode } from "./EmbeddedChat";+import { useEmbeddedChat } from "../../hooks/useEmbeddedChat";import { normalizeDbDate } from "../../utils/dateFormatting";import { parseTranscriptSegments } from "../../utils/parseTranscriptSegments";-type EmbeddedChatMode = "hidden" | "floating" | "sidebar";-function formatNoteDate(dateStr: string): string {const date = normalizeDbDate(dateStr);if (Number.isNaN(date.getTime())) return "";@@ -90,9 +89,14 @@ export default function NoteEditor({const { t } = useTranslation();const [viewMode, setViewMode] = useState<MeetingViewMode>("raw");const [chatMode, setChatMode] = useState<EmbeddedChatMode>("hidden");- const embeddedChatRef = useRef<EmbeddedChatHandle>(null);- const pendingAskRef = useRef<string | null>(null);const editorRef = useRef<Editor | null>(null);++ const embeddedChat = useEmbeddedChat({+ noteId: note.id,+ noteTitle: note.title,+ noteContent: note.content,+ noteTranscript: note.transcript,+ });const titleRef = useRef<HTMLDivElement>(null);const prevNoteIdRef = useRef<number>(note.id);@@ -216,24 +220,12 @@ export default function NoteEditor({[enhancement]);- // Handle ask submit from NoteBottomBar: open chat + send messageconst handleAskSubmit = useCallback((text: string) => {if (chatMode === "hidden") {- pendingAskRef.current = text;setChatMode("floating");- } else {- embeddedChatRef.current?.sendMessage(text);- }- }, [chatMode]);-- // Send pending message once EmbeddedChat mounts- useEffect(() => {- if (chatMode !== "hidden" && pendingAskRef.current && embeddedChatRef.current) {- const text = pendingAskRef.current;- pendingAskRef.current = null;- embeddedChatRef.current.sendMessage(text);}- }, [chatMode]);+ embeddedChat.sendMessage(text);+ }, [chatMode, embeddedChat]);const wordCount = useMemo(() => {const trimmed = note.content.trim();@@ -404,25 +396,23 @@ export default function NoteEditor({/>{chatMode === "floating" && (<EmbeddedChat- ref={embeddedChatRef}mode="floating"onModeChange={setChatMode}- noteId={note.id}- noteTitle={note.title}- noteContent={note.content}- noteTranscript={note.transcript}+ messages={embeddedChat.messages}+ agentState={embeddedChat.agentState}+ onTextSubmit={embeddedChat.sendMessage}+ onCancel={embeddedChat.cancelStream}/>)}</div>{chatMode === "sidebar" && (<EmbeddedChat- ref={embeddedChatRef}mode="sidebar"onModeChange={setChatMode}- noteId={note.id}- noteTitle={note.title}- noteContent={note.content}- noteTranscript={note.transcript}+ messages={embeddedChat.messages}+ agentState={embeddedChat.agentState}+ onTextSubmit={embeddedChat.sendMessage}+ onCancel={embeddedChat.cancelStream}/>)}</div>