## Bug Fixes ### Note Card Actions - Fix broken size change functionality (missing state declaration) - Implement React 19 useOptimistic for instant UI feedback - Add startTransition for non-blocking updates - Ensure smooth animations without page refresh - All note actions now work: pin, archive, color, size, checklist ### Markdown LaTeX Rendering - Add remark-math and rehype-katex plugins - Support inline equations with dollar sign syntax - Support block equations with double dollar sign syntax - Import KaTeX CSS for proper styling - Equations now render correctly instead of showing raw LaTeX ## Technical Details - Replace undefined currentNote references with optimistic state - Add optimistic updates before server actions for instant feedback - Use router.refresh() in transitions for smart cache invalidation - Install remark-math, rehype-katex, and katex packages ## Testing - Build passes successfully with no TypeScript errors - Dev server hot-reloads changes correctly
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { useDebounce } from './use-debounce';
|
|
import { TagSuggestion } from '@/lib/ai/types';
|
|
|
|
interface UseAutoTaggingProps {
|
|
content: string;
|
|
enabled?: boolean;
|
|
}
|
|
|
|
export function useAutoTagging({ content, enabled = true }: UseAutoTaggingProps) {
|
|
const [suggestions, setSuggestions] = useState<TagSuggestion[]>([]);
|
|
const [isAnalyzing, setIsAnalyzing] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
// Debounce le contenu de 1.5s
|
|
const debouncedContent = useDebounce(content, 1500);
|
|
|
|
useEffect(() => {
|
|
if (!enabled || !debouncedContent || debouncedContent.length < 10) {
|
|
setSuggestions([]);
|
|
return;
|
|
}
|
|
|
|
const analyzeContent = async () => {
|
|
setIsAnalyzing(true);
|
|
setError(null);
|
|
|
|
try {
|
|
const response = await fetch('/api/ai/tags', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ content: debouncedContent }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Erreur lors de l\'analyse');
|
|
}
|
|
|
|
const data = await response.json();
|
|
setSuggestions(data.tags || []);
|
|
} catch (err) {
|
|
console.error('❌ Auto-tagging error:', err);
|
|
setError('Impossible de générer des suggestions');
|
|
} finally {
|
|
setIsAnalyzing(false);
|
|
}
|
|
};
|
|
|
|
analyzeContent();
|
|
}, [debouncedContent, enabled]);
|
|
|
|
return {
|
|
suggestions,
|
|
isAnalyzing,
|
|
error,
|
|
clearSuggestions: () => setSuggestions([]),
|
|
};
|
|
}
|