local DB row store on frontend
This commit is contained in:
@@ -2,13 +2,13 @@ import nanoid from '../nanoid.min.js';
|
||||
import api from '../api.js';
|
||||
|
||||
const load_notes = function(state, dispatch){
|
||||
api.post('/load-notes', {bin_id: state.bin.id})
|
||||
api.post('/load-notes', {bin_id: state.bin_id})
|
||||
.then(res=>{
|
||||
dispatch('notes-loaded', res.notes);
|
||||
});
|
||||
};
|
||||
const runSearch = function(state, dispatch){
|
||||
api.post('/search', {search_term: state.search_term, sorting: state.sorting, bin_id: state.bin.id})
|
||||
api.post('/search', {search_term: state.search_term, sorting: state.sorting, bin_id: state.bin_id})
|
||||
.then(res=>{
|
||||
dispatch('update-search-results', res.notes);
|
||||
});
|
||||
@@ -16,6 +16,10 @@ const runSearch = function(state, dispatch){
|
||||
const new_note_handler = function(state, dispatch){
|
||||
dispatch('add-note', {id: nanoid(), date: Date.now()});
|
||||
};
|
||||
const new_note_by_dblclick_handler = function(state, dispatch, e){
|
||||
e.preventDefault(); // for nothing gets highlighted
|
||||
dispatch('add-note', {id: nanoid(), date: Date.now()});
|
||||
};
|
||||
const search_term_change_handler = function(state, dispatch, e){
|
||||
if(e.code === 'Enter'){
|
||||
runSearch(state, dispatch);
|
||||
@@ -51,8 +55,8 @@ const login_request_handler = function(state, dispatch, e){
|
||||
else{
|
||||
dispatch('login-failed');
|
||||
}
|
||||
})
|
||||
.catch(e=>{ dispatch('login-failed'); });
|
||||
},
|
||||
e=>{ dispatch('login-failed'); });
|
||||
};
|
||||
const logout_request_handler = function(state, dispatch, e){
|
||||
api.post('/logout', {});
|
||||
@@ -68,7 +72,7 @@ const bin_name_change_handler = function(state, dispatch, e){
|
||||
dispatch('update-bin-name', e.target.value);
|
||||
};
|
||||
const bin_name_commit_handler = function(state, dispatch){
|
||||
api.post('/bin-rename', {bin_id:state.bin.id, name:state.temp_bin_name});
|
||||
api.post('/bin-rename', {bin_id:state.bin_id, name:state.temp_bin_name});
|
||||
dispatch('commit-bin-name');
|
||||
};
|
||||
const choose_bin_handler = function(state, dispatch, bin_id){
|
||||
@@ -85,6 +89,7 @@ const choose_bin_handler = function(state, dispatch, bin_id){
|
||||
};
|
||||
|
||||
export {new_note_handler,
|
||||
new_note_by_dblclick_handler,
|
||||
search_term_change_handler,
|
||||
sorting_change_handler,
|
||||
load_notes,
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import api from '../api.js';
|
||||
|
||||
const edit_handler = function(note_state, dispatch){
|
||||
dispatch('update-note-editing', {id: note_state.note.id, is_editing: true});
|
||||
dispatch('update-note-editing', {id: note_state.note_id, is_editing: true});
|
||||
};
|
||||
const cancel_handler = function(note_state, dispatch){
|
||||
dispatch('update-note-editing', {id: note_state.note.id, is_editing: false});
|
||||
dispatch('update-note-editing', {id: note_state.note_id, is_editing: false});
|
||||
};
|
||||
const text_change_handler = function(note_state, dispatch, e){
|
||||
note_state.temp_text = e.target.value;
|
||||
};
|
||||
const save_handler = function(note_state, dispatch){
|
||||
dispatch('save-note-edit', {id: note_state.note.id, text: note_state.temp_text});
|
||||
api.post('/save', {bin_id: note_state.bin_id, note_id: note_state.note.id, text: note_state.temp_text})
|
||||
dispatch('save-note-edit', {id: note_state.note_id, text: note_state.temp_text});
|
||||
api.post('/save', {bin_id: note_state.bin_id, note_id: note_state.note_id, text: note_state.temp_text})
|
||||
};
|
||||
|
||||
export { edit_handler, cancel_handler, text_change_handler, save_handler };
|
||||
@@ -15,7 +15,7 @@ const hash_change_handler = function(state, dispatch, e){
|
||||
// get bin id from URL
|
||||
let bin_id = window.location.hash.substring(1); // extract the leading '#'
|
||||
if(bin_id === ''){
|
||||
const old_bin_id = state.bin.id;
|
||||
const old_bin_id = state.bin_id;
|
||||
window.history.replaceState(null,'', '#'+old_bin_id);
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user