From be92dda94c4f9156c44f159d7e0e66baa3465438 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Sun, 21 Jan 2024 21:40:53 +0100 Subject: [PATCH] refactor: default sort by most downloaded packages --- app/services/packages_fetcher.ts | 8 +++++--- content/packages/cavai-queue.yml | 2 +- resources/pages/home/main.vue | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/services/packages_fetcher.ts b/app/services/packages_fetcher.ts index 3de6781..a0466bc 100644 --- a/app/services/packages_fetcher.ts +++ b/app/services/packages_fetcher.ts @@ -40,7 +40,7 @@ export class PackagesFetcher { const valueB = b[property] if (typeof valueA === 'number' && typeof valueB === 'number') { - return valueA - valueB * order + return (valueA - valueB) * order } if (typeof valueA === 'string' && typeof valueB === 'string') { @@ -146,11 +146,13 @@ export class PackagesFetcher { /** * Sort the results */ + console.log(options) const sortedPackages = this.#sortPackages( - options.order ?? 1, - options.orderBy ?? 'name', + options.order ?? -1, + options.orderBy ?? 'downloads', packages, ) + console.log(sortedPackages) /** * Paginate the results diff --git a/content/packages/cavai-queue.yml b/content/packages/cavai-queue.yml index 5e5004b..207c8a3 100644 --- a/content/packages/cavai-queue.yml +++ b/content/packages/cavai-queue.yml @@ -1,4 +1,4 @@ -name: '@cavai/adonis-queue' +name: 'cavai/adonis-queue' description: Queue package for Adonis V5. Comes with built-in database driver and allows easy extension with custom drivers repo: cavai-research/Adonis-Queue npm: '@cavai/adonis-queue' diff --git a/resources/pages/home/main.vue b/resources/pages/home/main.vue index 5e1990f..3f7e4d2 100644 --- a/resources/pages/home/main.vue +++ b/resources/pages/home/main.vue @@ -67,8 +67,8 @@ const orderByOptions = [ description: 'Sort packages by their last update date', }, ] -const order = ref(params.order ? (+params.order as SortOrder) : 1) -const orderBy = ref(params.orderBy || orderByOptions[0].value) +const order = ref(params.order ? (+params.order as SortOrder) : -1) +const orderBy = ref(params.orderBy || orderByOptions[3].value) /** * Filters