You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pastebin/handlers/App.js

33 lines
1.1 KiB
JavaScript

import nanoid from '../nanoid.min.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})
.then(res=>{
dispatch({type: 'notes-loaded', notes: res.notes});
});
};
const runSearch = function(state, dispatch){
api.post('/search', {search_term: state.search_term, sorting: state.sorting})
.then(res=>{
dispatch({type:'update-search-results', notes: res.notes});
});
};
const new_note_handler = function(state, dispatch){
dispatch({type:'add-note', id: nanoid()});
};
const search_term_change_handler = function(state, dispatch, e){
if(e.code === 'Enter'){
runSearch(state, dispatch);
}
else{
dispatch({type:'update-search-term', search_term: e.target.value});
}
};
const sorting_change_handler = function(state, dispatch, e){
runSearch(state, dispatch);
dispatch({type:'update-sorting', sorting: e.target.value});
};
export {new_note_handler, search_term_change_handler, sorting_change_handler, load_notes};