@@ -16,6 +16,7 @@ import useDataLoadingController from '../Hooks/useDataLoadingController.hook'
1616import useFetchNotes from '../Hooks/useFetchNotes.hook'
1717import useEditNoteId from '../Hooks/useEditNoteId.hook'
1818import useNotesArr from '../Hooks/useNotesArr.hook'
19+ import { calcOrder , fixOrders } from '../Shared/order'
1920
2021/**
2122 * Страница с заметками
@@ -95,7 +96,13 @@ function NotesPage() {
9596 */
9697 function addNote ( noteData = { } ) {
9798 const newId = String ( auth . email ) + String ( Date . now ( ) ) + String ( Math . random ( ) )
98- const newNote = new Note ( { id : newId , name : noteData . name , color : noteData . color , text : noteData . text } )
99+ const newNote = new Note ( {
100+ id : newId ,
101+ name : noteData . name ,
102+ color : noteData . color ,
103+ text : noteData . text ,
104+ order : calcOrder ( notesArr )
105+ } )
99106 //console.log(newId, newNote.id);
100107 const newIndex = ( notesArr != null ) ? notesArr . length : 0
101108 setNotesArr (
@@ -133,6 +140,22 @@ function NotesPage() {
133140 loadDataToServer ( notesArr [ index ] , "set" )
134141 }
135142
143+ /**
144+ * Изменение порядка заметки
145+ * @param {number } index
146+ * @param {boolean } orderOperationFlag
147+ */
148+ function editNoteOrder ( index , orderOperationFlag ) {
149+ if ( notesArr [ index ] ) {
150+ notesArr [ index ] . order += orderOperationFlag ? 2 : - 2
151+ let fixedArr = fixOrders ( notesArr )
152+ setNotesArr ( fixedArr )
153+ fixedArr . forEach ( ( note ) => {
154+ loadDataToServer ( note , "set" )
155+ } )
156+ }
157+ }
158+
136159 /**функция получения карточки по id */
137160 function getNoteByIndex ( index ) {
138161 return index !== null ? notesArr [ index ] : null
@@ -159,7 +182,7 @@ function NotesPage() {
159182 /**рендер */
160183 return (
161184 /**Здесь отрисовываются меню добавления и редактирования заметок и сам перечнь заметок в виде динамичной отзывчивой сетки */
162- < NotesContext . Provider value = { { addNote, removeNote, changeNoteColor, editNoteContent, setEditNoteId, unsetEditNoteId, editNoteId, getNoteByIndex } } >
185+ < NotesContext . Provider value = { { addNote, removeNote, changeNoteColor, editNoteContent, editNoteOrder , setEditNoteId, unsetEditNoteId, editNoteId, getNoteByIndex } } >
163186 < div className = "NotesPage" >
164187 < main className = "p-1 pb-3 mb-3" >
165188 { /**Компонент добавления карточки и модальное окно редактирования */ }
0 commit comments