mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
Merge pull request #185 from teaxyz/package-details
temporary merge to prep for electron migration
This commit is contained in:
commit
ccd00b5c03
7 changed files with 55 additions and 37 deletions
|
@ -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 |
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
39
modules/gui/src/libs/stores/pkgs.ts
Normal file
39
modules/gui/src/libs/stores/pkgs.ts
Normal file
|
@ -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]);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
<div>
|
||||
<p>
|
||||
<span class="text-xs text-gray"
|
||||
>V {pkg.version} {pkg?.bottles ? `| ${pkg.bottles} bottles` : ''}</span
|
||||
>V {pkg.version}
|
||||
{pkg?.bottles?.length ? `| ${pkg.bottles.length} bottles` : ''}</span
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue