import { useEffect, useRef, useState } from "react"; import { useMarketplace } from "../../hooks/useMarketplace"; import BrowsePane from "./BrowsePane"; import InstalledPane from "./InstalledPane"; import AccountsPane from "./AccountsPane"; const SUB_TABS = [ { id: "browse", label: "Browse" }, { id: "installed", label: "Installed" }, { id: "accounts", label: "Accounts" }, ] as const; export type MarketplaceSubTab = (typeof SUB_TABS)[number]["id"]; interface Props { active: boolean; } export default function MarketplaceView({ active }: Props) { const mp = useMarketplace(); const [tab, setTab] = useState("browse"); const { load } = mp; const wasActive = useRef(false); // Load (and refresh stale marketplaces) each time the tab comes to the front. useEffect(() => { if (active && !wasActive.current) void load({ refreshStale: true }); wasActive.current = active; }, [active, load]); return (
{SUB_TABS.map((t) => ( ))}
{tab === "browse" && } {tab === "installed" && } {tab === "accounts" && }
); }