From c606b74f749d47815363369abfdfe88889c031e7 Mon Sep 17 00:00:00 2001 From: Deokhaeng Lee Date: Sat, 12 Jul 2025 02:03:41 +0900 Subject: [PATCH 1/5] added default templates --- Cargo.lock | 12 +- .../src/components/editor-area/index.tsx | 6 +- .../editor-area/note-header/listen-button.tsx | 3 +- .../components/settings/views/template.tsx | 77 +++---- .../components/settings/views/templates.tsx | 34 +-- apps/desktop/src/utils/default-templates.ts | 204 ++++++++++++++++++ apps/desktop/src/utils/template-service.ts | 88 ++++++++ 7 files changed, 364 insertions(+), 60 deletions(-) create mode 100644 apps/desktop/src/utils/default-templates.ts create mode 100644 apps/desktop/src/utils/template-service.ts diff --git a/Cargo.lock b/Cargo.lock index 9a911077db..66094c5bc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1756,7 +1756,7 @@ dependencies = [ "bitflags 2.9.1", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -2676,7 +2676,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -2685,7 +2685,7 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -7751,7 +7751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.53.0", ] [[package]] @@ -10469,7 +10469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.101", @@ -16555,7 +16555,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index 8fa50a7710..581629190a 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -8,6 +8,7 @@ import { z } from "zod"; import { useHypr } from "@/contexts"; import { extractTextFromHtml } from "@/utils/parse"; +import { TemplateService } from "@/utils/template-service"; import { commands as analyticsCommands } from "@hypr/plugin-analytics"; import { commands as connectorCommands } from "@hypr/plugin-connector"; import { commands as dbCommands } from "@hypr/plugin-db"; @@ -65,7 +66,7 @@ export default function EditorArea({ const templatesQuery = useQuery({ queryKey: ["templates"], - queryFn: () => dbCommands.listTemplates(), + queryFn: () => TemplateService.getAllTemplates(), refetchOnWindowFocus: true, }); @@ -293,8 +294,7 @@ export function useEnhanceMutation({ return null; } - const templates = await dbCommands.listTemplates(); - return templates.find(t => t.id === effectiveTemplateId) || null; + return await TemplateService.getTemplate(effectiveTemplateId); }; const selectedTemplate = await getTemplate(); 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 f5caa018d8..4c69f5fede 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 @@ -6,6 +6,7 @@ import { useEffect, useState } from "react"; import SoundIndicator from "@/components/sound-indicator"; import { useHypr } from "@/contexts"; import { useEnhancePendingState } from "@/hooks/enhance-pending"; +import { TemplateService } from "@/utils/template-service"; import { commands as dbCommands } from "@hypr/plugin-db"; import { commands as listenerCommands } from "@hypr/plugin-listener"; import { commands as localSttCommands } from "@hypr/plugin-local-stt"; @@ -299,7 +300,7 @@ function RecordingControls({ const templatesQuery = useQuery({ queryKey: ["templates"], - queryFn: () => dbCommands.listTemplates(), + queryFn: () => TemplateService.getAllTemplates(), refetchOnWindowFocus: true, }); diff --git a/apps/desktop/src/components/settings/views/template.tsx b/apps/desktop/src/components/settings/views/template.tsx index 9a7d29f639..f492a0299f 100644 --- a/apps/desktop/src/components/settings/views/template.tsx +++ b/apps/desktop/src/components/settings/views/template.tsx @@ -1,4 +1,5 @@ import { type Template } from "@hypr/plugin-db"; +import { TemplateService } from "@/utils/template-service"; import { Button } from "@hypr/ui/components/ui/button"; import { DropdownMenu, @@ -75,8 +76,13 @@ export default function TemplateEditor({ }: TemplateEditorProps) { const { t } = useLingui(); + // Check if this is a built-in template + const isBuiltinTemplate = !TemplateService.canEditTemplate(template.id); + const isReadOnly = disabled || isBuiltinTemplate; + console.log("now in template editor"); console.log("template: ", template); + console.log("isBuiltinTemplate: ", isBuiltinTemplate); // Extract emoji from title or use default const extractEmojiFromTitle = (title: string) => { @@ -145,7 +151,7 @@ export default function TemplateEditor({ - - - - - Duplicate - - - - - Delete - - - - ) - : ( - - )} + {/* Menu Button - Show for all templates with different options */} + {isCreator && ( + + + + + + + + Duplicate + + + {/* Only show separator and delete option for custom templates */} + {!isBuiltinTemplate && ( + <> + + + + Delete + + + )} + + + )} @@ -224,7 +227,7 @@ export default function TemplateEditor({ Description