import { useEffect, useMemo } from "react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "./ui/accordion"; import { Progress } from "./ui/progress"; import { usePinning } from "~/hooks/usePinnning"; import { IPinningData } from "~/providers/PinningProvider"; import { Tabs, TabsTrigger, TabsList, TabsContent } from "./ui/tabs"; import { Button } from "./ui/button"; import { Cross2Icon } from "@radix-ui/react-icons"; export const PinningNetworkBanner = () => { const { cidList } = usePinning(); const itemsLeft = useMemo( () => cidList.filter((item) => item.progress < 100), [cidList], ); const completedItems = useMemo( () => cidList.filter((item) => item.progress === 100), [cidList], ); return (
{itemsLeft.length > 0 ? `${itemsLeft.length} left` : "Completed"} In Progress Completed {itemsLeft.length ? ( itemsLeft.map((cid) => ( )) ) : (
Nothing yet.
)}
{completedItems.length ? ( completedItems.map((cid) => ( )) ) : (
Nothing yet.
)}
); }; const PinCidItem = ({ item }: { item: IPinningData }) => { const { getProgress, onRemoveCidFromList } = usePinning(); useEffect(() => { if (item.progress < 100) { const intervalId = setInterval(() => { getProgress(item.cid); }, 1000); // Adjust the interval time (1000ms = 1 second) as needed return () => clearInterval(intervalId); // Clear interval on component unmount } }, [getProgress, item]); // Add dependencies to ensure the effect runs correctly return (
{item.cid} {item.progress}%
); };