"use client" import type React from "react" import { useState } from "react" import toast from "react-hot-toast" import gt from "semver/functions/gt" import { Search, RefreshCw, Filter, Grid3x3, List } from "lucide-react" import DashboardCard from "./DashboardCard" import DashboardPackageCard from "./DashboardPackageCard" import PackageCard from "./PackageCard" import type { Plugin, InstalledPlugin } from "../App" interface DashboardOverviewProps { availablePlugins: Plugin[] installedPlugins: InstalledPlugin[] onRefresh: () => void onManualRefresh: () => void isRefreshing: boolean searchTerm: string setSearchTerm: (term: string) => void selectedCategory: string } const DashboardOverview: React.FC = ({ availablePlugins, installedPlugins, onRefresh, onManualRefresh, isRefreshing, searchTerm, setSearchTerm, selectedCategory, }) => { const [viewMode, setViewMode] = useState<"grid" | "list">("grid") const totalDownloads = "475.1M" // Placeholder const filteredPlugins = availablePlugins.filter((plugin) => { const matchesCategory = selectedCategory === "All" || (plugin.category || "Other") === selectedCategory const matchesSearch = plugin.name.toLowerCase().includes(searchTerm.toLowerCase()) || plugin.description.toLowerCase().includes(searchTerm.toLowerCase()) return matchesCategory && matchesSearch }) const handleInstall = async (pluginId: number) => { const promise = fetch("http://localhost:3001/api/plugins/install", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ plugin_id: pluginId }), }).then(async (response) => { const data = await response.json() if (response.ok) { onRefresh() return data.message } else { throw new Error(data.error || "Failed to install") } }) toast.promise(promise, { loading: "Installing plugin...", success: (message) => `Successfully installed: ${message}`, error: (err) => `Installation failed: ${err.message}`, }) } const handleUninstall = async (pluginId: number) => { if (!window.confirm("Are you sure you want to uninstall this plugin?")) return const promise = fetch(`http://localhost:3001/api/plugins/uninstall/${pluginId}`, { method: "DELETE", }).then(async (response) => { const data = await response.json() if (response.ok) { onRefresh() return data.message } else { throw new Error(data.error || "Failed to uninstall") } }) toast.promise(promise, { loading: "Uninstalling plugin...", success: (message) => `Successfully uninstalled: ${message}`, error: (err) => `Uninstallation failed: ${err.message}`, }) } const handleUpdate = async (pluginId: number) => { if (!window.confirm("Are you sure you want to update this plugin?")) return const promise = fetch("http://localhost:3001/api/plugins/update", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ plugin_id: pluginId }), }).then(async (response) => { const data = await response.json() if (response.ok) { onRefresh() return data.message } else { throw new Error(data.error || "Failed to update") } }) toast.promise(promise, { loading: "Updating plugin...", success: (message) => `Successfully updated: ${message}`, error: (err) => `Update failed: ${err.message}`, }) } return (

Package Registry

Discover and manage npm packages for your project

setSearchTerm(e.target.value)} />

Showing {filteredPlugins.length} packages in{" "} {selectedCategory}

{filteredPlugins.map((plugin) => { const installedPlugin = installedPlugins.find((p) => p.plugin_id === plugin.id) const isInstalled = !!installedPlugin const installedVersion = installedPlugin?.installed_version const isUpdateAvailable = isInstalled && installedVersion ? gt(plugin.version, installedVersion) : false const cardProps = { id: plugin.id, name: plugin.name, description: plugin.description || "No description available.", version: plugin.version, status: isInstalled ? (isUpdateAvailable ? "Update Available" : "Installed") : "Not Installed", isInstalled: isInstalled, installedVersion: installedVersion, onInstall: handleInstall, onUninstall: handleUninstall, onUpdate: handleUpdate, } return (
{viewMode === "grid" ? : }
) })}
) } export default DashboardOverview