mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
0edc66da49
Relates to #5389
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
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';
|
|
|
|
const useMoveNote = (notesParentType: string, noteSortOrder: string, selectedNoteIds: string[], selectedFolderId: string, uncompletedTodosOnTop: boolean, showCompletedTodos: boolean, notes: NoteEntity[]) => {
|
|
const moveNote = useCallback((direction: number, inc: number) => {
|
|
if (!canManuallySortNotes(notesParentType, noteSortOrder)) return;
|
|
|
|
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);
|
|
}, [selectedFolderId, noteSortOrder, notes, notesParentType, selectedNoteIds, uncompletedTodosOnTop, showCompletedTodos]);
|
|
|
|
return moveNote;
|
|
};
|
|
|
|
export default useMoveNote;
|