2023-08-21 17:01:20 +02:00
|
|
|
import BaseModel from '@joplin/lib/BaseModel';
|
|
|
|
import Note from '@joplin/lib/models/Note';
|
|
|
|
import { NoteEntity } from '@joplin/lib/services/database/types';
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
import canManuallySortNotes from './canManuallySortNotes';
|
|
|
|
|
2024-03-02 16:25:27 +02:00
|
|
|
const useMoveNote = (notesParentType: string, noteSortOrder: string, selectedNoteIds: string[], selectedFolderId: string, uncompletedTodosOnTop: boolean, showCompletedTodos: boolean, notes: NoteEntity[], selectedFolderInTrash: boolean) => {
|
2023-08-21 17:01:20 +02:00
|
|
|
const moveNote = useCallback((direction: number, inc: number) => {
|
2024-03-02 16:25:27 +02:00
|
|
|
if (!canManuallySortNotes(notesParentType, noteSortOrder, selectedFolderInTrash)) return;
|
2023-08-21 17:01:20 +02:00
|
|
|
|
|
|
|
const noteId = selectedNoteIds[0];
|
|
|
|
let targetNoteIndex = BaseModel.modelIndexById(notes, noteId);
|
|
|
|
if ((direction === 1)) {
|
|
|
|
targetNoteIndex += inc + 1;
|
|
|
|
}
|
|
|
|
if ((direction === -1)) {
|
|
|
|
targetNoteIndex -= inc;
|
|
|
|
}
|
|
|
|
void Note.insertNotesAt(selectedFolderId, selectedNoteIds, targetNoteIndex, uncompletedTodosOnTop, showCompletedTodos);
|
2024-03-02 16:25:27 +02:00
|
|
|
}, [selectedFolderId, noteSortOrder, notes, notesParentType, selectedNoteIds, uncompletedTodosOnTop, showCompletedTodos, selectedFolderInTrash]);
|
2023-08-21 17:01:20 +02:00
|
|
|
|
|
|
|
return moveNote;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useMoveNote;
|