Added sort button with asc/desc price sort

This commit is contained in:
lootboxer 2025-07-01 00:16:26 +03:00
parent e5478bb1c6
commit 4127f6af14
13 changed files with 226 additions and 71 deletions

View file

@ -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
}
}