⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
update link action icons
Yee Jia Weie910172558f0
diff --git a/components/LinkViews/LinkComponents/LinkActions.tsx b/components/LinkViews/LinkComponents/LinkActions.tsxindex 9f53a058..5bd18c0e 100644--- a/components/LinkViews/LinkComponents/LinkActions.tsx+++ b/components/LinkViews/LinkComponents/LinkActions.tsx@@ -4,8 +4,6 @@ import {LinkIncludingShortenedCollectionAndTags,} from "@/types/global";import usePermissions from "@/hooks/usePermissions";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import { faEllipsis } from "@fortawesome/free-solid-svg-icons";import EditLinkModal from "@/components/ModalContent/EditLinkModal";import DeleteLinkModal from "@/components/ModalContent/DeleteLinkModal";import PreservedFormatsModal from "@/components/ModalContent/PreservedFormatsModal";@@ -13,15 +11,13 @@ import useLinkStore from "@/store/links";import { toast } from "react-hot-toast";import useAccountStore from "@/store/account";-export default function LinkActions({- link,- collection,- position,-}: {+type Props = {link: LinkIncludingShortenedCollectionAndTags;collection: CollectionIncludingMembersAndLinkCount;position?: string;-}) {+}++export default function LinkActions({ link, collection, position }: Props) {const permissions = usePermissions(link.collection.id as number);const [editLinkModal, setEditLinkModal] = useState(false);@@ -46,7 +42,7 @@ export default function LinkActions({toast.dismiss(load);response.ok &&- toast.success(`Link ${isAlreadyPinned ? "Unpinned!" : "Pinned!"}`);+ toast.success(`Link ${isAlreadyPinned ? "Unpinned!" : "Pinned!"}`);};const deleteLink = async () => {@@ -74,14 +70,10 @@ export default function LinkActions({role="button"className="btn btn-ghost btn-sm btn-square text-neutral">- <FontAwesomeIcon- icon={faEllipsis}- title="More"- className="w-5 h-5"- id={"expand-dropdown" + collection.id}- />+ <i id={"expand-dropdown" + collection.id} title="More" className="bi-three-dots text-xl"/></div>- <ul className="dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1">+ <ul+ className="dropdown-content z-[20] menu shadow bg-base-200 border border-neutral-content rounded-box w-44 mr-1">{permissions === true ? (<li><divdiff --git a/components/ModalContent/DeleteLinkModal.tsx b/components/ModalContent/DeleteLinkModal.tsxindex dea90ab5..370e61e2 100644--- a/components/ModalContent/DeleteLinkModal.tsx+++ b/components/ModalContent/DeleteLinkModal.tsx@@ -1,15 +1,7 @@import React, { useEffect, useState } from "react";-import { Toaster } from "react-hot-toast";-import CollectionSelection from "@/components/InputSelect/CollectionSelection";-import TagSelection from "@/components/InputSelect/TagSelection";-import TextInput from "@/components/TextInput";-import unescapeString from "@/lib/client/unescapeString";import useLinkStore from "@/store/links";import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";import toast from "react-hot-toast";-import Link from "next/link";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import { faLink, faTrashCan } from "@fortawesome/free-solid-svg-icons";import Modal from "../Modal";import { useRouter } from "next/router";@@ -57,19 +49,7 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) {<p>Are you sure you want to delete this Link?</p><div role="alert" className="alert alert-warning">- <svg- xmlns="http://www.w3.org/2000/svg"- className="stroke-current shrink-0 h-6 w-6"- fill="none"- viewBox="0 0 24 24"- >- <path- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="2"- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"- />- </svg>+ <i className="bi-exclamation-triangle text-xl"/><span><b>Warning:</b> This action is irreversible!</span>@@ -84,7 +64,7 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) {className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer`}onClick={deleteLink}>- <FontAwesomeIcon icon={faTrashCan} className="h-5" />+ <i className="bi-trash text-xl"/>Delete</button></div>diff --git a/components/ModalContent/EditLinkModal.tsx b/components/ModalContent/EditLinkModal.tsxindex 94e2ce8e..bb43efda 100644--- a/components/ModalContent/EditLinkModal.tsx+++ b/components/ModalContent/EditLinkModal.tsx@@ -1,5 +1,4 @@import React, { useEffect, useState } from "react";-import { Toaster } from "react-hot-toast";import CollectionSelection from "@/components/InputSelect/CollectionSelection";import TagSelection from "@/components/InputSelect/TagSelection";import TextInput from "@/components/TextInput";@@ -8,8 +7,6 @@ import useLinkStore from "@/store/links";import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";import toast from "react-hot-toast";import Link from "next/link";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import { faLink } from "@fortawesome/free-solid-svg-icons";import Modal from "../Modal";type Props = {@@ -89,10 +86,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {title={link.url}target="_blank">- <FontAwesomeIcon- icon={faLink}- className="mt-1 w-5 h-5 min-w-[1.25rem]"- />+ <i className="bi-link-45deg text-xl"/><p>{shortendURL}</p></Link>) : undefined}@@ -122,13 +116,13 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {defaultValue={link.collection.id? {- value: link.collection.id,- label: link.collection.name,- }+ value: link.collection.id,+ label: link.collection.name,+ }: {- value: null as unknown as number,- label: "Unorganized",- }+ value: null as unknown as number,+ label: "Unorganized",+ }}/>) : null}diff --git a/components/ModalContent/PreservedFormatsModal.tsx b/components/ModalContent/PreservedFormatsModal.tsxindex 964dab5a..73f6cc8b 100644--- a/components/ModalContent/PreservedFormatsModal.tsx+++ b/components/ModalContent/PreservedFormatsModal.tsx@@ -1,32 +1,13 @@import React, { useEffect, useState } from "react";import useLinkStore from "@/store/links";-import {- ArchivedFormat,- LinkIncludingShortenedCollectionAndTags,-} from "@/types/global";+import { ArchivedFormat, LinkIncludingShortenedCollectionAndTags, } from "@/types/global";import toast from "react-hot-toast";import Link from "next/link";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import {- faArrowUpRightFromSquare,- faCloudArrowDown,- faLink,- faTrashCan,- faUpRightFromSquare,-} from "@fortawesome/free-solid-svg-icons";import Modal from "../Modal";-import {- faFileImage,- faFileLines,- faFilePdf,-} from "@fortawesome/free-regular-svg-icons";import { useRouter } from "next/router";import { useSession } from "next-auth/react";-import {- pdfAvailable,- readabilityAvailable,- screenshotAvailable,-} from "@/lib/shared/getArchiveValidity";+import { pdfAvailable, readabilityAvailable, screenshotAvailable, } from "@/lib/shared/getArchiveValidity";+import PreservedFormatRow from "@/components/PreserverdFormatRow";type Props = {onClose: Function;@@ -92,25 +73,6 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {} else toast.error(data.response);};- const handleDownload = (format: ArchivedFormat) => {- const path = `/api/v1/archives/${link?.id}?format=${format}`;- fetch(path)- .then((response) => {- if (response.ok) {- // Create a temporary link and click it to trigger the download- const link = document.createElement("a");- link.href = path;- link.download = format === ArchivedFormat.png ? "Screenshot" : "PDF";- link.click();- } else {- console.error("Failed to download file");- }- })- .catch((error) => {- console.error("Error:", error);- });- };-return (<Modal toggleModal={onClose}><p className="text-xl font-thin">Preserved Formats</p>@@ -129,112 +91,18 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {<div className={`flex flex-col gap-3`}>{readabilityAvailable(link) ? (- <div className="flex justify-between items-center pr-1 border border-neutral-content rounded-md">- <div className="flex gap-2 items-center">- <div className="bg-primary text-primary-content p-2 rounded-l-md">- <FontAwesomeIcon icon={faFileLines} className="w-6 h-6" />- </div>-- <p>Readable</p>- </div>-- <div className="flex gap-1">- {/* <div- onClick={() => handleDownload(ArchivedFormat.pdf)}- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faCloudArrowDown}- className="w-5 h-5 cursor-pointer text-neutral"- />- </div> */}-- <Link- href={`/preserved/${link?.id}?format=${ArchivedFormat.readability}`}- target="_blank"- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faArrowUpRightFromSquare}- className="w-5 h-5 text-neutral"- />- </Link>- </div>- </div>+ <PreservedFormatRow name={'Readable'} icon={'bi-file-earmark-text'} format={ArchivedFormat.readability}+ activeLink={link}/>) : undefined}{screenshotAvailable(link) ? (- <div className="flex justify-between items-center pr-1 border border-neutral-content rounded-md">- <div className="flex gap-2 items-center">- <div className="bg-primary text-primary-content p-2 rounded-l-md">- <FontAwesomeIcon icon={faFileImage} className="w-6 h-6" />- </div>-- <p>Screenshot</p>- </div>-- <div className="flex gap-1">- <div- onClick={() => handleDownload(ArchivedFormat.png)}- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faCloudArrowDown}- className="w-5 h-5 cursor-pointer text-neutral"- />- </div>-- <Link- href={`/api/v1/archives/${link?.id}?format=${- link.screenshotPath?.endsWith("png")- ? ArchivedFormat.png- : ArchivedFormat.jpeg- }`}- target="_blank"- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faUpRightFromSquare}- className="w-5 h-5 text-neutral"- />- </Link>- </div>- </div>+ <PreservedFormatRow name={'Screenshot'} icon={'bi-file-earmark-image'} format={ArchivedFormat.png}+ activeLink={link} downloadable={true}/>) : undefined}{pdfAvailable(link) ? (- <div className="flex justify-between items-center pr-1 border border-neutral-content rounded-md">- <div className="flex gap-2 items-center">- <div className="bg-primary text-primary-content p-2 rounded-l-md">- <FontAwesomeIcon icon={faFilePdf} className="w-6 h-6" />- </div>-- <p>PDF</p>- </div>-- <div className="flex gap-1">- <div- onClick={() => handleDownload(ArchivedFormat.pdf)}- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faCloudArrowDown}- className="w-5 h-5 cursor-pointer text-neutral"- />- </div>-- <Link- href={`/api/v1/archives/${link?.id}?format=${ArchivedFormat.pdf}`}- target="_blank"- className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"- >- <FontAwesomeIcon- icon={faArrowUpRightFromSquare}- className="w-5 h-5 text-neutral"- />- </Link>- </div>- </div>+ <PreservedFormatRow name={'PDF'} icon={'bi-file-earmark-pdf'} format={ArchivedFormat.pdf}+ activeLink={link} downloadable={true}/>) : undefined}<div className="flex flex-col-reverse sm:flex-row sm:gap-3 items-center justify-center">@@ -272,10 +140,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {<p className="whitespace-nowrap">View latest snapshot on archive.org</p>- <FontAwesomeIcon- icon={faArrowUpRightFromSquare}- className="w-4 h-4"- />+ <i className="bi-box-arrow-up-right"/></Link></div></div>diff --git a/components/PreserverdFormatRow.tsx b/components/PreserverdFormatRow.tsxnew file mode 100644index 00000000..499e4488--- /dev/null+++ b/components/PreserverdFormatRow.tsx@@ -0,0 +1,137 @@+import React, { useEffect, useState } from "react";+import useLinkStore from "@/store/links";+import {+ ArchivedFormat,+ LinkIncludingShortenedCollectionAndTags,+} from "@/types/global";+import toast from "react-hot-toast";+import Link from "next/link";+import { useRouter } from "next/router";+import { useSession } from "next-auth/react";++type Props = {+ name: string,+ icon: string,+ format: ArchivedFormat,+ activeLink: LinkIncludingShortenedCollectionAndTags,+ downloadable?: boolean,+};++export default function PreservedFormatRow({ name, icon, format, activeLink, downloadable }: Props) {+ const session = useSession();+ const { getLink } = useLinkStore();++ const [link, setLink] =+ useState<LinkIncludingShortenedCollectionAndTags>(activeLink);++ const router = useRouter();++ useEffect(() => {+ let isPublicRoute = router.pathname.startsWith("/public")+ ? true+ : undefined;++ (async () => {+ const data = await getLink(link.id as number, isPublicRoute);+ setLink(+ (data as any).response as LinkIncludingShortenedCollectionAndTags+ );+ })();++ let interval: any;+ if (link?.screenshotPath === "pending" || link?.pdfPath === "pending") {+ interval = setInterval(async () => {+ const data = await getLink(link.id as number, isPublicRoute);+ setLink(+ (data as any).response as LinkIncludingShortenedCollectionAndTags+ );+ }, 5000);+ } else {+ if (interval) {+ clearInterval(interval);+ }+ }++ return () => {+ if (interval) {+ clearInterval(interval);+ }+ };+ }, [link?.screenshotPath, link?.pdfPath, link?.readabilityPath]);++ const updateArchive = async () => {+ const load = toast.loading("Sending request...");++ const response = await fetch(`/api/v1/links/${link?.id}/archive`, {+ method: "PUT",+ });++ const data = await response.json();++ toast.dismiss(load);++ if (response.ok) {+ toast.success(`Link is being archived...`);+ getLink(link?.id as number);+ } else toast.error(data.response);+ };++ const handleDownload = () => {+ const path = `/api/v1/archives/${link?.id}?format=${format}`;+ fetch(path)+ .then((response) => {+ if (response.ok) {+ // Create a temporary link and click it to trigger the download+ const link = document.createElement("a");+ link.href = path;+ link.download = format === ArchivedFormat.png ? "Screenshot" : "PDF";+ link.click();+ } else {+ console.error("Failed to download file");+ }+ })+ .catch((error) => {+ console.error("Error:", error);+ });+ };++ return (+ <div className="flex justify-between items-center pr-1 border border-neutral-content rounded-md">+ <div className="flex gap-2 items-center">+ <div className="bg-primary text-primary-content p-2 rounded-l-md">+ <i className={`${icon} text-2xl`}/>+ </div>+ <p>{name}</p>+ </div>++ <div className="flex gap-1">+ {downloadable || false ? (+ <div+ onClick={() => handleDownload()}+ className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"+ >+ <i className="bi-cloud-arrow-down text-xl text-neutral"/>+ </div>+ ) : undefined}++ <Link+ href={+ `${+ format === ArchivedFormat.readability+ ? `/preserved/${link?.id}?format=${format}`+ : `/api/v1/archives/${link?.id}?format=${+ link.screenshotPath?.endsWith("png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg+ }`+ }`+ }+ target="_blank"+ className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"+ >+ <i className="bi-box-arrow-up-right text-xl text-neutral"/>+ </Link>+ </div>+ </div>+ );+}