From 1ff81379905a45569f5dc365a0cd30d03c63feab Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 9 Dec 2022 12:12:55 +0800 Subject: [PATCH] #72 list installed packages - added @tea/ui/MiniPackageCard reusable component --- .../InstalledPackages.svelte | 37 +++++++++- packages/gui/src/libs/api/tauri.ts | 2 +- .../MiniPackageCard.stories.ts | 46 +++++++++++++ .../MiniPackageCard/MiniPackageCard.svelte | 68 +++++++++++++++++++ packages/ui/src/types.ts | 1 + 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 packages/ui/src/MiniPackageCard/MiniPackageCard.stories.ts create mode 100644 packages/ui/src/MiniPackageCard/MiniPackageCard.svelte diff --git a/packages/gui/src/components/InstalledPackages/InstalledPackages.svelte b/packages/gui/src/components/InstalledPackages/InstalledPackages.svelte index c9a3c9f..76b1709 100644 --- a/packages/gui/src/components/InstalledPackages/InstalledPackages.svelte +++ b/packages/gui/src/components/InstalledPackages/InstalledPackages.svelte @@ -1,6 +1,39 @@ - + + +
    + {#if packages.length > 0} + {#each packages as pkg} +
    + { + console.log('do something with:', pkg.full_name); + }} + /> +
    + {/each} + {:else} + {#each Array(12) as _} +
    + +
    + {/each} + {/if} +
diff --git a/packages/gui/src/libs/api/tauri.ts b/packages/gui/src/libs/api/tauri.ts index 7cd9688..de0ac21 100644 --- a/packages/gui/src/libs/api/tauri.ts +++ b/packages/gui/src/libs/api/tauri.ts @@ -21,7 +21,7 @@ import { PackageStates } from '../types'; const base = 'https://api.tea.xyz/v1'; -async function get(path: string, query?: { [key: string]: any }) { +async function get(path: string, query?: { [key: string]: string }) { const client = await getClient(); const uri = join(base, path); const { data } = await client.get(uri.toString(), { diff --git a/packages/ui/src/MiniPackageCard/MiniPackageCard.stories.ts b/packages/ui/src/MiniPackageCard/MiniPackageCard.stories.ts new file mode 100644 index 0000000..44ae3ae --- /dev/null +++ b/packages/ui/src/MiniPackageCard/MiniPackageCard.stories.ts @@ -0,0 +1,46 @@ +import MiniPackageCard from './MiniPackageCard.svelte'; +import type { Package } from '../types'; + +const SamplePkg: Package = { + slug: 'mesonbuild_com', + homepage: 'https://mesonbuild.com', + name: 'mesonbuild.com', + version: '0.63.3', + last_modified: '2022-10-06T15:45:08.000Z', + full_name: 'mesonbuild.com', + dl_count: 270745, + thumb_image_name: 'mesonbuild_com_option 1.jpg ', + maintainer: 'neilm', + desc: 'Fast and user friendly build system', + thumb_image_url: 'https://tea.xyz/Images/packages/mesonbuild_com.jpg', + installs: 0, + bottles: 23 +}; + +// More on how to set up stories at: https://storybook.js.org/docs/7.0/svelte/writing-stories/introduction +export default { + title: 'Example/MiniPackageCard', + component: MiniPackageCard, + tags: ['docsPage'], + render: ({ pkg, link }: { pkg: Package; link: string }) => ({ + Component: MiniPackageCard, + props: { pkg, link } + }), + argTypes: { + pkg: { + name: 'pkg', + description: 'type Package' + }, + link: { + name: 'link' + } + } +}; + +// More on writing stories with args: https://storybook.js.org/docs/7.0/svelte/writing-stories/args +export const Example = { + args: { + pkg: SamplePkg, + link: '#' + } +}; diff --git a/packages/ui/src/MiniPackageCard/MiniPackageCard.svelte b/packages/ui/src/MiniPackageCard/MiniPackageCard.svelte new file mode 100644 index 0000000..f5520c6 --- /dev/null +++ b/packages/ui/src/MiniPackageCard/MiniPackageCard.svelte @@ -0,0 +1,68 @@ + + +
+
+ +
+ ‹/› +
+
+
+

{pkg.name}

+ {#if pkg.maintainer} +

• {pkg.maintainer}

+ {/if} +
+

+ V {pkg.version} {pkg?.bottles ? `| ${pkg.bottles} bottles` : ''} +

+
+ +
+
+ + diff --git a/packages/ui/src/types.ts b/packages/ui/src/types.ts index 2bd6c94..ca1dac3 100644 --- a/packages/ui/src/types.ts +++ b/packages/ui/src/types.ts @@ -18,6 +18,7 @@ export interface Package { dl_count: number; installs: number; reviews?: Review[]; + bottles?: number; // TODO: where to get this? } export type AirtablePost = {