feat(Notes): implement manual ordering for notes, add drag-and-drop functionality, and update related components for reordering
This commit is contained in:
@@ -14,6 +14,7 @@ import { TasksProvider, useTasksContext } from '@/contexts/TasksContext';
|
||||
import { Tag } from '@/lib/types';
|
||||
import { FileText, AlertCircle, ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import { getFolders } from '@/actions/folders';
|
||||
import { reorderNotes } from '@/actions/notes';
|
||||
|
||||
interface NotesPageClientProps {
|
||||
initialNotes: Note[];
|
||||
@@ -115,6 +116,40 @@ function NotesPageContent({
|
||||
[selectedNote, notes]
|
||||
);
|
||||
|
||||
const reloadNotes = useCallback(async () => {
|
||||
try {
|
||||
const updatedNotes = await notesClient.getNotes();
|
||||
setNotes(updatedNotes);
|
||||
} catch (err) {
|
||||
console.error('Error reloading notes:', err);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleReorderNotes = useCallback(
|
||||
async (noteOrders: Array<{ id: string; order: number }>) => {
|
||||
try {
|
||||
// Optimistic update
|
||||
const notesMap = new Map(notes.map((n) => [n.id, n]));
|
||||
const reorderedNotes = noteOrders
|
||||
.map((no) => notesMap.get(no.id))
|
||||
.filter((n): n is Note => n !== undefined);
|
||||
setNotes(reorderedNotes);
|
||||
|
||||
// Server update
|
||||
const result = await reorderNotes(noteOrders);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Erreur lors du réordonnancement des notes');
|
||||
console.error('Error reordering notes:', err);
|
||||
// Reload notes on error
|
||||
reloadNotes();
|
||||
}
|
||||
},
|
||||
[notes, reloadNotes]
|
||||
);
|
||||
|
||||
const getNoteTitle = (content: string): string => {
|
||||
// Extract title from first line, removing markdown headers
|
||||
const firstLine = content.split('\n')[0] || '';
|
||||
@@ -378,6 +413,7 @@ function NotesPageContent({
|
||||
onSelectNote={handleSelectNote}
|
||||
onCreateNote={handleCreateNote}
|
||||
onDeleteNote={handleDeleteNote}
|
||||
onReorderNotes={handleReorderNotes}
|
||||
selectedNoteId={selectedNote?.id}
|
||||
isLoading={false}
|
||||
availableTags={availableTags}
|
||||
|
||||
Reference in New Issue
Block a user