diff --git a/apps/desktop/src/components/editor-area/note-header/sub-headers/enhanced-note-sub-header.tsx b/apps/desktop/src/components/editor-area/note-header/sub-headers/enhanced-note-sub-header.tsx index b76a7f5bfe..ba31af0bda 100644 --- a/apps/desktop/src/components/editor-area/note-header/sub-headers/enhanced-note-sub-header.tsx +++ b/apps/desktop/src/components/editor-area/note-header/sub-headers/enhanced-note-sub-header.tsx @@ -39,13 +39,27 @@ export function EnhancedNoteSubHeader({ const templatesQuery = useQuery({ queryKey: ["templates"], queryFn: () => - TemplateService.getAllTemplates().then((templates) => - templates.map((template) => { + TemplateService.getAllTemplates().then((templates) => { + const sortedTemplates = templates.sort((a, b) => { + const aIsBuiltin = a.tags?.includes("builtin") || false; + const bIsBuiltin = b.tags?.includes("builtin") || false; + + if (aIsBuiltin === bIsBuiltin) { + return 0; + } + return aIsBuiltin ? 1 : -1; // custom templates come first + }); + + return sortedTemplates.map((template) => { const title = template.title || "Untitled"; const truncatedTitle = title.length > 30 ? title.substring(0, 30) + "..." : title; - return { id: template.id, title: truncatedTitle, fullTitle: template.title || "" }; - }) - ), + return { + id: template.id, + title: truncatedTitle, + fullTitle: template.title || "", + }; + }); + }), refetchOnWindowFocus: true, }); @@ -57,6 +71,13 @@ export function EnhancedNoteSubHeader({ }, }); + const handleTemplateDropdownChange = (open: boolean) => { + setIsTemplateDropdownOpen(open); + if (open) { + templatesQuery.refetch(); + } + }; + const handleRegenerateOrCancel = () => { if (isEnhancing) { // Cancel the enhancement @@ -79,11 +100,11 @@ export function EnhancedNoteSubHeader({ const actualTemplateId = templateId === "auto" ? null : templateId; onEnhance({ triggerType: "template", templateId: actualTemplateId }); } - setIsTemplateDropdownOpen(false); + handleTemplateDropdownChange(false); }; const handleAddTemplate = async () => { - setIsTemplateDropdownOpen(false); + handleTemplateDropdownChange(false); try { await windowsCommands.windowShow({ type: "settings" }); await windowsCommands.windowNavigate({ type: "settings" }, "/app/settings?tab=templates"); @@ -144,37 +165,13 @@ export function EnhancedNoteSubHeader({