- Rename directory keep-notes -> memento-note with all code references - Prisma: SQLite -> PostgreSQL (both app and MCP server schemas) - Sync MCP schema with main app (add missing fields, relations, indexes) - Delete 17 SQLite migrations (clean slate for PostgreSQL) - Remove SQLite dependencies (@libsql/client, better-sqlite3, etc.) - Fix MCP server: hardcoded Windows DB paths -> DATABASE_URL env var - Fix MCP server: .dockerignore excluded index-sse.js (SSE mode broken) - MCP Dockerfile: node:20 -> node:22 - Docker Compose: add postgres service, remove SQLite volume - Generate favicon.ico, icon-192.png, icon-512.png, apple-icon.png - Update layout.tsx icons and manifest.json for PNG icons - Update all .env files for PostgreSQL - Rewrite README.md with updated sections - Remove mcp-server/node_modules and prisma/client-generated from git tracking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
import { useDebounce } from './use-debounce'
|
|
|
|
export interface TitleSuggestion {
|
|
title: string
|
|
confidence: number
|
|
reasoning?: string
|
|
}
|
|
|
|
interface UseTitleSuggestionsProps {
|
|
content: string
|
|
enabled?: boolean
|
|
}
|
|
|
|
export function useTitleSuggestions({ content, enabled = true }: UseTitleSuggestionsProps) {
|
|
const [suggestions, setSuggestions] = useState<TitleSuggestion[]>([])
|
|
const [isAnalyzing, setIsAnalyzing] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
// Debounce le contenu de 2s pour éviter trop d'appels
|
|
const debouncedContent = useDebounce(content, 2000)
|
|
|
|
useEffect(() => {
|
|
if (!enabled || !debouncedContent) {
|
|
setSuggestions([])
|
|
return
|
|
}
|
|
|
|
const wordCount = debouncedContent.split(/\s+/).length
|
|
|
|
// Il faut au moins 10 mots
|
|
if (wordCount < 10) {
|
|
setSuggestions([])
|
|
return
|
|
}
|
|
|
|
|
|
const generateTitles = async () => {
|
|
setIsAnalyzing(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const response = await fetch('/api/ai/title-suggestions', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ content: debouncedContent }),
|
|
})
|
|
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json()
|
|
throw new Error(errorData.error || 'Erreur lors de la génération des titres')
|
|
}
|
|
|
|
const data = await response.json()
|
|
setSuggestions(data.suggestions || [])
|
|
} catch (err) {
|
|
console.error('❌ Title suggestions error:', err)
|
|
setError('Impossible de générer des suggestions de titres')
|
|
} finally {
|
|
setIsAnalyzing(false)
|
|
}
|
|
}
|
|
|
|
generateTitles()
|
|
}, [debouncedContent, enabled])
|
|
|
|
return {
|
|
suggestions,
|
|
isAnalyzing,
|
|
error,
|
|
clearSuggestions: () => setSuggestions([])
|
|
}
|
|
}
|