sorting works, on mock api server

readme
brian 4 years ago
parent 6e7ab2ea67
commit bd4aca06d7

@ -20,7 +20,13 @@ endpoints.post['/load-notes'] = function(resolve, reject, body){
}; };
endpoints.post['/search'] = function(resolve, reject, body){ endpoints.post['/search'] = function(resolve, reject, body){
const notes = state.notes.filter(n => n.text.indexOf(body.search_term) !== -1 ); const notes = state.notes.filter(n => n.text.indexOf(body.search_term) !== -1 )
if(body.sorting==='new->old'){
notes.sort((a,b) => a.modified-b.modified);
}
else{
notes.sort((a,b) => b.modified-a.modified);
}
resolve( {status: 'ok', notes} ); resolve( {status: 'ok', notes} );
}; };

@ -9,7 +9,7 @@ const load_notes = function(state, dispatch){
}); });
}; };
const runSearch = function(state, dispatch){ const runSearch = function(state, dispatch){
api.post('/search', {search_term: state.search_term}) api.post('/search', {search_term: state.search_term, sorting: state.sorting})
.then(res=>{ .then(res=>{
dispatch({type:'update-search-results', notes: res.notes}); dispatch({type:'update-search-results', notes: res.notes});
}); });
@ -26,6 +26,7 @@ const search_term_change_handler = function(state, dispatch, e){
} }
}; };
const sorting_change_handler = function(state, dispatch, e){ const sorting_change_handler = function(state, dispatch, e){
runSearch(state, dispatch);
dispatch({type:'update-sorting', sorting: e.target.value}); dispatch({type:'update-sorting', sorting: e.target.value});
}; };

Loading…
Cancel
Save