2024-03-22 18:33:30 +00:00
|
|
|
import { useContext, useMemo } from "react";
|
2024-03-21 05:17:00 +00:00
|
|
|
import {
|
|
|
|
Accordion,
|
|
|
|
AccordionContent,
|
|
|
|
AccordionItem,
|
|
|
|
AccordionTrigger,
|
|
|
|
} from "./ui/accordion";
|
|
|
|
import { Progress } from "./ui/progress";
|
2024-03-22 13:54:46 +00:00
|
|
|
import { usePinning } from "~/hooks/usePinning";
|
2024-03-21 05:17:00 +00:00
|
|
|
import { Tabs, TabsTrigger, TabsList, TabsContent } from "./ui/tabs";
|
|
|
|
import { Button } from "./ui/button";
|
|
|
|
import { Cross2Icon } from "@radix-ui/react-icons";
|
2024-03-22 18:33:30 +00:00
|
|
|
import type { PinningStatus } from "~/data/pinning";
|
|
|
|
import { PinningContext } from "~/providers/PinningProvider";
|
2024-03-21 05:17:00 +00:00
|
|
|
|
|
|
|
export const PinningNetworkBanner = () => {
|
2024-03-22 18:33:30 +00:00
|
|
|
// const context = useContext(PinningContext);
|
2024-03-22 13:54:46 +00:00
|
|
|
const { data } = usePinning();
|
2024-03-21 05:17:00 +00:00
|
|
|
|
2024-03-22 03:15:56 +00:00
|
|
|
// TODO: Adapt to real API
|
2024-03-21 05:17:00 +00:00
|
|
|
const itemsLeft = useMemo(
|
2024-03-22 18:33:30 +00:00
|
|
|
() =>
|
|
|
|
data?.items.filter((item: PinningStatus) =>
|
|
|
|
item.status.includes("inprogress"),
|
|
|
|
) || [],
|
2024-03-22 03:15:56 +00:00
|
|
|
[data],
|
2024-03-21 05:17:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const completedItems = useMemo(
|
2024-03-22 18:33:30 +00:00
|
|
|
() =>
|
|
|
|
data?.items.filter((item: PinningStatus) =>
|
|
|
|
item.status.includes("completed"),
|
|
|
|
) || [],
|
2024-03-22 03:15:56 +00:00
|
|
|
[data],
|
2024-03-21 05:17:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2024-03-22 18:33:30 +00:00
|
|
|
className={`bg-background border border-border rounded-lg absolute w-1/3 bottom-4 right-4 ${
|
2024-03-22 03:15:56 +00:00
|
|
|
!data?.items.length ? "hidden" : "block"
|
2024-03-21 05:17:00 +00:00
|
|
|
}`}>
|
|
|
|
<Accordion type="single" defaultValue="item-1" collapsible>
|
|
|
|
<AccordionItem value="item-1">
|
|
|
|
<AccordionTrigger className="font-bold bg-primary px-4 rounded-tr-lg rounded-tl-lg">
|
2024-03-22 03:15:56 +00:00
|
|
|
{`${completedItems.length}/${data?.items.length} items completed`}
|
2024-03-21 05:17:00 +00:00
|
|
|
</AccordionTrigger>
|
|
|
|
<AccordionContent>
|
|
|
|
<Tabs className="w-full" defaultValue="inProgress">
|
|
|
|
<TabsList className="rounded-none">
|
|
|
|
<TabsTrigger value="inProgress">In Progress</TabsTrigger>
|
|
|
|
<TabsTrigger value="completed">Completed</TabsTrigger>
|
|
|
|
</TabsList>
|
|
|
|
<TabsContent value="inProgress">
|
|
|
|
{itemsLeft.length ? (
|
2024-03-22 03:15:56 +00:00
|
|
|
itemsLeft.map((item: PinningStatus) => (
|
|
|
|
<PinCidItem key={item.id} item={item} />
|
2024-03-21 05:17:00 +00:00
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<div className="text-primary-2 text-sm flex justify-center items-center h-10">
|
|
|
|
Nothing yet.
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="completed">
|
|
|
|
{completedItems.length ? (
|
2024-03-22 03:15:56 +00:00
|
|
|
completedItems.map((item: PinningStatus) => (
|
|
|
|
<PinCidItem key={item.id} item={item} />
|
2024-03-21 05:17:00 +00:00
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<div className="text-muted text-sm flex justify-center items-center h-10">
|
|
|
|
Nothing yet.
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</TabsContent>
|
|
|
|
</Tabs>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
|
|
</Accordion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-03-22 03:15:56 +00:00
|
|
|
const PinCidItem = ({ item }: { item: PinningStatus }) => {
|
2024-03-22 18:33:30 +00:00
|
|
|
const { unpin } = usePinning();
|
2024-03-21 05:17:00 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="px-4 mb-4">
|
2024-03-22 18:33:30 +00:00
|
|
|
<div className="relative flex flex-col items-center rounded-lg py-2 px-4 hover:bg-primary/50 group">
|
|
|
|
<div className="flex justify-between items-center w-full">
|
|
|
|
<span className="font-semibold">{item.id}</span>
|
|
|
|
<span className="group-hover:hidden">{item.progress}%</span>
|
2024-03-21 05:17:00 +00:00
|
|
|
<Button
|
|
|
|
variant="ghost"
|
2024-03-22 18:33:30 +00:00
|
|
|
className="absolute top-2 right-2 hidden group-hover:flex rounded-full h-3"
|
|
|
|
onClick={() =>
|
|
|
|
unpin({
|
|
|
|
cid: item.id,
|
|
|
|
})
|
|
|
|
}>
|
2024-03-21 05:17:00 +00:00
|
|
|
<Cross2Icon />
|
|
|
|
</Button>
|
|
|
|
</div>
|
2024-03-22 18:33:30 +00:00
|
|
|
<Progress value={item.progress} className="h-2" />
|
2024-03-21 05:17:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|