fix: extract images from rich text HTML to enable image description quick action
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 34s

This commit is contained in:
2026-05-02 23:41:46 +02:00
parent 01cf5ccad7
commit d0387cd9a0
4 changed files with 42 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
'use client'
import { useState, useRef, useEffect } from 'react'
import { useState, useRef, useEffect, useMemo } from 'react'
import { Note, CheckItem, NOTE_COLORS, NoteColor, LinkMetadata, NoteType } from '@/lib/types'
import {
Dialog,
@@ -28,7 +28,7 @@ import { RichTextEditor } from '@/components/rich-text-editor'
import { X, Plus, Palette, Image as ImageIcon, Bell, Eye, Link as LinkIcon, Sparkles, Maximize2, Copy, Wand2, LogOut } from 'lucide-react'
import { updateNote, createNote, cleanupOrphanedImages, leaveSharedNote } from '@/app/actions/notes'
import { fetchLinkMetadata } from '@/app/actions/scrape'
import { cn } from '@/lib/utils'
import { cn, extractImagesFromHTML } from '@/lib/utils'
import { toast } from 'sonner'
import { MarkdownContent } from './markdown-content'
import { LabelManager } from './label-manager'
@@ -278,12 +278,21 @@ export function NoteEditor({ note, readOnly = false, onClose }: NoteEditorProps)
const handleGenerateTitles = async () => {
// Combine content and link metadata for AI
const fullContent = [
const fullContentForAI = [
content,
...links.map(l => `${l.title || ''} ${l.description || ''}`)
].join(' ').trim()
]
.join(' ')
.trim()
const wordCount = fullContent.split(/\s+/).filter(word => word.length > 0).length
const allImages = useMemo(() => {
const extracted = noteType === 'richtext' ? extractImagesFromHTML(content) : [];
return Array.from(new Set([...images, ...extracted]));
}, [images, content, noteType]);
const wordCount = fullContentForAI.split(/\s+/).filter(word => word.length > 0).length
if (wordCount < 10) {
toast.error(t('ai.titleGenerationMinWords', { count: wordCount }))
@@ -1006,7 +1015,7 @@ export function NoteEditor({ note, readOnly = false, onClose }: NoteEditorProps)
onClose={() => setAiOpen(false)}
noteTitle={title}
noteContent={content}
noteImages={images}
noteImages={allImages}
onApplyToNote={(newContent) => {
setPreviousContentForCopilot(content)
setContent(newContent)
@@ -1148,4 +1157,4 @@ export function NoteEditor({ note, readOnly = false, onClose }: NoteEditorProps)
)}
</Dialog>
)
}
}