fixed syncing a note's temp_text with its actual text, in different sitations; updating text updates 'modified' time on the mock server
This commit is contained in:
@@ -8,7 +8,7 @@ function Note(vnode_init){
|
||||
const {is_editing, note} = note_state;
|
||||
if(is_editing){
|
||||
return m('.note', [
|
||||
m('textarea', {key: 'textarea', onchange: text_change_handler.bind(null, note_state, dispatch) }, note.text),
|
||||
m('textarea', {key: 'textarea', onchange: text_change_handler.bind(null, note_state, dispatch) }, note_state.temp_text),
|
||||
m('.buttons', {key: 'editing-buttons'}, [
|
||||
m('button', {key: 'cancel-button', onclick: cancel_handler.bind(null, note_state, dispatch) }, 'Cancel'),
|
||||
m('button', {key: 'save-button', onclick: save_handler.bind(null, note_state, dispatch) }, 'Save')
|
||||
|
||||
@@ -35,6 +35,7 @@ endpoints.post['/save'] = function(resolve, reject, body){
|
||||
const note = state.notes.find( n => n.id===note_id );
|
||||
if(note){
|
||||
note.text = text;
|
||||
note.modified = Date.now();
|
||||
}
|
||||
else{
|
||||
state.notes.push({id: note_id, text, modified: Date.now()});
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import nanoid from '../nanoid.min.js';
|
||||
import api from '../api.js';
|
||||
//import api from '../api-stub.js';
|
||||
//import api from '../api.js';
|
||||
import api from '../api-stub.js';
|
||||
|
||||
const load_notes = function(state, dispatch){
|
||||
api.post('/load-notes', {bin_id: state.bin.id})
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import api from '../api.js';
|
||||
//import api from '../api-stub.js';
|
||||
//import api from '../api.js';
|
||||
import api from '../api-stub.js';
|
||||
|
||||
const edit_handler = function(note_state, dispatch){
|
||||
dispatch({type: 'update-note-editing', note_id: note_state.note.id, is_editing: true});
|
||||
|
||||
@@ -12,7 +12,7 @@ function search_reducer(old_state, new_state, action){
|
||||
new_state.search_term = action.search_term;
|
||||
}
|
||||
else if(action.type === 'update-search-results'){
|
||||
new_state.notes = action.notes.map(note=>({is_editing: false, note}));
|
||||
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: '', note}));
|
||||
new_state.search_term = old_state.search_term;
|
||||
}
|
||||
else{
|
||||
@@ -22,10 +22,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 = old_state.notes.concat([{is_editing: true, note: {id: action.id, text: '', modified: Date.now()}}])
|
||||
new_state.notes = ([{is_editing: true, 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, note}));
|
||||
new_state.notes = action.notes.map(note=>({is_editing: false, temp_text: note.text, note}));
|
||||
}
|
||||
else if(action.type === 'update-note-text'){
|
||||
const i = old_state.notes.findIndex(note_state => note_state.note.id === action.note_id);
|
||||
@@ -35,7 +35,7 @@ function notes_reducer(old_state, new_state, action){
|
||||
else if(action.type === 'update-note-editing'){
|
||||
const i = old_state.notes.findIndex(note_state => note_state.note.id === action.note_id);
|
||||
new_state.notes = old_state.notes.slice();
|
||||
new_state.notes[i] = {...new_state.notes[i], is_editing: action.is_editing};
|
||||
new_state.notes[i] = {...new_state.notes[i], is_editing: action.is_editing, temp_text: new_state.notes[i].note.text};
|
||||
}
|
||||
else{
|
||||
new_state.notes = old_state.notes;
|
||||
|
||||
Reference in New Issue
Block a user