11import { v4 as uuid4 } from 'uuid'
22
33export default {
4- addNote ( state , pageId ) {
4+ addNote ( state , { pageId, author } ) {
55 const noteId = uuid4 ( )
66 state . newNotes . push ( noteId )
77 state . notes [ pageId ] . push ( {
@@ -10,7 +10,7 @@ export default {
1010 position : state . notes [ pageId ] . length ,
1111 content : null ,
1212 styles : { someV : 'someV' } ,
13- author : 'a' ,
13+ author,
1414 newNote : true
1515 } )
1616 } ,
@@ -23,29 +23,25 @@ export default {
2323 clearChangedNotes ( state ) {
2424 state . changedNotes = [ ]
2525 } ,
26+ removeFromChangedNotes ( state , ...notesIds ) {
27+ notesIds . forEach ( noteId => {
28+ state . changedNotes . splice ( state . changedNotes . indexOf ( noteId ) , 1 )
29+ } )
30+ } ,
2631 setCurrentNotes ( state , pageId ) {
2732 state . currentNotes = state . notes [ pageId ] || [ ]
2833 } ,
29- editNote (
30- state ,
31- { page, noteId, styles, author, content, position, newNote, preventApiReq }
32- ) {
34+ editNote ( state , { page, noteId, author, updated } ) {
35+ console . log ( page , noteId , author , updated , 'editNote' )
3336 if ( state . removedNotes . includes ( noteId ) ) {
3437 return
3538 }
3639
3740 const foundNote = state . notes [ page ] . find ( ( note ) => note . noteId === noteId )
38- state . notes [ page ] [ state . notes [ page ] . indexOf ( foundNote ) ] = {
39- noteId,
40- page,
41- styles,
42- author,
43- content,
44- position,
45- newNote
46- }
41+ const foundNoteIndex = state . notes [ page ] . indexOf ( foundNote )
42+ state . notes [ page ] [ foundNoteIndex ] = { ...foundNote , ...updated , page, noteId, author }
4743
48- if ( ! state . changedNotes . includes ( noteId ) && ! preventApiReq ) {
44+ if ( ! state . changedNotes . includes ( noteId ) ) {
4945 state . changedNotes . push ( noteId )
5046 }
5147 } ,
0 commit comments