YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(app): drag-and-drop images into meeting notes, remove image button (#3873)
Louis Beaumont8aa3c841a73d
diff --git a/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx b/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsxindex c909e7415..ddc93d24e 100644--- a/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx+++ b/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx@@ -26,7 +26,10 @@ export interface NoteEditorProps {}export interface NoteEditorHandle {- insertImages: (dataUrls: string[]) => void;+ insertImages: (+ dataUrls: string[],+ at?: { clientX: number; clientY: number },+ ) => void;}const PROSE_CLASSES = [@@ -85,22 +88,34 @@ function NoteEditor(onChangeRef.current = onChange;}, [onChange]);- const insertImages = useCallback((dataUrls: string[]) => {- const editor = editorRef.current;- const images = dataUrls.filter((src) => src.startsWith("data:image/"));- if (!editor || images.length === 0) return;+ const insertImages = useCallback(+ (dataUrls: string[], at?: { clientX: number; clientY: number }) => {+ const editor = editorRef.current;+ const images = dataUrls.filter((src) => src.startsWith("data:image/"));+ if (!editor || images.length === 0) return;- editor- .chain()- .focus()- .insertContent(- images.flatMap((src) => [- { type: "image", attrs: { src, alt: "meeting note image" } },- { type: "paragraph" },- ]),- )- .run();- }, []);+ const content = images.flatMap((src) => [+ { type: "image", attrs: { src, alt: "meeting note image" } },+ { type: "paragraph" },+ ]);++ // When the caller passes drop coordinates, drop the image where the user+ // released it instead of at the stale caret. posAtCoords returns null for+ // points outside the document (e.g. padding below the text), in which case+ // we fall back to the caret.+ const pos =+ at != null+ ? editor.view.posAtCoords({ left: at.clientX, top: at.clientY })?.pos+ : undefined;++ if (pos != null) {+ editor.chain().focus().insertContentAt(pos, content).run();+ } else {+ editor.chain().focus().insertContent(content).run();+ }+ },+ [],+ );const insertImageFiles = useCallback(async (files: File[]) => {diff --git a/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx b/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsxindex ba6564ba1..1c25e7d95 100644--- a/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx+++ b/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx@@ -15,7 +15,6 @@ import {ExternalLink,FileText,Info,- ImageIcon,Languages,Loader2,Mic2,@@ -31,8 +30,9 @@ import {} from "lucide-react";import { commands } from "@/lib/utils/tauri";import { listen } from "@tauri-apps/api/event";+import { getCurrentWebview } from "@tauri-apps/api/webview";import { open as openExternal } from "@tauri-apps/plugin-shell";-import { save as saveDialog, open as openFileDialog } from "@tauri-apps/plugin-dialog";+import { save as saveDialog } from "@tauri-apps/plugin-dialog";import { readFile } from "@tauri-apps/plugin-fs";import posthog from "posthog-js";import { Button } from "@/components/ui/button";@@ -81,6 +81,7 @@ import { ReplayStrip } from "./replay-strip";import { NoteEditor, type NoteEditorHandle } from "./note-editor";import {imageBytesToDataUrl,+ imageExtensionFromName,NOTE_IMAGE_EXTENSIONS,resizeImageDataUrl,} from "./image-utils";@@ -168,6 +169,102 @@ export function NoteView({const [dismissedJoinUrl, setDismissedJoinUrl] = useState<string | null>(null);const { settings, updateSettings } = useSettings();const noteEditorRef = useRef<NoteEditorHandle>(null);+ const rootRef = useRef<HTMLDivElement>(null);+ const [isDraggingImage, setIsDraggingImage] = useState(false);++ // Drag-and-drop images straight into the note. Tauri delivers OS file drops+ // at the webview level (they never surface as DOM drop events), and the event+ // is window-global, so we hit-test the drop position against this note's own+ // box before reacting. Without that, an image dropped on the sidebar (or one+ // caught by another always-mounted webview drop listener such as the chat)+ // would still land in the note. We show the overlay only while an image drag+ // is over the note, then read the files, resize them, and insert them at the+ // drop point.+ useEffect(() => {+ // Tauri reports drag positions in physical pixels; getBoundingClientRect is+ // in CSS pixels, so convert before comparing.+ const toClient = (pos: { x: number; y: number }) => {+ const dpr = window.devicePixelRatio || 1;+ return { x: pos.x / dpr, y: pos.y / dpr };+ };+ const pointOverNote = (pos: { x: number; y: number }) => {+ const el = rootRef.current;+ if (!el || el.offsetParent === null) return false; // unmounted or hidden+ const { x, y } = toClient(pos);+ const r = el.getBoundingClientRect();+ return x >= r.left && x <= r.right && y >= r.top && y <= r.bottom;+ };+ const hasImagePath = (paths: string[]) =>+ paths.some((p) =>+ NOTE_IMAGE_EXTENSIONS.includes(imageExtensionFromName(p)),+ );++ const insertDroppedImages = async (+ paths: string[],+ pos: { x: number; y: number },+ ) => {+ const imagePaths = paths.filter((path) =>+ NOTE_IMAGE_EXTENSIONS.includes(imageExtensionFromName(path)),+ );+ if (paths.length === 0) return;+ if (imagePaths.length === 0) {+ toast({+ title: "couldn't insert image",+ description: "drop a png, jpg, gif, webp, bmp, or svg file.",+ variant: "destructive",+ });+ return;+ }+ try {+ const images: string[] = [];+ for (const path of imagePaths) {+ const raw = imageBytesToDataUrl(path, await readFile(path));+ if (raw) images.push(await resizeImageDataUrl(raw));+ }+ if (images.length === 0) return;+ const { x, y } = toClient(pos);+ noteEditorRef.current?.insertImages(images, { clientX: x, clientY: y });+ posthog.capture("meeting_note_images_inserted", {+ meeting_id: meeting.id,+ count: images.length,+ source: "drag_drop",+ });+ } catch (err) {+ console.error("failed to insert dropped meeting note image", err);+ toast({+ title: "couldn't insert image",+ description: String(err),+ variant: "destructive",+ });+ }+ };++ // `enter` carries the dragged paths so we can tell whether it's an image;+ // `over` does not, so we remember what `enter` classified. Default to true+ // when a platform omits the paths so we never suppress a real image drag.+ let dragHasImage = true;+ const webview = getCurrentWebview();+ const unlisten = webview.onDragDropEvent((event) => {+ const payload = event.payload;+ if (payload.type === "enter") {+ dragHasImage =+ payload.paths.length === 0 ? true : hasImagePath(payload.paths);+ }+ if (payload.type === "enter" || payload.type === "over") {+ setIsDraggingImage(dragHasImage && pointOverNote(payload.position));+ } else if (payload.type === "leave") {+ setIsDraggingImage(false);+ } else if (payload.type === "drop") {+ setIsDraggingImage(false);+ if (!pointOverNote(payload.position)) return;+ void insertDroppedImages(payload.paths ?? [], payload.position);+ }+ });++ return () => {+ void unlisten.then((fn) => fn());+ };+ }, [meeting.id, toast]);const lastSavedRef = useRef({title: meeting.title ?? "",@@ -500,45 +597,6 @@ export function NoteView({}};- const handleInsertImages = async () => {- try {- const selected = await openFileDialog({- multiple: true,- filters: [{ name: "Images", extensions: NOTE_IMAGE_EXTENSIONS }],- });- if (!selected) return;-- const paths = Array.isArray(selected) ? selected : [selected];- const images: string[] = [];- for (const path of paths) {- const raw = imageBytesToDataUrl(path, await readFile(path));- if (raw) images.push(await resizeImageDataUrl(raw));- }-- if (images.length === 0) {- toast({- title: "couldn't insert image",- description: "choose a png, jpg, gif, webp, bmp, or svg file.",- variant: "destructive",- });- return;- }-- noteEditorRef.current?.insertImages(images);- posthog.capture("meeting_note_images_inserted", {- meeting_id: meeting.id,- count: images.length,- });- } catch (err) {- console.error("failed to insert meeting note image", err);- toast({- title: "couldn't insert image",- description: String(err),- variant: "destructive",- });- }- };-const handleRetranscribe = async () => {if (retranscribing) return;if (!meeting.meeting_end) {@@ -798,7 +856,16 @@ export function NoteView({};return (- <div className="flex h-full flex-col bg-background">+ <div ref={rootRef} className="relative flex h-full flex-col bg-background">+ {isDraggingImage && (+ <div className="pointer-events-none absolute inset-0 z-50 flex items-center justify-center bg-background/60">+ <div className="border border-foreground bg-foreground px-12 py-10 text-background">+ <span className="text-sm font-medium tracking-tight">+ drop image to add to note+ </span>+ </div>+ </div>+ )}{/* The note scrolls in `main`; the footer is a non-overlapping dock belowit. Previously the footer was `sticky bottom-0` and floated over thebottom of a full-height scroll area, so its opaque bar (control row +@@ -834,16 +901,6 @@ export function NoteView({<Copy className="h-3.5 w-3.5" />)}</Button>- <Button- variant="ghost"- size="sm"- onClick={() => void handleInsertImages()}- title="insert image"- aria-label="insert image"- className="h-8 w-8 rounded-none p-0"- >- <ImageIcon className="h-3.5 w-3.5" />- </Button>{!isLive && (<><Buttondiff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex 2e606ea6a..ee07f8081 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -2860,6 +2860,11 @@ export function StandaloneChat({const [isUserScrolledUp, setIsUserScrolledUp] = useState(false);const inputRef = useRef<HTMLTextAreaElement>(null);const dropdownRef = useRef<HTMLDivElement>(null);+ // Root of the chat surface. The webview drag-drop event is window-global and+ // this chat is kept mounted-but-hidden (display:none) on non-chat sections,+ // so we use this ref's visibility to ignore drops meant for another view+ // (e.g. a meeting note) that would otherwise also stage into the composer.+ const dropRootRef = useRef<HTMLDivElement>(null);const [scheduleDialogMessage, setScheduleDialogMessage] = useState<{ prompt: string; response: string } | null>(null);const [prefillContext, setPrefillContext] = useState<string | null>(null);@@ -3367,6 +3372,13 @@ export function StandaloneChat({const webview = getCurrentWebview();const unlisten = webview.onDragDropEvent((event) => {+ // The drag-drop event is window-global. Only react when this chat is the+ // visible surface; when it's the hidden home layer (display:none on other+ // sections) offsetParent is null, so a drop meant for another view is not+ // also staged here.+ if (!dropRootRef.current || dropRootRef.current.offsetParent === null) {+ return;+ }if (event.payload.type === "enter" || event.payload.type === "over") {setIsDragging(true);} else if (event.payload.type === "drop") {@@ -7988,7 +8000,7 @@ export function StandaloneChat({);return (- <div className={cn("flex flex-col bg-background", className ?? "h-screen")} data-testid="section-home">+ <div ref={dropRootRef} className={cn("flex flex-col bg-background", className ?? "h-screen")} data-testid="section-home">{/* Header - draggable only in standalone mode */}{/* Add left padding on macOS to avoid traffic light overlap (standalone only) */}<divdiff --git a/docs/mockups/note-drag-drop-images.png b/docs/mockups/note-drag-drop-images.pngnew file mode 100644index 000000000..d9663f349Binary files /dev/null and b/docs/mockups/note-drag-drop-images.png differ