From ce5b1f444ad7a8a9cdd770000f7a7ad48e9745ec Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Thu, 7 Dec 2023 00:33:05 -0500 Subject: [PATCH] updated links id page --- components/LinkCard.tsx | 38 ++++--------- components/Modal.tsx | 8 +-- components/ModalContent/DeleteLinkModal.tsx | 7 +++ layouts/LinkLayout.tsx | 60 +++++++++++++-------- lib/api/urlHandler.ts | 17 ++++++ pages/collections/index.tsx | 29 ---------- 6 files changed, 77 insertions(+), 82 deletions(-) diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx index 73e652f..f12fcb5 100644 --- a/components/LinkCard.tsx +++ b/components/LinkCard.tsx @@ -69,7 +69,7 @@ export default function LinkCard({ link, count, className }: Props) { ); }, [collections, links]); - const { removeLink, updateLink, getLink } = useLinkStore(); + const { removeLink, updateLink } = useLinkStore(); const pinLink = async () => { const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0]; @@ -87,23 +87,6 @@ export default function LinkCard({ link, count, className }: Props) { toast.success(`Link ${isAlreadyPinned ? "Unpinned!" : "Pinned!"}`); }; - 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 deleteLink = async () => { const load = toast.loading("Deleting..."); @@ -227,7 +210,7 @@ export default function LinkCard({ link, count, className }: Props) { > {link.url && url ? ( {link.url ? ( - { - e.stopPropagation(); + e.preventDefault(); + window.open(link.url || "", "_blank"); }} className="flex items-center gap-1 max-w-full w-fit text-neutral hover:opacity-60 duration-100" >

{shortendURL}

- + ) : (
{link.type}
)} - { - e.stopPropagation(); + e.preventDefault(); + router.push(`/collections/${link.collection.id}`); }} className="flex items-center gap-1 max-w-full w-fit hover:opacity-70 duration-100" > @@ -286,7 +268,7 @@ export default function LinkCard({ link, count, className }: Props) { style={{ color: collection?.color }} />

{collection?.name}

- +
diff --git a/components/Modal.tsx b/components/Modal.tsx index cf9ccdc..c7f4da5 100644 --- a/components/Modal.tsx +++ b/components/Modal.tsx @@ -11,12 +11,14 @@ type Props = { export default function Modal({ toggleModal, className, children }: Props) { return ( -
+
-
+
} className="absolute top-3 right-3 btn btn-sm outline-none btn-circle btn-ghost" diff --git a/components/ModalContent/DeleteLinkModal.tsx b/components/ModalContent/DeleteLinkModal.tsx index bb78396..ebbe5ae 100644 --- a/components/ModalContent/DeleteLinkModal.tsx +++ b/components/ModalContent/DeleteLinkModal.tsx @@ -11,6 +11,7 @@ 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"; type Props = { onClose: Function; @@ -24,6 +25,8 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) { const { removeLink } = useLinkStore(); const [submitLoader, setSubmitLoader] = useState(false); + const router = useRouter(); + useEffect(() => { setLink(activeLink); }, []); @@ -37,6 +40,10 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) { response.ok && toast.success(`Link Deleted.`); + if (router.pathname.startsWith("/links/[id]")) { + router.push("/dashboard"); + } + onClose(); }; diff --git a/layouts/LinkLayout.tsx b/layouts/LinkLayout.tsx index 97baf16..3a00f07 100644 --- a/layouts/LinkLayout.tsx +++ b/layouts/LinkLayout.tsx @@ -21,6 +21,9 @@ import { useSession } from "next-auth/react"; import useCollectionStore from "@/store/collections"; import EditLinkModal from "@/components/ModalContent/EditLinkModal"; import Link from "next/link"; +import PreservedFormatsModal from "@/components/ModalContent/PreservedFormatsModal"; +import toast from "react-hot-toast"; +import DeleteLinkModal from "@/components/ModalContent/DeleteLinkModal"; interface Props { children: ReactNode; @@ -75,7 +78,21 @@ export default function LinkLayout({ children }: Props) { setLinkCollection(collections.find((e) => e.id === link?.collection?.id)); }, [link, collections]); + const deleteLink = async () => { + const load = toast.loading("Deleting..."); + + const response = await removeLink(link?.id as number); + + toast.dismiss(load); + + response.ok && toast.success(`Link Deleted.`); + + router.push("/dashboard"); + }; + const [editLinkModal, setEditLinkModal] = useState(false); + const [deleteLinkModal, setDeleteLinkModal] = useState(false); + const [preservedFormatsModal, setPreservedFormatsModal] = useState(false); return ( <> @@ -118,9 +135,7 @@ export default function LinkLayout({ children }: Props) { ) ? (
{ - setEditLinkModal(true); - }} + onClick={() => setEditLinkModal(true)} className={`btn btn-ghost btn-square btn-sm`} > { - link - ? setModal({ - modal: "LINK", - state: true, - active: link, - method: "FORMATS", - }) - : undefined; - }} + onClick={() => setPreservedFormatsModal(true)} title="Preserved Formats" - className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} + className={`btn btn-ghost btn-square btn-sm`} >
@@ -155,18 +161,16 @@ export default function LinkLayout({ children }: Props) { (e) => e.userId === userId && e.canDelete ) ? (
{ - if (link?.id) { - removeLink(link.id); - router.back(); - } + onClick={(e) => { + (document?.activeElement as HTMLElement)?.blur(); + e.shiftKey ? deleteLink() : setDeleteLinkModal(true); }} title="Delete" - className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} + className={`btn btn-ghost btn-square btn-sm`} >
) : undefined} @@ -194,6 +198,18 @@ export default function LinkLayout({ children }: Props) { activeLink={link} /> ) : undefined} + {link && deleteLinkModal ? ( + setDeleteLinkModal(false)} + activeLink={link} + /> + ) : undefined} + {link && preservedFormatsModal ? ( + setPreservedFormatsModal(false)} + activeLink={link} + /> + ) : undefined}
); diff --git a/lib/api/urlHandler.ts b/lib/api/urlHandler.ts index 8795d76..e61d0ac 100644 --- a/lib/api/urlHandler.ts +++ b/lib/api/urlHandler.ts @@ -37,6 +37,23 @@ export default async function urlHandler( const content = await page.content(); + // TODO + // const session = await page.context().newCDPSession(page); + + // const doc = await session.send("Page.captureSnapshot", { + // format: "mhtml", + // }); + + // const saveDocLocally = (doc: any) => { + // console.log(doc); + // return createFile({ + // data: doc, + // filePath: `archives/${targetLink.collectionId}/${linkId}.mhtml`, + // }); + // }; + + // saveDocLocally(doc.data); + // Readability const window = new JSDOM("").window; diff --git a/pages/collections/index.tsx b/pages/collections/index.tsx index 16795fc..477d92d 100644 --- a/pages/collections/index.tsx +++ b/pages/collections/index.tsx @@ -44,35 +44,6 @@ export default function Collections() {

Collections you own

-
-
-
- -
-
    -
  • -
    { - (document?.activeElement as HTMLElement)?.blur(); - setNewCollectionModal(true); - }} - > - New Collection -
    -
  • -
-
-