diff options
Diffstat (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 97be0cb..177d9f7 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -38,8 +38,9 @@ export class NeedListComponent { needs: Need[] = []; searchResults: Need[] = []; sortMode = 'Ascending' - sortSelection: string = ''; + currentSortAlgo: sortAlgo = sortByGoal; + sortSelection: string = this.currentSortAlgo.name; SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ {func:sortByGoal,name:"sortByMaxGoal", display:["Max Goal", "Min Goal"]}, @@ -77,19 +78,6 @@ export class NeedListComponent { this.search(form) } - changeSortAlgo(algoName: string, form: any) { - console.log(algoName); - this.SortingAlgoArrays.forEach(algo => { - if(algo.name === algoName) { - this.currentSortAlgo = algo.func; - console.log("changed sorting algorithm to: ", algo.name + this.sortMode) - return - } - }); - this.refresh() - this.search(form); - } - private searchDelay: any; async search(form: any) { @@ -103,6 +91,15 @@ export class NeedListComponent { this.searchDelay = setTimeout(() => { if (form) { + //sorting based on algo selected + this.SortingAlgoArrays.forEach(algo => { + if(algo.name === this.sortSelection) { + this.currentSortAlgo = algo.func; + console.log("changed sorting algorithm to: ", algo.name + this.sortMode) + return + } + }); + const currentSearchValue = form.search; //latest value of the search this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { if (this.sortMode == 'Ascending') { |