can create new bins

This commit is contained in:
brian
2021-03-15 20:19:00 -04:00
parent dffdcfcd60
commit 8bac25ab2c
5 changed files with 45 additions and 21 deletions
+8 -3
View File
@@ -5,11 +5,11 @@ import api from '../api-stub.js';
const load_notes = function(state, dispatch){
api.post('/load-notes', {bin_id: state.bin.id})
.then(res=>{
dispatch({type: 'notes-loaded', notes: res.notes});
dispatch({type: 'notes-loaded', notes: res.notes, bin_id: state.bin.id});
});
};
const runSearch = function(state, dispatch){
api.post('/search', {search_term: state.search_term, sorting: state.sorting})
api.post('/search', {search_term: state.search_term, sorting: state.sorting, bin_id: state.bin.id})
.then(res=>{
dispatch({type:'update-search-results', notes: res.notes});
});
@@ -29,5 +29,10 @@ const sorting_change_handler = function(state, dispatch, e){
runSearch(state, dispatch);
dispatch({type:'update-sorting', sorting: e.target.value});
};
const new_bin_handler = function(state, dispatch){
const id = nanoid();
dispatch({type: 'new-bin', bin: {id}});
dispatch({type: 'notes-loaded', notes: [], bin_id: id});
};
export {new_note_handler, search_term_change_handler, sorting_change_handler, load_notes};
export {new_note_handler, search_term_change_handler, sorting_change_handler, load_notes, new_bin_handler};
+1 -1
View File
@@ -15,7 +15,7 @@ const save_handler = function(note_state, dispatch){
dispatch({type: 'update-note-text', note_id: note_state.note.id, text: note_state.temp_text});
//note.text = temp_text;
dispatch({type: 'update-note-editing', note_id: note_state.note.id, is_editing: false});
api.post('/save', {note_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 };