Skip to content

Commit

Permalink
refactor date filter
Browse files Browse the repository at this point in the history
  • Loading branch information
rrchai committed Oct 25, 2023
1 parent 1cda8d0 commit fb2487b
Showing 1 changed file with 10 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,9 @@ export class ChallengeSearchComponent
this.isCustomYear = (this.selectedYear as string) === 'custom';
if (!this.isCustomYear) {
const yearRange = this.selectedYear as DateRange | undefined;
this.router.navigate([], {
queryParamsHandling: 'merge',
queryParams: {
minStartDate: yearRange?.start ? yearRange.start : undefined,
maxStartDate: yearRange?.end ? yearRange.end : undefined,
},
this.onParamChange({
minStartDate: yearRange?.start ? yearRange.start : undefined,
maxStartDate: yearRange?.end ? yearRange.end : undefined,
});

// reset custom range
Expand All @@ -466,41 +463,13 @@ export class ChallengeSearchComponent
onCalendarChange(): void {
this.isCustomYear = true;
if (this.calendar) {
this.router.navigate([], {
queryParamsHandling: 'merge',
queryParams: {
minStartDate: this.datePipe.transform(
this.calendar.value[0],
'yyyy-MM-dd'
),
maxStartDate: this.datePipe.transform(
this.calendar.value[1],
'yyyy-MM-dd'
),
},
this.onParamChange({
minStartDate: this.dateToFormat(this.calendar.value[0]),
maxStartDate: this.dateToFormat(this.calendar.value[1]),
});
}
}

onSortChange(): void {
this.router.navigate([], {
queryParamsHandling: 'merge',
queryParams: {
sort: this.sortedBy,
},
});
}

onPageChange(event: any) {
this.router.navigate([], {
queryParamsHandling: 'merge',
queryParams: {
pageNumber: event.page,
pageSize: event.rows,
},
});
}

onParamChange(filteredQuery: any): void {
// update params of URL
const params = Object.entries(filteredQuery)
Expand Down Expand Up @@ -530,6 +499,10 @@ export class ChallengeSearchComponent
}
}

dateToFormat(date: Date, format?: 'yyyy-MM-dd'): string | null {
return this.datePipe.transform(date, format);
}

splitParam(activeParam: string | undefined, by = ','): any[] {
return activeParam ? activeParam.split(by) : [];
}
Expand Down

0 comments on commit fb2487b

Please sign in to comment.