el.xwx.moe/components/LinkList.tsx

156 lines
5.4 KiB
TypeScript
Raw Normal View History

2023-03-10 13:25:33 -06:00
import { ExtendedLink } from "@/types/global";
import {
faFolder,
faArrowUpRightFromSquare,
faEllipsis,
2023-03-22 18:11:54 -05:00
faStar,
faPenToSquare,
faTrashCan,
2023-03-10 13:25:33 -06:00
} from "@fortawesome/free-solid-svg-icons";
2023-03-10 23:10:10 -06:00
import { faFileImage, faFilePdf } from "@fortawesome/free-regular-svg-icons";
2023-03-10 13:25:33 -06:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useState } from "react";
2023-03-10 23:10:10 -06:00
import Image from "next/image";
2023-03-22 18:11:54 -05:00
import Dropdown from "./Dropdown";
2023-03-05 15:03:20 -06:00
export default function ({
link,
count,
}: {
2023-03-10 13:25:33 -06:00
link: ExtendedLink;
2023-03-05 15:03:20 -06:00
count: number;
}) {
2023-03-22 18:11:54 -05:00
const [editDropdown, setEditDropdown] = useState(false);
2023-03-10 13:25:33 -06:00
const [archiveLabel, setArchiveLabel] = useState("Archived Formats");
const shortendURL = new URL(link.url).host.toLowerCase();
const formattedDate = new Date(link.createdAt).toLocaleString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
2023-03-05 15:03:20 -06:00
return (
2023-03-10 23:10:10 -06:00
<div className="border border-sky-100 mb-5 bg-gray-100 p-5 rounded flex items-center gap-5 group/item">
<Image
src={`http://icons.duckduckgo.com/ip3/${shortendURL}.ico`}
width={100}
height={100}
alt=""
className="blur-sm opacity-80 group-hover/item:opacity-100 duration-100"
draggable="false"
/>
<div className="flex justify-between gap-5 w-full">
2023-03-10 13:25:33 -06:00
<div>
<div className="flex items-baseline gap-1">
<p className="text-sm text-sky-300 font-bold">{count + 1}.</p>
<p className="text-lg text-sky-600">{link.name}</p>
2023-03-22 18:11:54 -05:00
{link.starred ? (
<FontAwesomeIcon icon={faStar} className="w-3 text-amber-400" />
2023-03-10 23:10:10 -06:00
) : null}
2023-03-10 13:25:33 -06:00
</div>
<p className="text-sky-400 text-sm font-medium">{link.title}</p>
<div className="flex gap-3 items-center flex-wrap my-3">
2023-03-11 12:08:56 -06:00
<div className="flex items-center gap-1 cursor-pointer hover:opacity-80 duration-100">
2023-03-10 13:25:33 -06:00
<FontAwesomeIcon icon={faFolder} className="w-4 text-sky-300" />
<p className="text-sky-900">{link.collection.name}</p>
</div>
<div className="flex gap-1 items-center flex-wrap">
{link.tags.map((e, i) => (
<p
key={i}
2023-03-10 23:10:10 -06:00
className="px-2 py-1 bg-sky-200 text-sky-700 text-xs rounded-3xl cursor-pointer hover:bg-sky-100 duration-100"
2023-03-10 13:25:33 -06:00
>
# {e.name}
</p>
))}
</div>
</div>
2023-03-10 23:10:10 -06:00
<div className="flex gap-2 items-center flex-wrap">
2023-03-10 13:25:33 -06:00
<p className="text-gray-500">{formattedDate}</p>
2023-03-10 23:10:10 -06:00
<a href={link.url} target="_blank" className="group/url">
2023-03-10 13:25:33 -06:00
<div className="text-gray-500 font-bold flex items-center gap-1">
<p>{shortendURL}</p>
<FontAwesomeIcon
icon={faArrowUpRightFromSquare}
2023-03-10 23:10:10 -06:00
className="w-3 opacity-0 group-hover/url:opacity-100 duration-75"
2023-03-10 13:25:33 -06:00
/>
</div>
</a>
</div>
</div>
2023-03-22 18:11:54 -05:00
<div className="flex flex-col justify-between items-end relative">
2023-03-10 13:25:33 -06:00
<FontAwesomeIcon
icon={faEllipsis}
2023-03-22 18:11:54 -05:00
className="w-6 h-6 text-gray-500 hover:text-gray-400 duration-100 cursor-pointer"
onClick={() => setEditDropdown(!editDropdown)}
2023-03-10 13:25:33 -06:00
/>
<div>
<p className="text-center text-sky-500 text-sm font-bold">
{archiveLabel}
</p>
<div
className="flex justify-between mt-3 gap-3"
onMouseLeave={() => setArchiveLabel("Archived Formats")}
>
<a
href={`/api/archives/${link.collectionId}/${encodeURIComponent(
link.screenshotPath
)}`}
onMouseEnter={() => setArchiveLabel("Screenshot")}
2023-03-10 23:10:10 -06:00
target="_blank"
2023-03-10 13:25:33 -06:00
>
<FontAwesomeIcon
icon={faFileImage}
2023-03-10 23:10:10 -06:00
className="w-8 h-8 text-sky-600 cursor-pointer hover:text-sky-500 duration-100"
2023-03-10 13:25:33 -06:00
/>
</a>
<a
href={`/api/archives/${link.collectionId}/${encodeURIComponent(
link.pdfPath
)}`}
2023-03-10 23:10:10 -06:00
target="_blank"
2023-03-10 13:25:33 -06:00
onMouseEnter={() => setArchiveLabel("PDF")}
>
<FontAwesomeIcon
icon={faFilePdf}
2023-03-10 23:10:10 -06:00
className="w-8 h-8 text-sky-600 cursor-pointer hover:text-sky-500 duration-100"
2023-03-10 13:25:33 -06:00
/>
</a>
<FontAwesomeIcon
icon={faArrowUpRightFromSquare}
2023-03-10 23:10:10 -06:00
className="w-8 h-8 text-sky-600 cursor-pointer hover:text-sky-500 duration-100"
2023-03-11 12:08:56 -06:00
onMouseEnter={() => setArchiveLabel("Wayback Machine")}
2023-03-10 13:25:33 -06:00
/>
</div>
</div>
2023-03-22 18:11:54 -05:00
{editDropdown ? (
<Dropdown
items={[
{
name: "Star",
icon: <FontAwesomeIcon icon={faStar} />,
},
{
name: "Edit",
icon: <FontAwesomeIcon icon={faPenToSquare} />,
},
{
name: "Delete",
icon: <FontAwesomeIcon icon={faTrashCan} />,
},
]}
onClickOutside={() => setEditDropdown(!editDropdown)}
className="absolute top-8 right-0"
/>
) : null}
2023-03-10 13:25:33 -06:00
</div>
2023-03-05 15:03:20 -06:00
</div>
</div>
);
}