@@ -357,6 +357,49 @@ function data (state = defaultDataMap(), action) {
357357 } )
358358 }
359359 return state
360+ case 'ADD_STORAGE' :
361+ state = Object . assign ( { } , state )
362+ state . storageMap = new Map ( state . storageMap )
363+ state . storageMap . set ( action . storage . key , action . storage )
364+
365+ state . noteMap = new Map ( state . noteMap )
366+ state . storageNoteMap = new Map ( state . storageNoteMap )
367+ state . storageNoteMap . set ( action . storage . key , new Set ( ) )
368+ state . folderNoteMap = new Map ( state . folderNoteMap )
369+ state . tagNoteMap = new Map ( state . tagNoteMap )
370+ action . notes . forEach ( ( note ) => {
371+ let uniqueKey = note . storage + '-' + note . key
372+ let folderKey = note . storage + '-' + note . folder
373+ state . noteMap . set ( uniqueKey , note )
374+
375+ if ( note . isStarred ) {
376+ state . starredSet . add ( uniqueKey )
377+ }
378+
379+ let storageNoteList = state . storageNoteMap . get ( note . storage )
380+ if ( storageNoteList == null ) {
381+ storageNoteList = new Set ( storageNoteList )
382+ state . storageNoteMap . set ( note . storage , storageNoteList )
383+ }
384+ storageNoteList . add ( uniqueKey )
385+
386+ let folderNoteSet = state . folderNoteMap . get ( folderKey )
387+ if ( folderNoteSet == null ) {
388+ folderNoteSet = new Set ( folderNoteSet )
389+ state . folderNoteMap . set ( folderKey , folderNoteSet )
390+ }
391+ folderNoteSet . add ( uniqueKey )
392+
393+ note . tags . forEach ( ( tag ) => {
394+ let tagNoteSet = state . tagNoteMap . get ( tag )
395+ if ( tagNoteSet == null ) {
396+ tagNoteSet = new Set ( tagNoteSet )
397+ state . tagNoteMap . set ( tag , tagNoteSet )
398+ }
399+ tagNoteSet . add ( uniqueKey )
400+ } )
401+ } )
402+ return state
360403 case 'REMOVE_STORAGE' :
361404 state = Object . assign ( { } , state )
362405 let storage = state . storageMap . get ( action . storageKey )
0 commit comments