From 9078db9fb854f3efd1db129a41c0b27d31c6bb18 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 03:02:06 +0900 Subject: [PATCH 01/11] hotfix --- .../editor-area/floating-button.tsx | 8 +-- .../src/components/editor-area/index.tsx | 62 ++++++++++++------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/apps/desktop/src/components/editor-area/floating-button.tsx b/apps/desktop/src/components/editor-area/floating-button.tsx index 038f7b0c8..c6cde3141 100644 --- a/apps/desktop/src/components/editor-area/floating-button.tsx +++ b/apps/desktop/src/components/editor-area/floating-button.tsx @@ -46,7 +46,7 @@ interface FloatingButtonProps { handleEnhanceWithTemplate: (templateId: string) => void; templates: Template[]; isError: boolean; - progress: number; + progress?: number; isLocalLlm: boolean; } @@ -56,7 +56,7 @@ export function FloatingButton({ handleEnhanceWithTemplate, templates, isError, - progress, + progress = 0, isLocalLlm, }: FloatingButtonProps) { const { userId } = useHypr(); @@ -180,8 +180,8 @@ export function FloatingButton({ } }; - // Only show progress for local LLMs - const shouldShowProgress = isLocalLlm && progress >= 0 && progress < 1; + // Only show progress for local LLMs AND when progress exists + const shouldShowProgress = isLocalLlm && progress !== undefined && progress >= 0 && progress < 1; if (isError) { const errorRetryButtonClasses = cn( diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index d8d25d337..cfe6a0edb 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -97,10 +97,16 @@ export default function EditorArea({ const preMeetingNote = useSession(sessionId, (s) => s.session.pre_meeting_memo_html) ?? ""; const hasTranscriptWords = useSession(sessionId, (s) => s.session.words.length > 0); + const llmConnectionQuery = useQuery({ + queryKey: ["llm-connection"], + queryFn: () => connectorCommands.getLlmConnection(), + }); + const { enhance, progress } = useEnhanceMutation({ sessionId, preMeetingNote, rawContent, + isLocalLlm: llmConnectionQuery.data?.type === "HyprLocal", onSuccess: (content) => { generateTitle.mutate({ enhancedContent: content }); @@ -205,11 +211,6 @@ export default function EditorArea({ })); }; - const llmConnectionQuery = useQuery({ - queryKey: ["llm-connection"], - queryFn: () => connectorCommands.getLlmConnection(), - }); - return (
void; }) { const { userId, onboardingSessionId } = useHypr(); @@ -313,7 +316,10 @@ export function useEnhanceMutation({ const enhance = useMutation({ mutationKey: ["enhance", sessionId], mutationFn: async () => { - setProgress(0); // Reset progress when starting + if (isLocalLlm) { + setProgress(0); + } + const fn = sessionId === onboardingSessionId ? dbCommands.getWordsOnboarding : dbCommands.getWords; @@ -406,9 +412,11 @@ Sections:`; const { text, fullStream } = streamText({ abortSignal, model, - tools: { - update_progress: tool({ parameters: z.any() }), - }, + ...(isLocalLlm && { + tools: { + update_progress: tool({ parameters: z.any() }), + }, + }), messages: [ { role: "system", content: systemMessage }, { role: "user", content: userMessage }, @@ -417,18 +425,20 @@ Sections:`; markdownTransform(), smoothStream({ delayInMs: 80, chunking: "line" }), ], - providerOptions: { - [localProviderName]: { - metadata: customGrammar - ? { - grammar: "custom", - customGrammar: customGrammar, - } - : { - grammar: "enhance", - }, + ...(isLocalLlm && { + providerOptions: { + [localProviderName]: { + metadata: customGrammar + ? { + grammar: "custom", + customGrammar: customGrammar, + } + : { + grammar: "enhance", + }, + }, }, - }, + }), }); let acc = ""; @@ -436,7 +446,7 @@ Sections:`; if (chunk.type === "text-delta") { acc += chunk.textDelta; } - if (chunk.type === "tool-call") { + if (chunk.type === "tool-call" && isLocalLlm) { const chunkProgress = chunk.args?.progress ?? 0; setProgress(chunkProgress); } @@ -459,10 +469,14 @@ Sections:`; }); persistSession(); - setProgress(0); + if (isLocalLlm) { + setProgress(0); + } }, onError: (error) => { - setProgress(0); + if (isLocalLlm) { + setProgress(0); + } console.error(error); if (!(error as unknown as string).includes("cancel")) { @@ -471,7 +485,7 @@ Sections:`; }, }); - return { enhance, progress }; + return { enhance, progress: isLocalLlm ? progress : undefined }; } function useGenerateTitleMutation({ sessionId }: { sessionId: string }) { From a774fb792a87df68d09cb852734adf08870a7bf4 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 03:04:15 +0900 Subject: [PATCH 02/11] went through formatting --- apps/desktop/src/components/editor-area/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index cfe6a0edb..2105cb462 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -319,7 +319,7 @@ export function useEnhanceMutation({ if (isLocalLlm) { setProgress(0); } - + const fn = sessionId === onboardingSessionId ? dbCommands.getWordsOnboarding : dbCommands.getWords; From 5abd55db8c9a96d06357c58e0875b99c35914bc1 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 17:41:22 +0900 Subject: [PATCH 03/11] hotfix - re-fetching logic --- .../editor-area/floating-button.tsx | 84 +++++++++++-------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/apps/desktop/src/components/editor-area/floating-button.tsx b/apps/desktop/src/components/editor-area/floating-button.tsx index c6cde3141..b1ce5248f 100644 --- a/apps/desktop/src/components/editor-area/floating-button.tsx +++ b/apps/desktop/src/components/editor-area/floating-button.tsx @@ -1,5 +1,6 @@ import { PlusIcon, RefreshCwIcon, TypeOutlineIcon, XIcon, ZapIcon } from "lucide-react"; import { useEffect, useRef, useState } from "react"; +import { useQueryClient } from "@tanstack/react-query"; import { useHypr } from "@/contexts"; import { useEnhancePendingState } from "@/hooks/enhance-pending"; @@ -70,6 +71,7 @@ export function FloatingButton({ const [showRefreshIcon, setShowRefreshIcon] = useState(true); const [showTemplatePopover, setShowTemplatePopover] = useState(false); const hideTimeoutRef = useRef(null); + const queryClient = useQueryClient(); // Clear timeout on cleanup useEffect(() => { @@ -111,6 +113,7 @@ export function FloatingButton({ hideTimeoutRef.current = null; } if (!showRaw && !isEnhancePending && showRefreshIcon) { + queryClient.invalidateQueries({ queryKey: ["templates"] }); setShowTemplatePopover(true); } }; @@ -121,11 +124,11 @@ export function FloatingButton({ }, 100); }; - // Simple template selection - just call parent function const handleTemplateSelect = (templateId: string) => { setShowTemplatePopover(false); - // Send analytics event for custom template usage (not for "auto") + queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); + if (templateId !== "auto") { analyticsCommands.event({ event: "custom_template_enhancement_started", @@ -136,45 +139,22 @@ export function FloatingButton({ handleEnhanceWithTemplate(templateId); }; - // Helper function to extract emoji and clean name - const extractEmojiAndName = (title: string) => { - const emojiMatch = title.match(/^(\p{Emoji})\s*/u); - if (emojiMatch) { - return { - emoji: emojiMatch[1], - name: title.replace(/^(\p{Emoji})\s*/u, "").trim(), - }; - } - - // Fallback emoji based on keywords if no emoji in title - const lowercaseTitle = title.toLowerCase(); - let fallbackEmoji = "📄"; - if (lowercaseTitle.includes("meeting")) { - fallbackEmoji = "💼"; - } - if (lowercaseTitle.includes("interview")) { - fallbackEmoji = "👔"; - } - if (lowercaseTitle.includes("standup")) { - fallbackEmoji = "☀️"; - } - if (lowercaseTitle.includes("review")) { - fallbackEmoji = "📝"; - } - - return { - emoji: fallbackEmoji, - name: title, - }; - }; - const handleAddTemplate = async () => { setShowTemplatePopover(false); try { - // Open settings window + queryClient.invalidateQueries({ queryKey: ["templates"] }); + await windowsCommands.windowShow({ type: "settings" }); - // Navigate to templates tab await windowsCommands.windowNavigate({ type: "settings" }, "/app/settings?tab=templates"); + + const handleWindowFocus = () => { + queryClient.invalidateQueries({ queryKey: ["templates"] }); + queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); + window.removeEventListener("focus", handleWindowFocus); + }; + + window.addEventListener("focus", handleWindowFocus); + } catch (error) { console.error("Failed to open settings/templates:", error); } @@ -356,3 +336,35 @@ function RunOrRerun({ showRefresh }: { showRefresh: boolean }) {
); } + +// Helper function to extract emoji and clean name +const extractEmojiAndName = (title: string) => { + const emojiMatch = title.match(/^(\p{Emoji})\s*/u); + if (emojiMatch) { + return { + emoji: emojiMatch[1], + name: title.replace(/^(\p{Emoji})\s*/u, "").trim(), + }; + } + + // Fallback emoji based on keywords if no emoji in title + const lowercaseTitle = title.toLowerCase(); + let fallbackEmoji = "📄"; + if (lowercaseTitle.includes("meeting")) { + fallbackEmoji = "💼"; + } + if (lowercaseTitle.includes("interview")) { + fallbackEmoji = "👔"; + } + if (lowercaseTitle.includes("standup")) { + fallbackEmoji = "☀️"; + } + if (lowercaseTitle.includes("review")) { + fallbackEmoji = "📝"; + } + + return { + emoji: fallbackEmoji, + name: title, + }; +}; From ae6205b13ff1ee6f07013b47ae459a868cbfbdd7 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 17:48:17 +0900 Subject: [PATCH 04/11] formatted --- .../src/components/editor-area/floating-button.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/components/editor-area/floating-button.tsx b/apps/desktop/src/components/editor-area/floating-button.tsx index b1ce5248f..68e582536 100644 --- a/apps/desktop/src/components/editor-area/floating-button.tsx +++ b/apps/desktop/src/components/editor-area/floating-button.tsx @@ -1,6 +1,6 @@ +import { useQueryClient } from "@tanstack/react-query"; import { PlusIcon, RefreshCwIcon, TypeOutlineIcon, XIcon, ZapIcon } from "lucide-react"; import { useEffect, useRef, useState } from "react"; -import { useQueryClient } from "@tanstack/react-query"; import { useHypr } from "@/contexts"; import { useEnhancePendingState } from "@/hooks/enhance-pending"; @@ -143,18 +143,17 @@ export function FloatingButton({ setShowTemplatePopover(false); try { queryClient.invalidateQueries({ queryKey: ["templates"] }); - + await windowsCommands.windowShow({ type: "settings" }); await windowsCommands.windowNavigate({ type: "settings" }, "/app/settings?tab=templates"); - + const handleWindowFocus = () => { queryClient.invalidateQueries({ queryKey: ["templates"] }); queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); window.removeEventListener("focus", handleWindowFocus); }; - + window.addEventListener("focus", handleWindowFocus); - } catch (error) { console.error("Failed to open settings/templates:", error); } From 51a22c75b9f0586fe315c57c966cf4e85c49d755 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 18:45:35 +0900 Subject: [PATCH 05/11] final final fix --- .../editor-area/floating-button.tsx | 2 -- .../src/components/editor-area/index.tsx | 33 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/desktop/src/components/editor-area/floating-button.tsx b/apps/desktop/src/components/editor-area/floating-button.tsx index 68e582536..0c3141ff7 100644 --- a/apps/desktop/src/components/editor-area/floating-button.tsx +++ b/apps/desktop/src/components/editor-area/floating-button.tsx @@ -127,8 +127,6 @@ export function FloatingButton({ const handleTemplateSelect = (templateId: string) => { setShowTemplatePopover(false); - queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); - if (templateId !== "auto") { analyticsCommands.event({ event: "custom_template_enhancement_started", diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index 2105cb462..420953e3a 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -292,6 +292,8 @@ export function useEnhanceMutation({ }) { const { userId, onboardingSessionId } = useHypr(); const [progress, setProgress] = useState(0); + const [actualIsLocalLlm, setActualIsLocalLlm] = useState(isLocalLlm); + const queryClient = useQueryClient(); const preMeetingText = extractTextFromHtml(preMeetingNote); const rawText = extractTextFromHtml(rawContent); @@ -316,7 +318,15 @@ export function useEnhanceMutation({ const enhance = useMutation({ mutationKey: ["enhance", sessionId], mutationFn: async () => { - if (isLocalLlm) { + await queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); + await new Promise(resolve => setTimeout(resolve, 100)); + + const { type } = await connectorCommands.getLlmConnection(); + const freshIsLocalLlm = type === "HyprLocal"; + + setActualIsLocalLlm(freshIsLocalLlm); + + if (freshIsLocalLlm) { setProgress(0); } @@ -334,12 +344,9 @@ export function useEnhanceMutation({ dismissible: true, duration: 5000, }); - return; } - const { type } = await connectorCommands.getLlmConnection(); - const config = await dbCommands.getConfig(); let templateInfo = ""; @@ -399,8 +406,6 @@ Sections:`; : provider.languageModel("defaultModel"); if (sessionId !== onboardingSessionId) { - const { type } = await connectorCommands.getLlmConnection(); - analyticsCommands.event({ event: "normal_enhance_start", distinct_id: userId, @@ -412,7 +417,8 @@ Sections:`; const { text, fullStream } = streamText({ abortSignal, model, - ...(isLocalLlm && { + // Use fresh value for tools + ...(freshIsLocalLlm && { tools: { update_progress: tool({ parameters: z.any() }), }, @@ -425,7 +431,8 @@ Sections:`; markdownTransform(), smoothStream({ delayInMs: 80, chunking: "line" }), ], - ...(isLocalLlm && { + // Use fresh value for provider options + ...(freshIsLocalLlm && { providerOptions: { [localProviderName]: { metadata: customGrammar @@ -446,7 +453,8 @@ Sections:`; if (chunk.type === "text-delta") { acc += chunk.textDelta; } - if (chunk.type === "tool-call" && isLocalLlm) { + // Use fresh value for progress updates + if (chunk.type === "tool-call" && freshIsLocalLlm) { const chunkProgress = chunk.args?.progress ?? 0; setProgress(chunkProgress); } @@ -469,12 +477,13 @@ Sections:`; }); persistSession(); - if (isLocalLlm) { + + if (actualIsLocalLlm) { setProgress(0); } }, onError: (error) => { - if (isLocalLlm) { + if (actualIsLocalLlm) { setProgress(0); } console.error(error); @@ -485,7 +494,7 @@ Sections:`; }, }); - return { enhance, progress: isLocalLlm ? progress : undefined }; + return { enhance, progress: actualIsLocalLlm ? progress : undefined }; } function useGenerateTitleMutation({ sessionId }: { sessionId: string }) { From b4c3b77e29cc1830fa44106e623f224f05999fbb Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Mon, 7 Jul 2025 18:46:00 +0900 Subject: [PATCH 06/11] formatting --- apps/desktop/src/components/editor-area/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index 420953e3a..afc2b3eb6 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -323,7 +323,7 @@ export function useEnhanceMutation({ const { type } = await connectorCommands.getLlmConnection(); const freshIsLocalLlm = type === "HyprLocal"; - + setActualIsLocalLlm(freshIsLocalLlm); if (freshIsLocalLlm) { @@ -477,7 +477,7 @@ Sections:`; }); persistSession(); - + if (actualIsLocalLlm) { setProgress(0); } From 7f396c30f916e0d08e4fd9a755c527fc996b851b Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Tue, 8 Jul 2025 00:02:53 +0900 Subject: [PATCH 07/11] refactored template selection --- .../editor-area/floating-button.tsx | 1 - .../src/components/editor-area/index.tsx | 108 ++++-------------- 2 files changed, 24 insertions(+), 85 deletions(-) diff --git a/apps/desktop/src/components/editor-area/floating-button.tsx b/apps/desktop/src/components/editor-area/floating-button.tsx index 0c3141ff7..f59c63e7c 100644 --- a/apps/desktop/src/components/editor-area/floating-button.tsx +++ b/apps/desktop/src/components/editor-area/floating-button.tsx @@ -147,7 +147,6 @@ export function FloatingButton({ const handleWindowFocus = () => { queryClient.invalidateQueries({ queryKey: ["templates"] }); - queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); window.removeEventListener("focus", handleWindowFocus); }; diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index afc2b3eb6..c66103cea 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -63,37 +63,12 @@ export default function EditorArea({ [sessionId, showRaw], ); - const [needsRestoration, setNeedsRestoration] = useState(false); - const [originalTemplateId, setOriginalTemplateId] = useState(null); - const queryClient = useQueryClient(); - - const configQuery = useQuery({ - queryKey: ["config", "general"], - queryFn: async () => { - const result = await dbCommands.getConfig(); - return result; - }, - }); - - const setConfigMutation = useMutation({ - mutationFn: async (configData: any) => { - await dbCommands.setConfig(configData); - }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["config", "general"] }); - }, - onError: (error) => { - console.error("Failed to set template config:", error); - }, - }); - const templatesQuery = useQuery({ queryKey: ["templates"], queryFn: () => dbCommands.listTemplates(), refetchOnWindowFocus: true, }); - const generateTitle = useGenerateTitleMutation({ sessionId }); const preMeetingNote = useSession(sessionId, (s) => s.session.pre_meeting_memo_html) ?? ""; const hasTranscriptWords = useSession(sessionId, (s) => s.session.words.length > 0); @@ -108,27 +83,14 @@ export default function EditorArea({ rawContent, isLocalLlm: llmConnectionQuery.data?.type === "HyprLocal", onSuccess: (content) => { - generateTitle.mutate({ enhancedContent: content }); - - if (needsRestoration && configQuery.data) { - const restoreConfig = { - ...configQuery.data, - general: { - ...configQuery.data.general, - selected_template_id: originalTemplateId, - }, - }; - setConfigMutation.mutate(restoreConfig); - setNeedsRestoration(false); - setOriginalTemplateId(null); - } - if (hasTranscriptWords) { generateTitle.mutate({ enhancedContent: content }); } }, }); + const generateTitle = useGenerateTitleMutation({ sessionId }); + useAutoEnhance({ sessionId, enhanceStatus: enhance.status, @@ -151,46 +113,13 @@ export default function EditorArea({ [showRaw, enhancedContent, rawContent], ); - const handleEnhanceWithTemplate = useCallback(async (templateId: string) => { - if (configQuery.data) { - const currentTemplateId = configQuery.data.general?.selected_template_id || null; - setOriginalTemplateId(currentTemplateId); - setNeedsRestoration(true); - - const targetTemplateId = templateId === "auto" ? null : templateId; - - const updatedConfig = { - ...configQuery.data, - general: { - ...configQuery.data.general, - selected_template_id: targetTemplateId, - }, - }; - - try { - await setConfigMutation.mutateAsync(updatedConfig); - - await new Promise(resolve => setTimeout(resolve, 200)); - - const verifyConfig = await dbCommands.getConfig(); - - if (verifyConfig.general?.selected_template_id !== targetTemplateId) { - setOriginalTemplateId(null); - setNeedsRestoration(false); - return; - } - } catch (error) { - setOriginalTemplateId(null); - setNeedsRestoration(false); - return; - } - } - - enhance.mutate(); - }, [enhance, configQuery.data, setConfigMutation]); + const handleEnhanceWithTemplate = useCallback((templateId: string) => { + const targetTemplateId = templateId === "auto" ? null : templateId; + enhance.mutate({ templateId: targetTemplateId, triggerType: 'template' }); + }, [enhance]); const handleClickEnhance = useCallback(() => { - enhance.mutate(); + enhance.mutate({ triggerType: 'manual' }); }, [enhance]); const safelyFocusEditor = useCallback(() => { @@ -317,7 +246,13 @@ export function useEnhanceMutation({ const enhance = useMutation({ mutationKey: ["enhance", sessionId], - mutationFn: async () => { + mutationFn: async ({ + triggerType, + templateId + }: { + triggerType: 'manual' | 'template' | 'auto'; + templateId?: string | null; + } = { triggerType: 'manual' }) => { await queryClient.invalidateQueries({ queryKey: ["llm-connection"] }); await new Promise(resolve => setTimeout(resolve, 100)); @@ -347,15 +282,20 @@ export function useEnhanceMutation({ return; } + // Get current config for default template const config = await dbCommands.getConfig(); + + // Use provided templateId or fall back to config + const effectiveTemplateId = templateId !== undefined + ? templateId + : config.general?.selected_template_id; let templateInfo = ""; let customGrammar: string | null = null; - const selectedTemplateId = config.general.selected_template_id; - if (selectedTemplateId) { + if (effectiveTemplateId) { const templates = await dbCommands.listTemplates(); - const selectedTemplate = templates.find(t => t.id === selectedTemplateId); + const selectedTemplate = templates.find(t => t.id === effectiveTemplateId); if (selectedTemplate) { if (selectedTemplate.sections && selectedTemplate.sections.length > 0) { @@ -560,7 +500,7 @@ function useAutoEnhance({ }: { sessionId: string; enhanceStatus: string; - enhanceMutate: () => void; + enhanceMutate: (params: { triggerType: 'auto' }) => void; }) { const ongoingSessionStatus = useOngoingSession((s) => s.status); const prevOngoingSessionStatus = usePreviousValue(ongoingSessionStatus); @@ -573,7 +513,7 @@ function useAutoEnhance({ && enhanceStatus !== "pending" ) { setShowRaw(false); - enhanceMutate(); + enhanceMutate({ triggerType: 'auto' }); } }, [ ongoingSessionStatus, From 50453d6bfd1f664b72fa1b161b3d793c55615b19 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Tue, 8 Jul 2025 00:39:46 +0900 Subject: [PATCH 08/11] added template selector after recording --- .../src/components/editor-area/index.tsx | 17 ++++- .../editor-area/note-header/listen-button.tsx | 63 +++++++++++++++++-- packages/utils/src/stores/ongoing-session.ts | 10 +++ 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index c66103cea..aacccbbef 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -500,9 +500,11 @@ function useAutoEnhance({ }: { sessionId: string; enhanceStatus: string; - enhanceMutate: (params: { triggerType: 'auto' }) => void; + enhanceMutate: (params: { triggerType: 'auto'; templateId?: string | null }) => void; }) { const ongoingSessionStatus = useOngoingSession((s) => s.status); + const autoEnhanceTemplate = useOngoingSession((s) => s.autoEnhanceTemplate); + const setAutoEnhanceTemplate = useOngoingSession((s) => s.setAutoEnhanceTemplate); const prevOngoingSessionStatus = usePreviousValue(ongoingSessionStatus); const setShowRaw = useSession(sessionId, (s) => s.setShowRaw); @@ -513,7 +515,15 @@ function useAutoEnhance({ && enhanceStatus !== "pending" ) { setShowRaw(false); - enhanceMutate({ triggerType: 'auto' }); + + // Use the selected template and then clear it + enhanceMutate({ + triggerType: 'auto', + templateId: autoEnhanceTemplate + }); + + // Clear the template after using it (one-time use) + setAutoEnhanceTemplate(null); } }, [ ongoingSessionStatus, @@ -521,6 +531,9 @@ function useAutoEnhance({ sessionId, enhanceMutate, setShowRaw, + autoEnhanceTemplate, + setAutoEnhanceTemplate, + prevOngoingSessionStatus, ]); } diff --git a/apps/desktop/src/components/editor-area/note-header/listen-button.tsx b/apps/desktop/src/components/editor-area/note-header/listen-button.tsx index 102cd9fd2..7fe01cdd1 100644 --- a/apps/desktop/src/components/editor-area/note-header/listen-button.tsx +++ b/apps/desktop/src/components/editor-area/note-header/listen-button.tsx @@ -1,6 +1,6 @@ import { Trans } from "@lingui/react/macro"; import { useMutation, useQuery } from "@tanstack/react-query"; -import { MicIcon, MicOffIcon, PauseIcon, PlayIcon, StopCircleIcon, Volume2Icon, VolumeOffIcon } from "lucide-react"; +import { ChevronDownIcon, MicIcon, MicOffIcon, PauseIcon, PlayIcon, StopCircleIcon, Volume2Icon, VolumeOffIcon } from "lucide-react"; import { useEffect, useState } from "react"; import SoundIndicator from "@/components/sound-indicator"; @@ -8,8 +8,10 @@ import { useHypr } from "@/contexts"; import { useEnhancePendingState } from "@/hooks/enhance-pending"; import { commands as listenerCommands } from "@hypr/plugin-listener"; import { commands as localSttCommands } from "@hypr/plugin-local-stt"; +import { commands as dbCommands, Template } from "@hypr/plugin-db"; import { Button } from "@hypr/ui/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/popover"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@hypr/ui/components/ui/select"; import { Spinner } from "@hypr/ui/components/ui/spinner"; import { sonnerToast, toast } from "@hypr/ui/components/ui/toast"; import { Tooltip, TooltipContent, TooltipTrigger } from "@hypr/ui/components/ui/tooltip"; @@ -222,6 +224,7 @@ function WhenActive() { const ongoingSessionStore = useOngoingSession((s) => ({ pause: s.pause, stop: s.stop, + setAutoEnhanceTemplate: s.setAutoEnhanceTemplate, })); const sessionWords = useSession(ongoingSessionId!, (s) => s.session.words); const [isPopoverOpen, setIsPopoverOpen] = useState(false); @@ -231,7 +234,11 @@ function WhenActive() { setIsPopoverOpen(false); }; - const handleStopSession = () => { + const handleStopSession = (templateId?: string | null) => { + if (templateId !== undefined) { + ongoingSessionStore.setAutoEnhanceTemplate(templateId); + } + ongoingSessionStore.stop(); setIsPopoverOpen(false); @@ -241,7 +248,7 @@ function WhenActive() { }; return ( - +