feat: rename keep-notes to memento-note, migrate to PostgreSQL, fix MCP bugs

- 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>
This commit is contained in:
Sepehr Ramezani
2026-04-20 20:58:04 +02:00
parent e2ddfa53d4
commit aa6a214f37
3548 changed files with 440 additions and 516800 deletions

View File

@@ -0,0 +1,62 @@
import { useState, useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import { useSession } from 'next-auth/react'
/**
* Hook to check if auto label suggestions should be shown for the current notebook
* Triggers when notebook has 15+ notes (IA4)
*/
export function useAutoLabelSuggestion() {
const { data: session } = useSession()
const searchParams = useSearchParams()
const [shouldSuggest, setShouldSuggest] = useState(false)
const [notebookId, setNotebookId] = useState<string | null>(searchParams.get('notebook'))
const [hasChecked, setHasChecked] = useState(false)
useEffect(() => {
const currentNotebookId = searchParams.get('notebook')
// Reset when notebook changes
if (currentNotebookId !== notebookId) {
setNotebookId(currentNotebookId)
setHasChecked(false)
setShouldSuggest(false)
// Check if we should suggest labels for this notebook
if (currentNotebookId && session?.user?.id) {
checkNotebookForSuggestions(currentNotebookId)
}
}
}, [searchParams, notebookId, session])
const checkNotebookForSuggestions = async (nbId: string) => {
try {
// Check if notebook has 15+ notes
const response = await fetch('/api/ai/auto-labels', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ notebookId: nbId }),
})
const data = await response.json()
// Show suggestions if available
if (data.success && data.data) {
setShouldSuggest(true)
}
setHasChecked(true)
} catch (error) {
console.error('Failed to check for label suggestions:', error)
setHasChecked(true)
}
}
return {
shouldSuggest,
notebookId,
hasChecked,
dismiss: () => setShouldSuggest(false),
}
}

View File

@@ -0,0 +1,94 @@
import { useState, useEffect, useRef } from 'react';
import { useDebounce } from './use-debounce';
import { TagSuggestion } from '@/lib/ai/types';
interface UseAutoTaggingProps {
content: string;
notebookId?: string | null;
enabled?: boolean;
}
export function useAutoTagging({ content, notebookId, 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);
// Track previous notebookId to detect when note is moved to a notebook
const previousNotebookId = useRef<string | null | undefined>(notebookId);
const analyzeContent = async (contentToAnalyze: string) => {
// CRITICAL: Don't suggest labels in "Notes générales" (notebookId is null)
// Labels should ONLY appear within notebooks, not in the general notes section
if (!notebookId) {
setSuggestions([]);
return;
}
if (!contentToAnalyze || contentToAnalyze.length < 10) {
setSuggestions([]);
return;
}
setIsAnalyzing(true);
setError(null);
try {
const response = await fetch('/api/ai/tags', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
content: contentToAnalyze,
notebookId: notebookId || undefined,
language: document.documentElement.lang || 'en',
}),
});
if (!response.ok) {
throw new Error('Erreur lors de l\'analyse');
}
const data = await response.json();
setSuggestions(data.tags || []);
} catch (err) {
setError('Impossible de générer des suggestions');
} finally {
setIsAnalyzing(false);
}
};
// Trigger on content change
useEffect(() => {
if (!enabled) {
setSuggestions([]);
return;
}
analyzeContent(debouncedContent);
}, [debouncedContent, enabled]);
// CRITICAL: Also trigger when notebookId changes from null/undefined to a value (note moved to notebook)
useEffect(() => {
if (!enabled) return;
const prev = previousNotebookId.current;
previousNotebookId.current = notebookId;
// Detect when note is moved FROM "Notes générales" (null) TO a notebook
const wasMovedToNotebook = (prev === null || prev === undefined) && notebookId;
if (wasMovedToNotebook && content && content.length >= 10) {
// Use current content immediately (no debounce) when moving to notebook
analyzeContent(content);
}
}, [notebookId, content, enabled]);
return {
suggestions,
isAnalyzing,
error,
clearSuggestions: () => setSuggestions([]),
};
}

View File

@@ -0,0 +1,44 @@
'use client'
import { useState, useEffect } from 'react'
import { getNoteById } from '@/app/actions/notes'
import { Note } from '@/lib/types'
export function useConnectionsCompare(noteIds: string[] | null) {
const [notes, setNotes] = useState<Note[]>([])
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
// Early return if no noteIds or empty array
if (!noteIds || noteIds.length === 0) {
setNotes([])
return
}
const fetchNotes = async () => {
setIsLoading(true)
setError(null)
try {
const fetchedNotes = await Promise.all(
noteIds.map(id => getNoteById(id))
)
// Filter out null/undefined notes
const validNotes = fetchedNotes.filter((note): note is Note => note !== null && note !== undefined)
setNotes(validNotes)
} catch (err) {
console.error('[useConnectionsCompare] Failed to fetch notes:', err)
setError('Failed to load notes')
} finally {
setIsLoading(false)
}
}
fetchNotes()
}, [noteIds])
return { notes, isLoading, error }
}

View File

@@ -0,0 +1,17 @@
import { useEffect, useState } from 'react';
export function useDebounce<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value);
useEffect(() => {
const timer = setTimeout(() => {
setDebouncedValue(value);
}, delay);
return () => {
clearTimeout(timer);
};
}, [value, delay]);
return debouncedValue;
}

View File

@@ -0,0 +1,36 @@
'use client'
import { useState, useCallback } from 'react'
export type DragState = 'idle' | 'dragging' | 'drag-over'
export function useNoteDrag() {
const [draggedNoteId, setDraggedNoteId] = useState<string | null>(null)
const [dragOverNotebookId, setDragOverNotebookId] = useState<string | null>(null)
const startDrag = useCallback((noteId: string) => {
setDraggedNoteId(noteId)
}, [])
const endDrag = useCallback(() => {
setDraggedNoteId(null)
setDragOverNotebookId(null)
}, [])
const dragOver = useCallback((notebookId: string | null) => {
setDragOverNotebookId(notebookId)
}, [])
const isDragging = draggedNoteId !== null
const isDragOver = dragOverNotebookId !== null
return {
draggedNoteId,
dragOverNotebookId,
startDrag,
endDrag,
dragOver,
isDragging,
isDragOver,
}
}

View File

@@ -0,0 +1,44 @@
'use client';
import { useState, useEffect } from 'react';
import { Note } from '@/lib/types';
import { toast } from 'sonner';
export function useReminderCheck(notes: Note[]) {
const [notifiedReminders, setNotifiedReminders] = useState<Set<string>>(new Set());
useEffect(() => {
const checkReminders = () => {
const now = new Date();
const dueReminders: string[] = [];
// First pass: collect which reminders are due
notes.forEach(note => {
if (!note.reminder) return;
const reminderDate = new Date(note.reminder);
if (reminderDate <= now && !notifiedReminders.has(note.id)) {
dueReminders.push(note.id);
toast.info("🔔 Reminder: " + (note.title || "Untitled Note"));
}
});
// Second pass: update state only once with all due reminders
if (dueReminders.length > 0) {
setNotifiedReminders(prev => {
const newSet = new Set(prev);
dueReminders.forEach(id => newSet.add(id));
return newSet;
});
}
};
// Check immediately
checkReminders();
// Then check every 30 seconds
const interval = setInterval(checkReminders, 30000);
return () => clearInterval(interval);
}, [notes]);
}

View File

@@ -0,0 +1,33 @@
'use client';
import { useEffect, useRef } from 'react';
export function useResizeObserver(callback: (entry: ResizeObserverEntry) => void) {
const ref = useRef<HTMLElement>(null);
const frameId = useRef<number>(0);
useEffect(() => {
const element = ref.current;
if (!element) return;
const observer = new ResizeObserver((entries) => {
// Cancel previous frame to avoid stacking updates
if (frameId.current) cancelAnimationFrame(frameId.current);
frameId.current = requestAnimationFrame(() => {
for (const entry of entries) {
callback(entry);
}
});
});
observer.observe(element);
return () => {
observer.disconnect();
if (frameId.current) cancelAnimationFrame(frameId.current);
};
}, [callback]);
return ref;
}

View File

@@ -0,0 +1,74 @@
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([])
}
}

View File

@@ -0,0 +1,115 @@
import { useState, useCallback, useRef } from 'react'
export interface UndoRedoState<T> {
past: T[]
present: T
future: T[]
}
interface UseUndoRedoReturn<T> {
state: T
setState: (newState: T | ((prev: T) => T)) => void
undo: () => void
redo: () => void
canUndo: boolean
canRedo: boolean
clear: () => void
}
const MAX_HISTORY_SIZE = 50
export function useUndoRedo<T>(initialState: T): UseUndoRedoReturn<T> {
const [history, setHistory] = useState<UndoRedoState<T>>({
past: [],
present: initialState,
future: [],
})
// Track if we're in an undo/redo operation to prevent adding to history
const isUndoRedoAction = useRef(false)
const setState = useCallback((newState: T | ((prev: T) => T)) => {
// Skip if this is an undo/redo action
if (isUndoRedoAction.current) {
isUndoRedoAction.current = false
return
}
setHistory((currentHistory) => {
const resolvedNewState =
typeof newState === 'function'
? (newState as (prev: T) => T)(currentHistory.present)
: newState
// Don't add to history if state hasn't changed
if (JSON.stringify(resolvedNewState) === JSON.stringify(currentHistory.present)) {
return currentHistory
}
const newPast = [...currentHistory.past, currentHistory.present]
// Limit history size
if (newPast.length > MAX_HISTORY_SIZE) {
newPast.shift()
}
return {
past: newPast,
present: resolvedNewState,
future: [], // Clear future on new action
}
})
}, [])
const undo = useCallback(() => {
setHistory((currentHistory) => {
if (currentHistory.past.length === 0) return currentHistory
const previous = currentHistory.past[currentHistory.past.length - 1]
const newPast = currentHistory.past.slice(0, currentHistory.past.length - 1)
isUndoRedoAction.current = true
return {
past: newPast,
present: previous,
future: [currentHistory.present, ...currentHistory.future],
}
})
}, [])
const redo = useCallback(() => {
setHistory((currentHistory) => {
if (currentHistory.future.length === 0) return currentHistory
const next = currentHistory.future[0]
const newFuture = currentHistory.future.slice(1)
isUndoRedoAction.current = true
return {
past: [...currentHistory.past, currentHistory.present],
present: next,
future: newFuture,
}
})
}, [])
const clear = useCallback(() => {
setHistory({
past: [],
present: initialState,
future: [],
})
}, [initialState])
return {
state: history.present,
setState,
undo,
redo,
canUndo: history.past.length > 0,
canRedo: history.future.length > 0,
clear,
}
}