Added sort button with asc/desc price sort
This commit is contained in:
parent
e5478bb1c6
commit
4127f6af14
13 changed files with 226 additions and 71 deletions
|
|
@ -5,15 +5,15 @@ interface IGetExcursionsRequest {
|
|||
limit: number;
|
||||
offset: number;
|
||||
filter?: Partial<IExcursionsFilter>;
|
||||
isPriceSortAsc?: boolean;
|
||||
}
|
||||
|
||||
export default class ApiService {
|
||||
getExcursions({ limit, offset, filter }: IGetExcursionsRequest): IExcursionCard[] {
|
||||
console.log(limit, offset, filter);
|
||||
getExcursions({ limit, offset, filter, isPriceSortAsc }: IGetExcursionsRequest): Promise<IExcursionCard[]> {
|
||||
const excursionsSorted = excursions.sort((a, b) => isPriceSortAsc ? a.cost - b.cost : b.cost - a.cost)
|
||||
|
||||
let result = excursions.slice(offset, offset + limit)
|
||||
|
||||
|
||||
if (filter) {
|
||||
if (filter.city) {
|
||||
result = result.filter((card) => card.city.includes(filter.city))
|
||||
|
|
@ -31,8 +31,11 @@ export default class ApiService {
|
|||
)
|
||||
}
|
||||
}
|
||||
return new Promise((res, reg) => {
|
||||
setTimeout(() => {
|
||||
res(result)
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue