Skip to content

Commit

Permalink
Sort by amount
Browse files Browse the repository at this point in the history
Now we have the sort by amount generator cooking for values & what not.
  • Loading branch information
extrude committed Jun 17, 2018
1 parent d089165 commit 7635039
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ const getVisibleExpenses = (expenses, {text, sortBy, startDate, endDate}) => {
const textMatch = expense.description.toLowerCase().includes(text.toLowerCase()) ;

return startDateMatch && endDateMatch && textMatch;
}).sort((a,b) => {
if(sortBy === 'date'){
return a.createdAt < b.createdAt ? 1 : -1;
} else if(sortBy === 'amount'){
return a.amount < b.amount ? 1 : -1;
}
});
};
const expenseReducerDefaultState = [];
Expand Down Expand Up @@ -137,8 +143,9 @@ store.subscribe(() => {
const visibleExpenses = getVisibleExpenses(state.expenses, state.filters);
console.log(visibleExpenses);
});
const expense1 = store.dispatch(addExpense({description: 'Rent',amount:100, createdAt: 300}));
const expense2 = store.dispatch(addExpense({description: 'Tits',amount:3400, createdAt:-100}));
const expense1 = store.dispatch(addExpense({description: 'Rent',amount:300, createdAt: -1000}));
const expense2 = store.dispatch(addExpense({description: 'Tits',amount:100, createdAt:-2100}));
store.dispatch(sortByAmount());
// const expense3 = store.dispatch(addExpense({description: 'Pussy',amount:100}));
// //console.log(store.getState());
// store.dispatch(removeExpense({id: expense2.expense.id}));
Expand All @@ -151,5 +158,4 @@ const expense2 = store.dispatch(addExpense({description: 'Tits',amount:3400, cre
//store.dispatch(setStartDate(0));
// store.dispatch(setStartDate());
//store.dispatch(setEndDate(999));
// store.dispatch(setEndDate());
store.dispatch(setTextFilter('poop'));
// store.dispatch(setEndDate());

0 comments on commit 7635039

Please sign in to comment.