Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
Merge pull request #185 from teaxyz/package-details
Browse files Browse the repository at this point in the history
temporary merge to prep for electron migration
  • Loading branch information
getneil authored Feb 2, 2023
2 parents 4273295 + be07f25 commit ccd00b5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For better documentation checkout this [notion](https://www.notion.so/teaxyz/tea

| Project | Version |
|------------|---------|
| nodejs.org | >=16 |
| nodejs.org | =18.13.0 |
| pnpm.io | >=7.18.2 |
| rust-lang.org | >=1.62 |
| rust-lang.org/cargo | >=0.66 |
Expand Down
2 changes: 1 addition & 1 deletion modules/gui/src/libs/api/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function getPackages(): Promise<GUIPackage[]> {
getInstalledPackages()
]);

return packages.map((pkg) => {
return (packages || []).map((pkg) => {
const found = installedPackages.find((p) => p.full_name === pkg.full_name);
return {
...pkg,
Expand Down
35 changes: 2 additions & 33 deletions modules/gui/src/libs/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,13 @@ import Fuse from 'fuse.js';
import type { Package, Review, AirtablePost } from '@tea/ui/types';
import type { GUIPackage } from '$libs/types';

import { getPackages, getFeaturedPackages, getPackageReviews, getAllPosts } from '@api';
import { getFeaturedPackages, getPackageReviews, getAllPosts } from '@api';
import initAuthStore from './stores/auth';
import initNavStore from './stores/nav';
import initPackagesStore from './stores/pkgs';

export const featuredPackages = writable<Package[]>([]);

function initPackagesStore() {
let initialized = false;
const { subscribe, set } = writable<GUIPackage[]>([]);
const packages: GUIPackage[] = [];
let packagesIndex: Fuse<GUIPackage>;

if (!initialized) {
initialized = true;
getPackages().then((pkgs) => {
set(pkgs);
packagesIndex = new Fuse(pkgs, {
keys: ['name', 'full_name', 'desc']
});
});
}

subscribe((v) => packages.push(...v));

return {
packages,
subscribe,
search: async (term: string, limit = 5): Promise<GUIPackage[]> => {
if (!term || !packagesIndex) return [];
// TODO: if online, use algolia else use Fuse

const res = packagesIndex.search(term, { limit });
const matchingPackages: GUIPackage[] = res.map((v) => v.item);
return matchingPackages;
}
};
}

export const packagesStore = initPackagesStore();

export const initializeFeaturedPackages = async () => {
Expand Down
39 changes: 39 additions & 0 deletions modules/gui/src/libs/stores/pkgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { writable } from 'svelte/store';
import type { Review } from '@tea/ui/types';
import { getPackageReviews } from '@api';

interface PackagesReview {
[full_name: string]: Review[];
}

export default function initPackagesReviewStore() {
const { update, subscribe } = writable<PackagesReview>({});

let packagesReviews: PackagesReview = {};

subscribe((v) => (packagesReviews = v));

const getSetPackageReviews = async (full_name: string) => {
if (full_name && !packagesReviews[full_name]) {
packagesReviews[full_name] = [];
const reviews = await getPackageReviews(full_name);
update((v) => {
return {
...v,
[full_name]: reviews
};
});
}
};

return {
subscribe: (full_name: string, reset: (reviews: Review[]) => void) => {
getSetPackageReviews(full_name);
return subscribe((value) => {
if (value[full_name]) {
reset(value[full_name]);
}
});
}
};
}
1 change: 1 addition & 0 deletions modules/gui/src/libs/v1Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import urlJoin from 'url-join';
export const baseUrl = 'https://api.tea.xyz/v1';

export async function get<T>(path: string, query?: { [key: string]: string }) {
console.log(`GET /api/${path}`);
const [session, client] = await Promise.all([getSession(), getClient()]);

const uri = urlJoin(baseUrl, path);
Expand Down
3 changes: 2 additions & 1 deletion modules/ui/src/MiniPackageCard/MiniPackageCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<div>
<p>
<span class="text-xs text-gray"
>V&NonBreakingSpace;{pkg.version} {pkg?.bottles ? `| ${pkg.bottles} bottles` : ''}</span
>V&NonBreakingSpace;{pkg.version}
{pkg?.bottles?.length ? `| ${pkg.bottles.length} bottles` : ''}</span
>
</p>
</div>
Expand Down
10 changes: 9 additions & 1 deletion modules/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export interface Package {
dl_count: number;
installs: number;
reviews?: Review[];
bottles?: number; // TODO: where to get this?
// metas
full_description?: string; // probably markdown
bottles?: Bottle[];
license?: string;
size_bytes?: number;
documentation_url?: string;
github_repository_url?: string;
owners?: Partial<Developer>[];
categories?: string[];
}

export type AirtablePost = {
Expand Down

0 comments on commit ccd00b5

Please sign in to comment.