11<script setup lang="ts">
22import PackageCard from ' ./PackageCard.vue'
3- import { PackageOutput , PackagesInput } from ' ./types'
3+ import { PackageOutput } from ' ./types'
44import { ref , computed , onMounted } from ' vue'
55import { uniqBy } from ' ./helpers'
6+ import { useQuery } from ' ./useQuery'
67
78const packageSource = ' https://ecosystem.feathershq.workers.dev/'
89
@@ -28,10 +29,6 @@ async function getPackageStats(): Promise<PackageOutput[]> {
2829 return uniq
2930}
3031
31- onMounted (async () => {
32- fetchedPackages .value = await getPackageStats ()
33- })
34-
3532const categories: CategoryOption [] = [
3633 { label: ' Authentication' , value: [' authentication' ] },
3734 { label: ' Authorization' , value: [' authorization' ] },
@@ -57,8 +54,8 @@ const categories: CategoryOption[] = [
5754]
5855
5956const keyToSortBy = ref <' stars' | ' downloads' | ' lastPublish' >(' lastPublish' )
60-
6157const showCore = ref (true )
58+
6259function filterCore(pkg : PackageOutput ) {
6360 return pkg .ownerName === ' feathersjs'
6461}
@@ -68,6 +65,7 @@ const coreCount = computed(() => {
6865
6966const packagesAreOldIfOlderThan = 1000 * 60 * 60 * 24 * 365 * 2.9 // 3 years
7067const showOld = ref (false )
68+
7169function filterOld(pkg : PackageOutput ) {
7270 return pkg .lastPublish .getTime () < Date .now () - packagesAreOldIfOlderThan
7371}
@@ -86,7 +84,15 @@ const countByCategory = computed(() => {
8684 return counts
8785})
8886
89- const categoriesToShow = ref <CategoryOption []>([])
87+ const categoriesToFilter = ref <string []>([])
88+
89+ const categoriesToShow = computed (() => {
90+ const cats = categories .filter ((category ) => {
91+ return categoriesToFilter .value .includes (category .label )
92+ })
93+ return cats
94+ })
95+
9096type Category = string []
9197type CategoryOption = {
9298 label: string
@@ -143,6 +149,17 @@ const packagesToShow = computed(() => {
143149 })
144150 return result
145151})
152+
153+ onMounted (async () => {
154+ fetchedPackages .value = await getPackageStats ()
155+
156+ // sync values with URL
157+ useQuery (keyToSortBy , ' sort' , ' string' )
158+ useQuery (showCore , ' core' , ' boolean' )
159+ useQuery (showOld , ' old' , ' boolean' )
160+ useQuery (search , ' s' , ' string' )
161+ useQuery (categoriesToFilter , ' cat' , ' string[]' )
162+ })
146163 </script >
147164
148165<template >
@@ -158,7 +175,7 @@ const packagesToShow = computed(() => {
158175 >
159176 </div >
160177 <el-select
161- v-model =" categoriesToShow "
178+ v-model =" categoriesToFilter "
162179 multiple
163180 collapse-tags
164181 collapse-tags-tooltip
@@ -171,7 +188,7 @@ const packagesToShow = computed(() => {
171188 v-for =" option in categories"
172189 :key =" option.label"
173190 :label =" option.label"
174- :value =" option"
191+ :value =" option.label "
175192 :title =" option.value.join(', ')"
176193 >
177194 {{ option.label }} ({{ countByCategory[option.label] }})
0 commit comments