@ -1,6 +1,7 @@
import App from './App.js' ;
import App from './App.js' ;
import nanoid from './nanoid.min.js' ;
import nanoid from './nanoid.min.js' ;
import { load _bin _handler , hash _change _handler } from './handlers/index.js' ;
import { load _bin _handler , hash _change _handler } from './handlers/index.js' ;
import { bin , note } from './models.js' ;
const produce = immer . produce ;
const produce = immer . produce ;
immer . setAutoFreeze ( false ) ; // needed for high-frequency updated values, like onkeyup->note.temp_text; only once 'save' is called will it produce a new immutable state tree
immer . setAutoFreeze ( false ) ; // needed for high-frequency updated values, like onkeyup->note.temp_text; only once 'save' is called will it produce a new immutable state tree
@ -25,7 +26,7 @@ if(bin_id === ''){
const reducer = handleActions ( {
const reducer = handleActions ( {
'new-bin' : ( s , bin ) => { s . bin = bin ; s . notes = [ ] ; } ,
'new-bin' : ( s , bin ) => { s . bin = bin ; s . notes = [ ] ; } ,
'bin-requested' : ( s , bin _id ) => { s . bin = { id : bin _id } ; s . notes = [ ] ; } ,
'bin-requested' : ( s , bin _id ) => { s . bin = { id : bin _id } ; s . notes = [ ] ; } ,
'bin-loaded' : ( s , { bin , _notes } ) => { s . bin = bin ; s . notes= _notes . map ( n => ( { is _editing : false , temp _text : n . text , bin _id : bin . id , note : n } ) ) ; } ,
'bin-loaded' : ( s , { bin , _notes } ) => { s . bin = bin ; s . temp_bin _name = bin . name ; s . notes= _notes . map ( n => ( { is _editing : false , temp _text : n . text , bin _id : bin . id , note : n } ) ) ; } ,
'update-search-term' : ( s , search _term ) => { s . search _term = search _term ; } ,
'update-search-term' : ( s , search _term ) => { s . search _term = search _term ; } ,
'update-search-results' : ( s , _notes ) => { s . notes = _notes . map ( n => ( { is _editing : false , temp _text : '' , bin _id : s . bin . id , note : n } ) ) ; } ,
'update-search-results' : ( s , _notes ) => { s . notes = _notes . map ( n => ( { is _editing : false , temp _text : '' , bin _id : s . bin . id , note : n } ) ) ; } ,
'add-note' : ( s , { id , date } ) => { s . notes . unshift ( { is _editing : true , temp _text : '' , bin _id : s . bin . id , is _focused : true , note : { id : id , text : '' , modified : date } } ) ; } ,
'add-note' : ( s , { id , date } ) => { s . notes . unshift ( { is _editing : true , temp _text : '' , bin _id : s . bin . id , is _focused : true , note : { id : id , text : '' , modified : date } } ) ; } ,
@ -33,14 +34,35 @@ const reducer = handleActions({
'update-note-text' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . note . text = text ; } , // updates underlying note text (i.e. the "model", not the app note_state) "in the background" (e.g. from a server-pushed update), regardless of whether it's being edited; "save" is a separate action, below
'update-note-text' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . note . text = text ; } , // updates underlying note text (i.e. the "model", not the app note_state) "in the background" (e.g. from a server-pushed update), regardless of whether it's being edited; "save" is a separate action, below
'update-note-editing' : ( s , { id , is _editing } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . is _editing = is _editing ; note _s . temp _text = note _s . note . text ; } ,
'update-note-editing' : ( s , { id , is _editing } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . is _editing = is _editing ; note _s . temp _text = note _s . note . text ; } ,
'save-note-edit' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . note . text = text ; note _s . temp _text = text ; note _s . is _editing = false ; } ,
'save-note-edit' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note . id === id ) ; note _s . note . text = text ; note _s . temp _text = text ; note _s . is _editing = false ; } ,
'update-sorting' : ( s , sorting ) => { s . sorting = sorting ; }
'update-sorting' : ( s , sorting ) => { s . sorting = sorting ; } ,
'update-username' : ( s , username ) => { s . login . username = username ; } ,
'update-password' : ( s , password ) => { s . login . password = password ; } ,
'login-requested' : ( s ) => { s . login . showing = false ; } ,
'login-succeeded' : ( s , user , session _id ) => { s . login . showing = false ; s . login . password = '' ; s . login . user = user ; s . login . session _id = session _id ; } ,
'login-failed' : ( s ) => { s . login . showing = true ; s . login . password = '' ; } ,
'update-bin-name-editing' : ( s , is _editing ) => { s . is _editing _bin _name = is _editing ; } ,
'update-bin-name' : ( s , name ) => { s . temp _bin _name = name ; } ,
'commit-bin-name' : ( s ) => { s . bin . name = s . temp _bin _name ; s . is _editing _bin _name = false ; }
} , {
} , {
bin : { id : bin _id } ,
bin : { id : bin _id , name : bin _id , user _id : '' } ,
is _editing _bin _name : false ,
temp _bin _name : bin _id ,
notes : [
notes : [
//{is_editing: false, temp_text: '', bin_id: '', note: {id: nanoid(), text: 'Note one', modified: 1}},
//{is_editing: false, temp_text: '', bin_id: '', note: {id: nanoid(), text: 'Note one', modified: 1}},
] ,
] ,
search _term : '' ,
search _term : '' ,
sorting : 'new->old'
sorting : 'new->old' ,
login : {
showing : true ,
username : '' , // value of textbox
password : '' , // value of textbox
logged _in : false ,
user : {
id : '' ,
username : ''
} ,
session _id : ''
}
//search_result_notes: []
//search_result_notes: []
} ) ;
} ) ;