import { useState, useEffect } from 'react'; import './style.css'; import { usePackageStore, Package } from './store'; import { Link2, SquareArrowOutUpRight } from 'lucide-react'; import { useConfigStore } from '@/store/config'; export const PackageManager = () => { const { shopPackages, installedPackages, getInstalledPackages, getShopPackages, uninstallPackage, installPackage } = usePackageStore(); const { pageApi, pageStoreApi } = useConfigStore(); useEffect(() => { getInstalledPackages(); getShopPackages(); }, []); const getPackageStatus = (pkg: Package): string => { const installed = installedPackages.find((p) => p.user === pkg.user && p.key === pkg.key); if (!installed) return 'not-installed'; if (installed.version !== pkg.version) return 'update-available'; return 'installed'; }; const handleInstall = (id: string) => { const pkg = shopPackages.find((p) => p.id === id); if (pkg) { installPackage(pkg); } }; const handleUpdate = (id: string) => { const pkg = shopPackages.find((p) => p.id === id); if (pkg) { installPackage(pkg); } }; const handleReinstall = (id: string) => { const pkg = shopPackages.find((p) => p.id === id); if (pkg) { installPackage(pkg); } }; const handleUninstall = (id: string) => { const pkg = shopPackages.find((p) => p.id === id); if (pkg) { uninstallPackage(pkg); } }; const getActionButton = (status: string, pkg: Package) => { switch (status) { case 'not-installed': return ( ); case 'update-available': return ( ); case 'installed': return ( ); } }; const handleOpenWindow = (pkg: Package) => { const baseUrl = pageStoreApi || 'https://kevisual.silkyai.cn'; const path = `/${pkg.user}/${pkg.key}`; window.open(`${baseUrl}${path}`, '_blank'); }; const handleOpenClientWindow = (pkg: Package) => { if (!pageApi) return; const baseUrl = pageApi; const path = `/${pkg.user}/${pkg.key}`; window.open(`${baseUrl}${path}`, '_blank'); }; return (
{pkg.description}