From 25b36528a00b99130831be92a07a5b53305cdb96 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Tue, 9 Jan 2024 22:06:27 +0100 Subject: [PATCH] feat: add official package btn --- app/services/packages_fetcher.ts | 2 +- app/validators/main.ts | 2 +- .../pages/home/components/button_group.vue | 2 +- resources/pages/home/components/order.vue | 7 ++- resources/pages/home/main.vue | 54 ++++++++++--------- types/packages.ts | 2 +- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/app/services/packages_fetcher.ts b/app/services/packages_fetcher.ts index 07c9fcc..3de6781 100644 --- a/app/services/packages_fetcher.ts +++ b/app/services/packages_fetcher.ts @@ -139,7 +139,7 @@ export class PackagesFetcher { * Filter them based on the given options */ if (options.category) packages = packages.filter((pkg) => pkg.category === options.category) - if (options.parties) packages = packages.filter((pkg) => options.parties!.includes(pkg.type)) + if (options.officialOnly) packages = packages.filter((pkg) => pkg.type === 'official') if (options.version) packages = this.#filterByVersions(packages, options.version) if (options.search) packages = this.#filterBySearch(packages, options.search) diff --git a/app/validators/main.ts b/app/validators/main.ts index c5df071..4913d97 100644 --- a/app/validators/main.ts +++ b/app/validators/main.ts @@ -15,7 +15,7 @@ export const getHomeValidator = vine.compile( category: vine.enum(categories.map((category) => category.label)).optional(), search: vine.string().optional(), version: vine.enum(['5', '6']).optional(), - parties: vine.array(vine.enum(['3rd-party', 'official'])).optional(), + officialOnly: vine.boolean().optional(), order: vine .enum(['-1', '1']) .transform((value) => Number(value) as SortOrder) diff --git a/resources/pages/home/components/button_group.vue b/resources/pages/home/components/button_group.vue index c74e174..ba6b00e 100644 --- a/resources/pages/home/components/button_group.vue +++ b/resources/pages/home/components/button_group.vue @@ -5,7 +5,7 @@ provide('group', true) diff --git a/resources/pages/home/components/order.vue b/resources/pages/home/components/order.vue index 13c0989..c9d8217 100644 --- a/resources/pages/home/components/order.vue +++ b/resources/pages/home/components/order.vue @@ -7,11 +7,14 @@ const group = inject('group', false) diff --git a/resources/pages/home/main.vue b/resources/pages/home/main.vue index ac18dd5..eec0494 100644 --- a/resources/pages/home/main.vue +++ b/resources/pages/home/main.vue @@ -14,7 +14,6 @@ import MainSection from './components/main_section.vue' import ButtonGroup from './components/button_group.vue' import type { GetHomeResponse, - ModuleType, PackageCategories, PackageCategory, PackagesFilters, @@ -93,33 +92,27 @@ const versionsOptions = [ subline: 'Compatible with AdonisJS 5', }, ] -const selectedVersion = ref(null) -/** - * Package parties - */ -const partiesOptions = [ - { value: 'official', label: 'Official' }, - { value: '3rd-party', label: '3rd Party' }, -] -const selectedParties = ref((params.parties as ModuleType[]) ?? []) +const selectedVersion = ref(params.version || null) + +const officialPackagesOnly = ref(params.officialOnly) /** * Refetch when any of the filters change */ -watch([selectedParties, order, orderBy, selectedVersion, category], () => fetchNewPageData(1)) +watch([officialPackagesOnly, order, orderBy, selectedVersion, category], () => fetchNewPageData(1)) function fetchNewPageData(page: number) { router.get( '/', { page, - category: category.value, - search: search.value, - version: selectedVersion.value, - parties: selectedParties.value, order: order.value, + search: search.value, orderBy: orderBy.value, + category: category.value, + version: selectedVersion.value, + officialOnly: officialPackagesOnly.value, }, { preserveState: true, preserveScroll: true }, ) @@ -160,22 +153,33 @@ function fetchNewPageData(page: number) {
- - - + + + - +
diff --git a/types/packages.ts b/types/packages.ts index 2dc64f4..3c20494 100644 --- a/types/packages.ts +++ b/types/packages.ts @@ -113,7 +113,7 @@ export type PackagesFilters = { order: SortOrder orderBy: 'name' | 'downloads' | 'stars' | 'updated' | 'created' version?: '5' | '6' - parties: ModuleType[] + officialOnly: boolean page: number }