Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Button } from "@hypr/ui/components/ui/button";
import { MessageSquare, Sparkles } from "lucide-react";
import { useEffect, useRef, useState } from "react";

import { useHypr } from "@/contexts";
import { commands as analyticsCommands } from "@hypr/plugin-analytics";

interface TextSelectionPopoverProps {
isEnhancedNote: boolean;
onAnnotate: (selectedText: string, selectedRect: DOMRect) => void;
Expand All @@ -19,6 +22,7 @@ export function TextSelectionPopover(
) {
const [selection, setSelection] = useState<SelectionInfo | null>(null);
const delayTimeoutRef = useRef<NodeJS.Timeout>();
const { userId } = useHypr();

useEffect(() => {
if (!isEnhancedNote) {
Expand Down Expand Up @@ -91,6 +95,11 @@ export function TextSelectionPopover(
}

const handleAnnotateClick = () => {
analyticsCommands.event({
event: "source_view_clicked",
distinct_id: userId,
});

onAnnotate(selection.text, selection.rect);
setSelection(null); // Hide the popover
};
Expand Down
65 changes: 34 additions & 31 deletions apps/desktop/src/components/settings/views/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/
import { Textarea } from "@hypr/ui/components/ui/textarea";
import { Trans, useLingui } from "@lingui/react/macro";
import { CopyIcon, MoreHorizontalIcon, TrashIcon } from "lucide-react";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { SectionsList } from "../components/template-sections";

interface TemplateEditorProps {
Expand Down Expand Up @@ -94,36 +94,41 @@ export default function TemplateEditor({
return title.replace(/^(\p{Emoji})\s*/u, "");
};

// Local state for both inputs
const [titleText, setTitleText] = useState(() => getTitleWithoutEmoji(template.title || ""));
const [descriptionText, setDescriptionText] = useState(template.description || "");
const [selectedEmoji, setSelectedEmoji] = useState(() => extractEmojiFromTitle(template.title || ""));

const [emojiPopoverOpen, setEmojiPopoverOpen] = useState(false);

const handleChangeTitle = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const titleWithoutEmoji = e.target.value;
const fullTitle = selectedEmoji + " " + titleWithoutEmoji;
onTemplateUpdate({ ...template, title: fullTitle });
},
[onTemplateUpdate, template, selectedEmoji],
);
// Sync local state when template ID changes (new template loaded)
useEffect(() => {
setTitleText(getTitleWithoutEmoji(template.title || ""));
setDescriptionText(template.description || "");
setSelectedEmoji(extractEmojiFromTitle(template.title || ""));
}, [template.id]);

const handleEmojiSelect = useCallback(
(emoji: string) => {
setSelectedEmoji(emoji);
const titleWithoutEmoji = getTitleWithoutEmoji(template.title || "");
const fullTitle = emoji + " " + titleWithoutEmoji;
onTemplateUpdate({ ...template, title: fullTitle });
setEmojiPopoverOpen(false);
},
[onTemplateUpdate, template],
);
// Simple handlers with local state
const handleChangeTitle = (e: React.ChangeEvent<HTMLInputElement>) => {
const newTitle = e.target.value;
setTitleText(newTitle); // Update local state immediately

const handleChangeDescription = useCallback(
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
onTemplateUpdate({ ...template, description: e.target.value });
},
[onTemplateUpdate, template],
);
const fullTitle = selectedEmoji + " " + newTitle;
onTemplateUpdate({ ...template, title: fullTitle });
};

const handleEmojiSelect = (emoji: string) => {
setSelectedEmoji(emoji);
const fullTitle = emoji + " " + titleText; // Use local state
onTemplateUpdate({ ...template, title: fullTitle });
setEmojiPopoverOpen(false);
};

const handleChangeDescription = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const newDescription = e.target.value;
setDescriptionText(newDescription); // Update local state immediately

onTemplateUpdate({ ...template, description: newDescription });
};

const handleChangeSections = useCallback(
(sections: Template["sections"]) => {
Expand All @@ -145,7 +150,7 @@ export default function TemplateEditor({
<div className="flex flex-col gap-3 border-b pb-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 flex-1">
{/* Emoji Selector */}
{/* Emoji Selector - unchanged */}
<Popover open={emojiPopoverOpen} onOpenChange={setEmojiPopoverOpen}>
<PopoverTrigger asChild>
<Button
Expand Down Expand Up @@ -179,17 +184,15 @@ export default function TemplateEditor({
</PopoverContent>
</Popover>

{/* Title Input */}
<Input
disabled={isReadOnly}
value={getTitleWithoutEmoji(template.title || "")}
value={titleText}
onChange={handleChangeTitle}
className="rounded-none border-0 p-0 !text-lg font-semibold focus:outline-none focus-visible:ring-0 focus-visible:ring-offset-0 flex-1"
placeholder={t`Untitled Template`}
/>
</div>

{/* Menu Button - Show for all templates with different options */}
{isCreator && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
Expand Down Expand Up @@ -228,7 +231,7 @@ export default function TemplateEditor({
</h2>
<Textarea
disabled={isReadOnly}
value={template.description}
value={descriptionText}
onChange={handleChangeDescription}
placeholder={t`Add a system instruction...`}
className="h-20 resize-none focus-visible:ring-0 focus-visible:ring-offset-0"
Expand Down
14 changes: 7 additions & 7 deletions apps/desktop/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ msgstr "Access multiple AI models through OpenRouter with your API key"
#~ msgid "Add a description..."
#~ msgstr "Add a description..."

#: src/components/settings/views/template.tsx:233
#: src/components/settings/views/template.tsx:236
msgid "Add a system instruction..."
msgstr "Add a system instruction..."

Expand Down Expand Up @@ -672,7 +672,7 @@ msgstr "Custom Vocabulary"
#~ msgid "Default (llama-3.2-3b-q4)"
#~ msgstr "Default (llama-3.2-3b-q4)"

#: src/components/settings/views/template.tsx:215
#: src/components/settings/views/template.tsx:218
#: src/components/settings/views/team.tsx:165
#: src/components/left-sidebar/notes-list.tsx:336
msgid "Delete"
Expand Down Expand Up @@ -714,7 +714,7 @@ msgstr "Downloading AI Models"
msgid "Draft follow up"
msgstr "Draft follow up"

#: src/components/settings/views/template.tsx:203
#: src/components/settings/views/template.tsx:206
msgid "Duplicate"
msgstr "Duplicate"

Expand All @@ -730,7 +730,7 @@ msgstr "Email addresses"
msgid "Email separated by commas"
msgstr "Email separated by commas"

#: src/components/settings/views/template.tsx:163
#: src/components/settings/views/template.tsx:168
msgid "Emoji"
msgstr "Emoji"

Expand Down Expand Up @@ -1309,7 +1309,7 @@ msgstr "Search..."
#~ msgid "Searching..."
#~ msgstr "Searching..."

#: src/components/settings/views/template.tsx:240
#: src/components/settings/views/template.tsx:243
msgid "Sections"
msgstr "Sections"

Expand Down Expand Up @@ -1434,7 +1434,7 @@ msgstr "Stop"
msgid "System Audio Access"
msgstr "System Audio Access"

#: src/components/settings/views/template.tsx:227
#: src/components/settings/views/template.tsx:230
msgid "System Instruction"
msgstr "System Instruction"

Expand Down Expand Up @@ -1538,7 +1538,7 @@ msgstr "Type to search..."
msgid "Untitled"
msgstr "Untitled"

#: src/components/settings/views/template.tsx:188
#: src/components/settings/views/template.tsx:192
msgid "Untitled Template"
msgstr "Untitled Template"

Expand Down
14 changes: 7 additions & 7 deletions apps/desktop/src/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ msgstr ""
#~ msgid "Add a description..."
#~ msgstr ""

#: src/components/settings/views/template.tsx:233
#: src/components/settings/views/template.tsx:236
msgid "Add a system instruction..."
msgstr ""

Expand Down Expand Up @@ -672,7 +672,7 @@ msgstr ""
#~ msgid "Default (llama-3.2-3b-q4)"
#~ msgstr ""

#: src/components/settings/views/template.tsx:215
#: src/components/settings/views/template.tsx:218
#: src/components/settings/views/team.tsx:165
#: src/components/left-sidebar/notes-list.tsx:336
msgid "Delete"
Expand Down Expand Up @@ -714,7 +714,7 @@ msgstr ""
msgid "Draft follow up"
msgstr ""

#: src/components/settings/views/template.tsx:203
#: src/components/settings/views/template.tsx:206
msgid "Duplicate"
msgstr ""

Expand All @@ -730,7 +730,7 @@ msgstr ""
msgid "Email separated by commas"
msgstr ""

#: src/components/settings/views/template.tsx:163
#: src/components/settings/views/template.tsx:168
msgid "Emoji"
msgstr ""

Expand Down Expand Up @@ -1309,7 +1309,7 @@ msgstr ""
#~ msgid "Searching..."
#~ msgstr ""

#: src/components/settings/views/template.tsx:240
#: src/components/settings/views/template.tsx:243
msgid "Sections"
msgstr ""

Expand Down Expand Up @@ -1434,7 +1434,7 @@ msgstr ""
msgid "System Audio Access"
msgstr ""

#: src/components/settings/views/template.tsx:227
#: src/components/settings/views/template.tsx:230
msgid "System Instruction"
msgstr ""

Expand Down Expand Up @@ -1538,7 +1538,7 @@ msgstr ""
msgid "Untitled"
msgstr ""

#: src/components/settings/views/template.tsx:188
#: src/components/settings/views/template.tsx:192
msgid "Untitled Template"
msgstr ""

Expand Down
18 changes: 18 additions & 0 deletions apps/desktop/src/routes/app.finder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { z } from "zod";

import { ViewSelector } from "@/components/finder/view-selector";
import { CalendarView, ContactView, FolderView, TableView, TagsView } from "@/components/finder/views";
import { commands as analyticsCommands } from "@hypr/plugin-analytics";
import { commands as dbCommands } from "@hypr/plugin-db";
import { cn } from "@hypr/ui/lib/utils";

Expand Down Expand Up @@ -177,6 +178,23 @@ function FinderView() {
const searchParams = Route.useSearch();

const handleViewChange = (newView: ViewType) => {
if (newView === "tags") {
analyticsCommands.event({
event: "finder_tags_view",
distinct_id: userId,
});
} else if (newView === "contact") {
analyticsCommands.event({
event: "finder_contact_view",
distinct_id: userId,
});
} else if (newView === "table") {
analyticsCommands.event({
event: "finder_table_view",
distinct_id: userId,
});
}

navigate({
search: (prev) => ({
...prev,
Expand Down
3 changes: 2 additions & 1 deletion crates/template/assets/enhance.system.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ The user has provided a custom template that defines the structure and sections
Your response must strictly follow this template's format and section headers.
The sections and their order in your output must exactly match those defined in the template below.
Sections in the template should be the only existing sections in the enhanced note, as markdown 1 headers h1 (#).
Contents of each section should be following the section description that the user provided.
Each section's content must strictly adhere to the section description provided by the user. Extract and organize relevant information from the raw notes and transcript to fulfill each section's requirements.
CRITICAL: Only include information that exists in the source material. If the transcript or raw notes do not contain information relevant to a specific section, explicitly say so. Do not generate, infer, or create content that is not directly supported by the source material.

---Template Structure---
{{ templateInfo }}
Expand Down
Loading