|
|
|
@ -4,15 +4,20 @@ import nanoid from './nanoid.min.js';
|
|
|
|
|
var root = document.body;
|
|
|
|
|
|
|
|
|
|
function bin_reducer(old_state, new_state, action){
|
|
|
|
|
if(action.type === 'new-bin'){
|
|
|
|
|
new_state.bin = action.bin;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
new_state.bin = old_state.bin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function search_reducer(old_state, new_state, action){
|
|
|
|
|
if(action.type === 'update-search-term'){
|
|
|
|
|
new_state.search_term = action.search_term;
|
|
|
|
|
}
|
|
|
|
|
else if(action.type === 'update-search-results'){
|
|
|
|
|
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: '', note}));
|
|
|
|
|
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: '', bin_id: old_state.bin.id, note}));
|
|
|
|
|
new_state.search_term = old_state.search_term;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
@ -22,10 +27,10 @@ function search_reducer(old_state, new_state, action){
|
|
|
|
|
|
|
|
|
|
function notes_reducer(old_state, new_state, action){
|
|
|
|
|
if(action.type === 'add-note'){
|
|
|
|
|
new_state.notes = ([{is_editing: true, note: {id: action.id, text: '', modified: Date.now()}}]).concat(old_state.notes)
|
|
|
|
|
new_state.notes = ([{is_editing: true, temp_text: '', bin_id: old_state.bin.id, note: {id: action.id, text: '', modified: Date.now()}}]).concat(old_state.notes)
|
|
|
|
|
}
|
|
|
|
|
else if(action.type === 'notes-loaded'){
|
|
|
|
|
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: note.text, note}));
|
|
|
|
|
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: note.text, bin_id: action.bin_id, note}));
|
|
|
|
|
}
|
|
|
|
|
else if(action.type === 'update-note-text'){
|
|
|
|
|
const i = old_state.notes.findIndex(note_state => note_state.note.id === action.note_id);
|
|
|
|
@ -64,7 +69,7 @@ function reducer(old_state, action){
|
|
|
|
|
const store = Redux.createStore(reducer, /* preloadedState, */ {
|
|
|
|
|
bin: {id: nanoid()},
|
|
|
|
|
notes: [
|
|
|
|
|
//{is_editing: false, 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: '',
|
|
|
|
|
sorting: 'new->old'
|
|
|
|
|