#180 get Foundation Essentials packages, managed by airtable categories column

This commit is contained in:
neil 2023-02-10 14:35:36 +08:00
parent 73c9eb843e
commit 9ac0aa32fc
5 changed files with 10 additions and 9 deletions

View file

@ -4,13 +4,14 @@
import { PackageStates } from '$libs/types'; import { PackageStates } from '$libs/types';
import Preloader from '@tea/ui/Preloader/Preloader.svelte'; import Preloader from '@tea/ui/Preloader/Preloader.svelte';
import PackageCard from '@tea/ui/PackageCard/PackageCard.svelte'; import PackageCard from '@tea/ui/PackageCard/PackageCard.svelte';
import { onMount } from 'svelte'; import { packagesStore } from '$libs/stores';
// TODO: replace with getting foundation essentials // TODO: replace with getting foundation essentials
import { getTopPackages } from '$libs/api/mock'; import { getTopPackages } from '$libs/api/mock';
import { installPackage } from '@api'; import { installPackage } from '@api';
export let title = 'Packages'; export let title = 'Packages';
export let category = ''; // filter
let packages: GUIPackage[] = []; let packages: GUIPackage[] = [];
@ -23,10 +24,10 @@
}[state]; }[state];
}; };
onMount(async () => { packagesStore.subscribe((ps) => {
if (!packages.length) { packages = category ?
packages = await getTopPackages(); ps.filter((p) => (p.categories || []).includes(category)) :
} ps;
}); });
</script> </script>

View file

@ -24,7 +24,7 @@ import { get as apiGet } from '$libs/v1Client';
export async function getPackages(): Promise<GUIPackage[]> { export async function getPackages(): Promise<GUIPackage[]> {
const [packages, installedPackages] = await Promise.all([ const [packages, installedPackages] = await Promise.all([
apiGet<Package[]>('packages'), apiGet<Package[]>('packages', { nocache: 'true' }),
getInstalledPackages() getInstalledPackages()
]); ]);

View file

@ -17,7 +17,7 @@ export default function initPackagesStore() {
getPackages().then((pkgs) => { getPackages().then((pkgs) => {
set(pkgs); set(pkgs);
packagesIndex = new Fuse(pkgs, { packagesIndex = new Fuse(pkgs, {
keys: ['name', 'full_name', 'desc'] keys: ['name', 'full_name', 'desc', 'categories']
}); });
}); });
} }

View file

@ -13,7 +13,7 @@
<div> <div>
<PageHeader coverUrl="/images/headers/header_bg_1.png">Discover</PageHeader> <PageHeader coverUrl="/images/headers/header_bg_1.png">Discover</PageHeader>
<section class="mt-8 mb-8"> <section class="mt-8 mb-8">
<Packages title="FOUNDATION ESSENTIALS" /> <Packages title="FOUNDATION ESSENTIALS" category="foundation_essentials" />
</section> </section>
<PageHeader coverUrl="/images/headers/header_bg_1.png">ASSET TYPE</PageHeader> <PageHeader coverUrl="/images/headers/header_bg_1.png">ASSET TYPE</PageHeader>
<section class="mt-8 mb-8 flex gap-4"> <section class="mt-8 mb-8 flex gap-4">

View file

@ -20,6 +20,7 @@ export interface Package {
installs: number; installs: number;
reviews?: Review[]; reviews?: Review[];
package_yml_url?: string; package_yml_url?: string;
categories: string[];
// metas // metas
full_description?: string; // probably markdown full_description?: string; // probably markdown
bottles?: Bottle[]; bottles?: Bottle[];
@ -27,7 +28,6 @@ export interface Package {
size_bytes?: number; size_bytes?: number;
documentation_url?: string; documentation_url?: string;
github?: string; github?: string;
categories?: string[];
contributors?: Contributor[]; contributors?: Contributor[];
readme_md?: string; readme_md?: string;
} }