⚡️⚡️⚡️ 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
revert modal
daniel31x131360a03eb566
diff --git a/components/Drawer.tsx b/components/Drawer.tsxnew file mode 100644index 00000000..7400e44f--- /dev/null+++ b/components/Drawer.tsx@@ -0,0 +1,81 @@+import React, { ReactNode, useEffect } from "react";+import { Drawer as D } from "vaul";+import clsx from "clsx";++type Props = {+ toggleDrawer: Function;+ children: ReactNode;+ className?: string;+ dismissible?: boolean;+};++export default function Drawer({+ toggleDrawer,+ className,+ children,+ dismissible = true,+}: Props) {+ const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);++ useEffect(() => {+ if (window.innerWidth >= 640) {+ document.body.style.overflow = "hidden";+ document.body.style.position = "relative";+ return () => {+ document.body.style.overflow = "auto";+ document.body.style.position = "";+ };+ }+ }, []);++ if (window.innerWidth < 640) {+ return (+ <D.Root+ open={drawerIsOpen}+ onClose={() => dismissible && setDrawerIsOpen(false)}+ onAnimationEnd={(isOpen) => !isOpen && toggleDrawer()}+ dismissible={dismissible}+ >+ <D.Portal>+ <D.Overlay className="fixed inset-0 bg-black/40" />+ <D.Content className="flex flex-col rounded-t-2xl mt-24 fixed bottom-0 left-0 right-0 z-30 h-[90%] !select-auto focus:outline-none">+ <div+ className={clsx(+ "p-4 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto",+ className+ )}+ data-testid="mobile-modal-container"+ >+ <div data-testid="mobile-modal-slider" />+ {children}+ </div>+ </D.Content>+ </D.Portal>+ </D.Root>+ );+ } else {+ return (+ <D.Root+ open={drawerIsOpen}+ onClose={() => dismissible && setDrawerIsOpen(false)}+ onAnimationEnd={(isOpen) => !isOpen && toggleDrawer()}+ dismissible={dismissible}+ direction="right"+ >+ <D.Portal>+ <D.Overlay className="fixed inset-0 bg-black/10 z-20" />+ <D.Content className="bg-white flex flex-col h-full w-2/5 min-w-[30rem] mt-24 fixed bottom-0 right-0 z-40 !select-auto focus:outline-none">+ <div+ className={clsx(+ "p-4 bg-base-100 flex-1 border-neutral-content border-l overflow-y-auto",+ className+ )}+ >+ {children}+ </div>+ </D.Content>+ </D.Portal>+ </D.Root>+ );+ }+}diff --git a/components/LinkDetails.tsx b/components/LinkDetails.tsxindex fad065a5..f6790531 100644--- a/components/LinkDetails.tsx+++ b/components/LinkDetails.tsx@@ -1,4 +1,4 @@-import React, { useEffect, useMemo, useRef, useState } from "react";+import React, { useEffect, useState } from "react";import {LinkIncludingShortenedCollectionAndTags,ArchivedFormat,@@ -8,8 +8,10 @@ import {atLeastOneFormatAvailable,formatAvailable,} from "@/lib/shared/formatStats";+import PreservedFormatRow from "@/components/PreserverdFormatRow";import getPublicUserData from "@/lib/client/getPublicUserData";import { useTranslation } from "next-i18next";+import { BeatLoader } from "react-spinners";import { useUser } from "@/hooks/store/user";import { useGetLink, useUpdateLink, useUpdateFile } from "@/hooks/store/links";import LinkIcon from "./LinkViews/LinkComponents/LinkIcon";@@ -27,10 +29,6 @@ import IconPopover from "./IconPopover";import TextInput from "./TextInput";import usePermissions from "@/hooks/usePermissions";import oklchVariableToHex from "@/lib/client/oklchVariableToHex";-import Preservation from "./Preservation/Preservation";-import useWindowDimensions from "@/hooks/useWindowDimensions";-import PreservedFormatRow from "./PreserverdFormatRow";-import { BeatLoader } from "react-spinners";type Props = {className?: string;@@ -38,25 +36,17 @@ type Props = {standalone?: boolean;mode?: "view" | "edit";setMode?: Function;- onClose?: Function;onUpdateArchive?: Function;- activeMode?: "view" | "edit";- onDelete?: Function;- onPin?: Function;};export default function LinkDetails({className,activeLink,standalone,- onClose,+ mode = "view",+ setMode,onUpdateArchive,- activeMode,- onDelete,- onPin,}: Props) {- const [mode, setMode] = useState<"view" | "edit">(activeMode || "view");-const [link, setLink] =useState<LinkIncludingShortenedCollectionAndTags>(activeLink);@@ -66,14 +56,6 @@ export default function LinkDetails({const permissions = usePermissions(link.collection.id as number);- const { width } = useWindowDimensions();-- const iconTriggerRef = useRef<HTMLDivElement>(null);- const [iconPopoverPosition, setIconPopoverPosition] = useState<{- top: number;- left: number;- } | null>(null);-const { t } = useTranslation();const getLink = useGetLink();const { data: user = {} } = useUser();@@ -111,15 +93,15 @@ export default function LinkDetails({fetchOwner();}, [link.collection.ownerId]);- const isReady = useMemo(() => {+ const isReady = () => {return (- ((collectionOwner.archiveAsScreenshot === true ? link.pdf : true) &&- (collectionOwner.archiveAsMonolith === true ? link.monolith : true) &&- (collectionOwner.archiveAsPDF === true ? link.pdf : true) &&- link.readable) ||- !link.url+ link &&+ (collectionOwner.archiveAsScreenshot === true ? link.pdf : true) &&+ (collectionOwner.archiveAsMonolith === true ? link.monolith : true) &&+ (collectionOwner.archiveAsPDF === true ? link.pdf : true) &&+ link.readable);- }, [link, collectionOwner]);+ };useEffect(() => {(async () => {@@ -130,7 +112,7 @@ export default function LinkDetails({let interval: any;- if (!isReady) {+ if (!isReady()) {interval = setInterval(async () => {await getLink.mutateAsync({id: link.id as number,@@ -199,626 +181,485 @@ export default function LinkDetails({const [iconPopover, setIconPopover] = useState(false);return (- <div className={clsx(className)}>+ <div className={clsx(className)} data-vaul-no-drag><divclassName={clsx(- standalone && "sm:flex h-screen w-screen",- !standalone && "sm:flex sm:h-[80vh]"+ standalone && "sm:border sm:border-neutral-content sm:rounded-2xl p-5")}>- {width >= 640 && atLeastOneFormatAvailable(link) && (- <div className="w-1/2 lg:w-2/3 overflow-y-auto">- {link.id && (- <Preservation- link={link}- standalone={standalone || false}- isReady={!!isReady}- />- )}- </div>- )}<divclassName={clsx(- "sm:overflow-y-auto",- atLeastOneFormatAvailable(link) && "sm:w-1/2 lg:w-1/3"+ "overflow-hidden select-none relative group h-40 opacity-80",+ standalone+ ? "sm:max-w-xl -mx-5 -mt-5 sm:rounded-t-2xl"+ : "-mx-4 -mt-4")}>- {setMode && onClose && (- <div className={clsx("flex justify-center -mb-11 pt-3 relative")}>- {(permissions === true || permissions?.canUpdate) &&- !isPublicRoute && (- <div className="flex gap-1 h-8 rounded-full bg-neutral-content bg-opacity-50 text-base-content p-1 text-xs duration-100 select-none z-10">- <div- className={clsx(- "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold",- mode === "view" && "bg-primary bg-opacity-50"- )}- onClick={() => {- setMode("view");- }}- >- {t("view")}- </div>- <div- className={clsx(- "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold",- mode === "edit" && "bg-primary bg-opacity-50"- )}- onClick={() => {- setMode("edit");- }}- >- {t("edit")}- </div>- </div>- )}+ {formatAvailable(link, "preview") ? (+ <Image+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true&updatedAt=${link.updatedAt}`}+ width={1280}+ height={720}+ alt=""+ className="object-cover scale-105 object-center h-full"+ style={{+ filter: "blur(1px)",+ }}+ onError={(e) => {+ const target = e.target as HTMLElement;+ target.style.display = "none";+ }}+ />+ ) : link.preview === "unavailable" ? (+ <div className="bg-gray-50 duration-100 h-40"></div>+ ) : (+ <div className="duration-100 h-40 skeleton rounded-none"></div>+ )}- <div- className="btn btn-sm btn-circle text-base-content opacity-50 hover:opacity-100 z-10 absolute right-3"- onClick={() => {- onClose();- }}- >- <i title="Close" className="bi-x text-xl" />+ {!standalone &&+ (permissions === true || permissions?.canUpdate) &&+ !isPublicRoute && (+ <div className="absolute top-0 bottom-0 left-0 right-0 opacity-0 group-hover:opacity-100 duration-100 flex justify-end items-end">+ <label className="btn btn-xs mb-2 mr-3 opacity-50 hover:opacity-100">+ {t("upload_banner")}+ <input+ type="file"+ accept="image/jpg, image/jpeg, image/png"+ onChange={async (e) => {+ const file = e.target.files?.[0];+ if (!file) return;++ const load = toast.loading(t("updating"));++ await updateFile.mutateAsync(+ {+ linkId: link.id as number,+ file,+ },+ {+ onSettled: (data, error) => {+ toast.dismiss(load);++ if (error) {+ toast.error(error.message);+ } else {+ toast.success(t("updated"));+ setLink({ updatedAt: data.updatedAt, ...link });+ }+ },+ }+ );+ }}+ className="hidden"+ />+ </label></div>- </div>- )}- <div- className={clsx(- "overflow-hidden select-none relative group/banner h-40 opacity-80 -mt-5 sm:mt-0",- !standalone &&- "-mx-5 sm:mx-0 rounded-t-2xl sm:rounded-tr-2xl sm:rounded-tl-none")}- >- {formatAvailable(link, "preview") ? (- <Image- src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true&updatedAt=${link.updatedAt}`}- width={1280}- height={720}- alt=""- className="object-cover object-center h-full"- style={{- filter: "blur(1px)",- }}- onError={(e) => {- const target = e.target as HTMLElement;- target.style.display = "none";+ </div>++ {!standalone &&+ (permissions === true || permissions?.canUpdate) &&+ !isPublicRoute ? (+ <div className="-mt-14 ml-8 relative w-fit pb-2">+ <div className="tooltip tooltip-bottom" data-tip={t("change_icon")}>+ <LinkIcon+ link={link}+ className="hover:bg-opacity-70 duration-100 cursor-pointer"+ onClick={() => setIconPopover(true)}+ />+ </div>+ {iconPopover && (+ <IconPopover+ color={link.color || oklchVariableToHex("--p")}+ setColor={(color: string) => setLink({ ...link, color })}+ weight={(link.iconWeight || "regular") as IconWeight}+ setWeight={(iconWeight: string) =>+ setLink({ ...link, iconWeight })+ }+ iconName={link.icon as string}+ setIconName={(icon: string) => setLink({ ...link, icon })}+ reset={() =>+ setLink({+ ...link,+ color: "",+ icon: "",+ iconWeight: "",+ })+ }+ className="top-12"+ onClose={() => {+ setIconPopover(false);+ submit();}}/>- ) : link.preview === "unavailable" ? (- <div className="bg-gray-50 duration-100 h-40"></div>- ) : (- <div className="duration-100 h-40 skeleton rounded-none"></div>)}-- {!standalone &&- (permissions === true || permissions?.canUpdate) &&- !isPublicRoute && (- <div- className={clsx(- "absolute top-0 bottom-0 left-0 right-0 opacity-0 group-hover/banner:opacity-100 duration-100 flex justify-end items-end"- )}- >- <label className="btn btn-xs mb-2 mr-3 opacity-50 hover:opacity-100">- {t("upload_banner")}- <input- type="file"- accept="image/jpg, image/jpeg, image/png"- onChange={async (e) => {- const file = e.target.files?.[0];- if (!file) return;-- const load = toast.loading(t("updating"));-- await updateFile.mutateAsync(- {- linkId: link.id as number,- file,- isPreview: true,- },- {- onSettled: (data, error) => {- toast.dismiss(load);-- if (error) {- toast.error(error.message);- } else {- toast.success(t("updated"));- setLink({- updatedAt: data.response.updatedAt,- ...link,- });- }- },- }- );- }}- className="hidden"- />- </label>- </div>- )}</div>+ ) : (+ <div className="-mt-14 ml-8 relative w-fit pb-2">+ <LinkIcon link={link} onClick={() => setIconPopover(true)} />+ </div>+ )}- {!standalone &&- (permissions === true || permissions?.canUpdate) &&- !isPublicRoute ? (- <div className="-mt-14 ml-8 relative w-fit pb-2">- <div- className="tooltip tooltip-bottom"- ref={iconTriggerRef}- data-tip={t("change_icon")}+ <div className="max-w-xl sm:px-8 p-5 pb-8 pt-2">+ {mode === "view" && (+ <div className="text-xl mt-2 pr-7">+ <p+ className={clsx("relative w-fit", !link.name && "text-neutral")}>- <LinkIcon- link={link}- className="hover:bg-opacity-70 duration-100 cursor-pointer"- onClick={() => {- if (iconTriggerRef.current) {- const rect =- iconTriggerRef.current.getBoundingClientRect();- if (width >= 640) {- setIconPopoverPosition({- top: rect.bottom + window.scrollY,- left: rect.left + rect.width / 2 + window.scrollX, // center of LinkIcon- });- } else {- setIconPopoverPosition({- top: rect.bottom + window.scrollY,- left: rect.left + window.scrollX,- });- }- }- setIconPopover(true);- }}- />- </div>- {iconPopover && iconPopoverPosition && (- <IconPopover- color={link.color || oklchVariableToHex("--p")}- setColor={(color: string) => setLink({ ...link, color })}- weight={(link.iconWeight || "regular") as IconWeight}- setWeight={(iconWeight: string) =>- setLink({ ...link, iconWeight })- }- iconName={link.icon as string}- setIconName={(icon: string) => setLink({ ...link, icon })}- reset={() =>- setLink({- ...link,- color: "",- icon: "",- iconWeight: "",- })- }- className={clsx("sm:-translate-x-1/2")}- top={width >= 640 ? iconPopoverPosition.top : undefined}- left={width >= 640 ? iconPopoverPosition.left : undefined}- onClose={() => {- setIconPopover(false);- submit();- }}- />- )}- </div>- ) : (- <div className="-mt-14 ml-8 relative w-fit pb-2">- <LinkIcon link={link} onClick={() => setIconPopover(true)} />+ {unescapeString(link.name) || t("untitled")}+ </p></div>)}- <div className={clsx("pb-8 pt-2 p-3", width < 640 && "sm:px-8")}>- {mode === "view" ? (- <div className="text-xl mt-2 pr-7">- <p- className={clsx(- "relative w-fit",- !link.name ? "text-neutral" : "text-primary"- )}- >- {unescapeString(link.name) || t("untitled")}+ {mode === "edit" && (+ <>+ <br />++ <div>+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">+ {t("name")}</p>+ <TextInput+ value={link.name}+ onChange={(e) => setLink({ ...link, name: e.target.value })}+ placeholder={t("placeholder_example_link")}+ className="bg-base-200"+ /></div>- ) : (- <>- <br />-- <div>- <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">- {t("name")}- </p>- <TextInput- value={link.name}- onChange={(e) => setLink({ ...link, name: e.target.value })}- placeholder={t("placeholder_example_link")}- className="bg-base-200"- />- </div>- </>- )}-- {mode === "view" && !standalone && (- <>- <br />-- <div className={clsx("flex gap-3")}>- <div- title={t("open_modal_new_tab")}- className="text-center bg-base-200 p-2 rounded-md cursor-pointer duration-100 hover:bg-base-300 active:scale-95 select-none text-2xl w-full"- onClick={() => {- window.open("/links/" + link.id, "_blank");- }}- >- <i className="bi-box-arrow-up-right"></i>- </div>- {onPin && (- <div- title={t("pin_to_dashboard")}- className="text-center bg-base-200 p-2 rounded-md cursor-pointer duration-100 hover:bg-base-300 active:scale-95 select-none text-2xl w-full"- onClick={() => {- onPin();- }}- >- {link?.pinnedBy && link.pinnedBy[0] ? (- <i className="bi-pin-fill"></i>- ) : (- <i className="bi-pin"></i>- )}- </div>- )}- {(permissions === true || permissions?.canDelete) &&- onDelete &&- onClose && (- <div- title={t("delete")}- className="text-center bg-base-200 p-2 rounded-md cursor-pointer duration-100 hover:bg-base-300 active:scale-95 select-none text-2xl w-full"- onClick={() => {- onDelete();- onClose();- }}- >- <i className="bi-trash"></i>- </div>- )}- </div>- </>- )}+ </>+ )}- {link.url && mode === "view" ? (- <>- <br />+ {link.url && mode === "view" ? (+ <>+ <br />- <p className="text-sm mb-2 text-neutral">{t("link")}</p>+ <p className="text-sm mb-2 text-neutral">{t("link")}</p>- <div className="relative">- <div className="rounded-md p-2 bg-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14">- <Link href={link.url} title={link.url} target="_blank">- {link.url}- </Link>- <div className="absolute right-0 px-2 bg-base-200">- <CopyButton text={link.url} />- </div>+ <div className="relative">+ <div className="rounded-md p-2 bg-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14">+ <Link href={link.url} title={link.url} target="_blank">+ {link.url}+ </Link>+ <div className="absolute right-0 px-2 bg-base-200">+ <CopyButton text={link.url} /></div></div>- </>- ) : activeLink.url ? (- <>- <br />-- <div>- <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">- {t("link")}- </p>- <TextInput- value={link.url || ""}- onChange={(e) => setLink({ ...link, url: e.target.value })}- placeholder={t("placeholder_example_link")}- className="bg-base-200"- />- </div>- </>- ) : undefined}- <br />- <div className="relative">- <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">- {t("collection")}- </p>+ </div>+ </>+ ) : activeLink.url ? (+ <>+ <br />- {mode === "view" ? (- <div className="relative">- <Link- href={- isPublicRoute- ? `/public/collections/${link.collection.id}`- : `/collections/${link.collection.id}`- }- className="rounded-md p-2 bg-base-200 border border-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14"- >- <p>{link.collection.name}</p>- <div className="absolute right-0 px-2 bg-base-200">- {link.collection.icon ? (- <Icon- icon={link.collection.icon}- size={30}- weight={- (link.collection.iconWeight ||- "regular") as IconWeight- }- color={link.collection.color}- />- ) : (- <i- className="bi-folder-fill text-2xl"- style={{ color: link.collection.color }}- ></i>- )}- </div>- </Link>- </div>- ) : (- <CollectionSelection- onChange={setCollection}- defaultValue={- link.collection.id- ? {- value: link.collection.id,- label: link.collection.name,- }- : {- value: null as unknown as number,- label: "Unorganized",- }- }- creatable={false}+ <div>+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">+ {t("link")}+ </p>+ <TextInput+ value={link.url || ""}+ onChange={(e) => setLink({ ...link, url: e.target.value })}+ placeholder={t("placeholder_example_link")}+ className="bg-base-200"/>- )}- </div>- <br />- <div className="relative">- <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">- {t("tags")}- </p>+ </div>+ </>+ ) : undefined}- {mode === "view" ? (- <div className="flex gap-2 flex-wrap rounded-md p-2 bg-base-200 border border-base-200 w-full text-xs">- {link.tags && link.tags[0] ? (- link.tags.map((tag) =>- isPublicRoute ? (- <div- key={tag.id}- className="bg-base-200 p-1 hover:bg-neutral-content rounded-md duration-100"- >- {tag.name}- </div>- ) : (- <Link- href={"/tags/" + tag.id}- key={tag.id}- className="bg-base-200 p-1 hover:bg-neutral-content btn btn-xs btn-ghost rounded-md"- >- {tag.name}- </Link>- )- )- ) : (- <div className="text-neutral text-base">{t("no_tags")}</div>- )}- </div>- ) : (- <TagSelection- onChange={setTags}- defaultValue={link.tags.map((e) => ({- label: e.name,- value: e.id,- }))}- />- )}- </div>- <br />- <div className="relative">- <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">- {t("description")}- </p>+ <br />- {mode === "view" ? (- <div className="rounded-md p-2 bg-base-200 hyphens-auto">- {link.description ? (- <p>{link.description}</p>- ) : (- <p className="text-neutral">- {t("no_description_provided")}- </p>- )}- </div>- ) : (- <textarea- value={unescapeString(link.description) as string}- onChange={(e) =>- setLink({ ...link, description: e.target.value })+ <div className="relative">+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">+ {t("collection")}+ </p>++ {mode === "view" ? (+ <div className="relative">+ <Link+ href={+ isPublicRoute+ ? `/public/collections/${link.collection.id}`+ : `/collections/${link.collection.id}`}- placeholder={t("link_description_placeholder")}- className="resize-none w-full rounded-md p-2 h-32 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"- />- )}- </div>- {mode === "view" && (- <div>- <br />+ className="rounded-md p-2 bg-base-200 border border-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14"+ >+ <p>{link.collection.name}</p>+ <div className="absolute right-0 px-2 bg-base-200">+ {link.collection.icon ? (+ <Icon+ icon={link.collection.icon}+ size={30}+ weight={+ (link.collection.iconWeight ||+ "regular") as IconWeight+ }+ color={link.collection.color}+ />+ ) : (+ <i+ className="bi-folder-fill text-2xl"+ style={{ color: link.collection.color }}+ ></i>+ )}+ </div>+ </Link>+ </div>+ ) : (+ <CollectionSelection+ onChange={setCollection}+ defaultValue={+ link.collection.id+ ? { value: link.collection.id, label: link.collection.name }+ : { value: null as unknown as number, label: "Unorganized" }+ }+ creatable={false}+ />+ )}+ </div>- <div className="flex gap-1 items-center mb-2">- <p- className="text-sm text-neutral"- title={t("available_formats")}- >- {link.url ? t("preserved_formats") : t("content")}- </p>+ <br />- {onUpdateArchive &&- link.type === "url" &&- (permissions === true || permissions?.canUpdate) &&- !isPublicRoute && (+ <div className="relative">+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">+ {t("tags")}+ </p>++ {mode === "view" ? (+ <div className="flex gap-2 flex-wrap rounded-md p-2 bg-base-200 border border-base-200 w-full text-xs">+ {link.tags && link.tags[0] ? (+ link.tags.map((tag) =>+ isPublicRoute ? (<div- className="tooltip tooltip-bottom"- data-tip={t("refresh_preserved_formats")}+ key={tag.id}+ className="bg-base-200 p-1 hover:bg-neutral-content rounded-md duration-100">- <button- className="btn btn-xs btn-ghost btn-square text-neutral"- onClick={() => onUpdateArchive()}- >- <i className="bi-arrow-clockwise text-sm" />- </button>+ {tag.name}</div>- )}- </div>+ ) : (+ <Link+ href={"/tags/" + tag.id}+ key={tag.id}+ className="bg-base-200 p-1 hover:bg-neutral-content btn btn-xs btn-ghost rounded-md"+ >+ {tag.name}+ </Link>+ )+ )+ ) : (+ <div className="text-neutral text-base">{t("no_tags")}</div>+ )}+ </div>+ ) : (+ <TagSelection+ onChange={setTags}+ defaultValue={link.tags.map((e) => ({+ label: e.name,+ value: e.id,+ }))}+ />+ )}+ </div>- <div className={`flex flex-col rounded-md p-3 bg-base-200`}>- {formatAvailable(link, "monolith") ? (- <>- <PreservedFormatRow- name={t("webpage")}- icon={"bi-filetype-html"}- format={ArchivedFormat.monolith}- link={link}- downloadable={true}- />- <hr className="m-3 border-t border-neutral-content" />- </>- ) : undefined}-- {formatAvailable(link, "image") ? (- <>- <PreservedFormatRow- name={t("screenshot")}- icon={"bi-file-earmark-image"}- format={- link?.image?.endsWith("png")- ? ArchivedFormat.png- : ArchivedFormat.jpeg- }- link={link}- downloadable={true}- />- <hr className="m-3 border-t border-neutral-content" />- </>- ) : undefined}-- {formatAvailable(link, "pdf") ? (- <>- <PreservedFormatRow- name={t("pdf")}- icon={"bi-file-earmark-pdf"}- format={ArchivedFormat.pdf}- link={link}- downloadable={true}- />- <hr className="m-3 border-t border-neutral-content" />- </>- ) : undefined}-- {formatAvailable(link, "readable") ? (- <>- <PreservedFormatRow- name={t("readable")}- icon={"bi-file-earmark-text"}- format={ArchivedFormat.readability}- link={link}- />- <hr className="m-3 border-t border-neutral-content" />- </>- ) : undefined}+ <br />- {!isReady ? (- <div- className={`w-full h-full flex flex-col justify-center p-10`}- >- <BeatLoader- color="oklch(var(--p))"- className="mx-auto mb-3"- size={30}- />+ <div className="relative">+ <p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">+ {t("description")}+ </p>- <p className="text-center text-2xl">- {t("preservation_in_queue")}- </p>- <p className="text-center text-lg">- {t("check_back_later")}- </p>- </div>- ) : link.url && !isReady ? (+ {mode === "view" ? (+ <div className="rounded-md p-2 bg-base-200 hyphens-auto">+ {link.description ? (+ <p>{link.description}</p>+ ) : (+ <p className="text-neutral">{t("no_description_provided")}</p>+ )}+ </div>+ ) : (+ <textarea+ value={unescapeString(link.description) as string}+ onChange={(e) =>+ setLink({ ...link, description: e.target.value })+ }+ placeholder={t("link_description_placeholder")}+ className="resize-none w-full rounded-md p-2 h-32 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"+ />+ )}+ </div>++ {mode === "view" && (+ <div>+ <br />++ <div className="flex gap-1 items-center mb-2">+ <p+ className="text-sm text-neutral"+ title={t("available_formats")}+ >+ {link.url ? t("preserved_formats") : t("content")}+ </p>++ {onUpdateArchive &&+ (permissions === true || permissions?.canUpdate) &&+ !isPublicRoute && (<div- className={`w-full h-full flex flex-col justify-center p-5`}+ className="tooltip tooltip-bottom"+ data-tip={t("refresh_preserved_formats")}>- <BeatLoader- color="oklch(var(--p))"- className="mx-auto mb-3"- size={20}- />- <p className="text-center">- {t("there_are_more_formats")}- </p>- <p className="text-center text-sm">- {t("check_back_later")}- </p>+ <button+ className="btn btn-xs btn-ghost btn-square text-neutral"+ onClick={() => onUpdateArchive()}+ >+ <i className="bi-arrow-clockwise text-sm" />+ </button></div>- ) : undefined}-- {link.url && (- <Link- href={`https://web.archive.org/web/${link?.url?.replace(- /(^\w+:|^)\/\//,- ""- )}`}- target="_blank"- className="text-neutral text-center mx-auto duration-100 opacity-100 hover:opacity-60 text-sm"- >- <p>- {t("view_latest_snapshot")}- <span>- {" "}- <i className="bi-box-arrow-up-right" />- </span>- </p>- </Link>)}- </div></div>- )}- {mode === "view" ? (- <>- <br />-- <p className="text-neutral text-xs text-center">- {t("saved")}{" "}- {new Date(link.createdAt || "").toLocaleDateString("en-US", {- month: "short",- day: "numeric",- year: "numeric",- })}{" "}- at{" "}- {new Date(link.createdAt || "").toLocaleTimeString("en-US", {- hour: "numeric",- minute: "numeric",- })}- </p>- </>- ) : (- <>- <br />- <div className="flex justify-end items-center">- <button- className={clsx(- "btn btn-accent text-white",- JSON.stringify(activeLink) === JSON.stringify(link)- ? "btn-disabled"- : "dark:border-violet-400"- )}- onClick={submit}++ <div className={`flex flex-col rounded-md p-3 bg-base-200`}>+ {formatAvailable(link, "monolith") ? (+ <>+ <PreservedFormatRow+ name={t("webpage")}+ icon={"bi-filetype-html"}+ format={ArchivedFormat.monolith}+ link={link}+ downloadable={true}+ />+ <hr className="m-3 border-t border-neutral-content" />+ </>+ ) : undefined}++ {formatAvailable(link, "image") ? (+ <>+ <PreservedFormatRow+ name={t("screenshot")}+ icon={"bi-file-earmark-image"}+ format={+ link?.image?.endsWith("png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg+ }+ link={link}+ downloadable={true}+ />+ <hr className="m-3 border-t border-neutral-content" />+ </>+ ) : undefined}++ {formatAvailable(link, "pdf") ? (+ <>+ <PreservedFormatRow+ name={t("pdf")}+ icon={"bi-file-earmark-pdf"}+ format={ArchivedFormat.pdf}+ link={link}+ downloadable={true}+ />+ <hr className="m-3 border-t border-neutral-content" />+ </>+ ) : undefined}++ {formatAvailable(link, "readable") ? (+ <>+ <PreservedFormatRow+ name={t("readable")}+ icon={"bi-file-earmark-text"}+ format={ArchivedFormat.readability}+ link={link}+ />+ <hr className="m-3 border-t border-neutral-content" />+ </>+ ) : undefined}++ {!isReady() && !atLeastOneFormatAvailable(link) ? (+ <div+ className={`w-full h-full flex flex-col justify-center p-10`}>- {t("save_changes")}- </button>- </div>- </>- )}- </div>+ <BeatLoader+ color="oklch(var(--p))"+ className="mx-auto mb-3"+ size={30}+ />++ <p className="text-center text-2xl">+ {t("preservation_in_queue")}+ </p>+ <p className="text-center text-lg">+ {t("check_back_later")}+ </p>+ </div>+ ) : link.url &&+ !isReady() &&+ atLeastOneFormatAvailable(link) ? (+ <div+ className={`w-full h-full flex flex-col justify-center p-5`}+ >+ <BeatLoader+ color="oklch(var(--p))"+ className="mx-auto mb-3"+ size={20}+ />+ <p className="text-center">{t("there_are_more_formats")}</p>+ <p className="text-center text-sm">+ {t("check_back_later")}+ </p>+ </div>+ ) : undefined}++ {link.url && (+ <Link+ href={`https://web.archive.org/web/${link?.url?.replace(+ /(^\w+:|^)\/\//,+ ""+ )}`}+ target="_blank"+ className="text-neutral mx-auto duration-100 hover:opacity-60 flex gap-2 w-1/2 justify-center items-center text-sm"+ >+ <p className="whitespace-nowrap">+ {t("view_latest_snapshot")}+ </p>+ <i className="bi-box-arrow-up-right" />+ </Link>+ )}+ </div>+ </div>+ )}++ {mode === "view" ? (+ <>+ <br />++ <p className="text-neutral text-xs text-center">+ {t("saved")}{" "}+ {new Date(link.createdAt || "").toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year: "numeric",+ })}{" "}+ at{" "}+ {new Date(link.createdAt || "").toLocaleTimeString("en-US", {+ hour: "numeric",+ minute: "numeric",+ })}+ </p>+ </>+ ) : (+ <>+ <br />+ <div className="flex justify-end items-center">+ <button+ className={clsx(+ "btn btn-accent text-white",+ JSON.stringify(activeLink) === JSON.stringify(link)+ ? "btn-disabled"+ : "dark:border-violet-400"+ )}+ onClick={submit}+ >+ {t("save_changes")}+ </button>+ </div>+ </>+ )}</div></div></div>diff --git a/components/Modal.tsx b/components/Modal.tsxindex c2d645cb..00ed7e43 100644--- a/components/Modal.tsx+++ b/components/Modal.tsx@@ -1,7 +1,6 @@import React, { MouseEventHandler, ReactNode, useEffect } from "react";import ClickAwayHandler from "@/components/ClickAwayHandler";import { Drawer } from "vaul";-import clsx from "clsx";import useWindowDimensions from "@/hooks/useWindowDimensions";type Props = {@@ -9,10 +8,6 @@ type Props = {children: ReactNode;className?: string;dismissible?: boolean;- linkModal?: {- state: boolean;- size: "full" | "half";- };};export default function Modal({@@ -20,10 +15,8 @@ export default function Modal({className,children,dismissible = true,- linkModal,}: Props) {const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);-const { width } = useWindowDimensions();useEffect(() => {@@ -47,17 +40,16 @@ export default function Modal({><Drawer.Portal><Drawer.Overlay className="fixed inset-0 bg-black/40" />- <Drawer.Content className="flex flex-col rounded-t-2xl h-[90%] mt-24 fixed bottom-0 left-0 right-0 z-30 outline-none">+ <Drawer.Content className="flex flex-col rounded-t-2xl h-[90%] mt-24 fixed bottom-0 left-0 right-0 z-30"><divclassName="p-4 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto"data-testid="mobile-modal-container">- {!linkModal?.state && (- <div- className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5"- data-testid="mobile-modal-slider"- />- )}+ <div+ className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5"+ data-testid="mobile-modal-slider"+ />+{children}</div></Drawer.Content>@@ -72,24 +64,15 @@ export default function Modal({><ClickAwayHandleronClickOutside={() => dismissible && toggleModal()}- className={clsx(- "w-full mt-auto sm:m-auto",- linkModal?.state && linkModal.size === "full"- ? "sm:w-[80vw] sm:h-[80vh]"- : "sm:w-11/12 sm:max-w-2xl",- className- )}+ className={`w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl ${+ className || ""+ }`}><div- className={clsx(- "slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl bg-base-100",- linkModal?.state- ? "h-full overflow-hidden"- : "overflow-y-auto sm:overflow-y-visible p-5"- )}+ className="slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl p-5 bg-base-100 overflow-y-auto sm:overflow-y-visible"data-testid="modal-container">- {dismissible && !linkModal?.state && (+ {dismissible && (<divonClick={toggleModal as MouseEventHandler<HTMLDivElement>}className="absolute top-4 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"diff --git a/components/ModalContent/LinkModal.tsx b/components/ModalContent/LinkModal.tsxindex 6d86ae58..c3793ac1 100644--- a/components/ModalContent/LinkModal.tsx+++ b/components/ModalContent/LinkModal.tsx@@ -1,7 +1,15 @@+import React, { useState } from "react";import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";+import { useTranslation } from "next-i18next";+import { useDeleteLink } from "@/hooks/store/links";+import Drawer from "../Drawer";import LinkDetails from "../LinkDetails";-import Modal from "../Modal";-import { atLeastOneFormatAvailable } from "@/lib/shared/formatStats";+import Link from "next/link";+import usePermissions from "@/hooks/usePermissions";+import { useRouter } from "next/router";+import { dropdownTriggerer } from "@/lib/client/utils";+import toast from "react-hot-toast";+import clsx from "clsx";type Props = {onClose: Function;@@ -20,23 +28,159 @@ export default function LinkModal({link,activeMode,}: Props) {+ const { t } = useTranslation();++ const permissions = usePermissions(link.collection.id as number);++ const router = useRouter();++ const isPublicRoute = router.pathname.startsWith("/public") ? true : false;++ const deleteLink = useDeleteLink();++ const [mode, setMode] = useState<"view" | "edit">(activeMode || "view");+return (- <Modal- toggleModal={onClose}- linkModal={{- state: true,- size: atLeastOneFormatAvailable(link) ? "full" : "half",- }}+ <Drawer+ toggleDrawer={onClose}+ className="sm:h-screen items-center relative">- <LinkDetails- activeLink={link}- className="sm:mt-0 -mt-11"- onUpdateArchive={onUpdateArchive}- onClose={onClose}- activeMode={activeMode}- onDelete={onDelete}- onPin={onPin}- />- </Modal>+ <div className="absolute top-3 left-0 right-0 flex justify-between px-3">+ <div+ className="bi-x text-xl btn btn-sm btn-circle text-base-content opacity-50 hover:opacity-100 z-10"+ onClick={() => onClose()}+ ></div>++ {(permissions === true || permissions?.canUpdate) && !isPublicRoute && (+ <div className="flex gap-1 h-8 rounded-full bg-neutral-content bg-opacity-50 text-base-content p-1 text-xs duration-100 select-none z-10">+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold",+ mode === "view" && "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setMode("view");+ }}+ >+ View+ </div>+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold",+ mode === "edit" && "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setMode("edit");+ }}+ >+ Edit+ </div>+ </div>+ )}++ <div className="flex gap-2">+ {!isPublicRoute && (+ <div className={`dropdown dropdown-end z-20`}>+ <div+ tabIndex={0}+ role="button"+ onMouseDown={dropdownTriggerer}+ className="btn btn-sm btn-circle text-base-content opacity-50 hover:opacity-100 z-10"+ >+ <i 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`}+ >+ {+ <li>+ <div+ role="button"+ tabIndex={0}+ onClick={() => {+ (document?.activeElement as HTMLElement)?.blur();+ onPin();+ }}+ className="whitespace-nowrap"+ >+ {link?.pinnedBy && link.pinnedBy[0]+ ? t("unpin")+ : t("pin_to_dashboard")}+ </div>+ </li>+ }+ {link.type === "url" &&+ (permissions === true || permissions?.canUpdate) && (+ <li>+ <div+ role="button"+ tabIndex={0}+ onClick={() => {+ (document?.activeElement as HTMLElement)?.blur();+ onUpdateArchive();+ }}+ className="whitespace-nowrap"+ >+ {t("refresh_preserved_formats")}+ </div>+ </li>+ )}+ {(permissions === true || permissions?.canDelete) && (+ <li>+ <div+ role="button"+ tabIndex={0}+ onClick={async (e) => {+ (document?.activeElement as HTMLElement)?.blur();+ console.log(e.shiftKey);+ if (e.shiftKey) {+ const load = toast.loading(t("deleting"));++ await deleteLink.mutateAsync(link.id as number, {+ onSettled: (data, error) => {+ toast.dismiss(load);++ if (error) {+ toast.error(error.message);+ } else {+ toast.success(t("deleted"));+ }+ },+ });+ onClose();+ } else {+ onDelete();+ onClose();+ }+ }}+ className="whitespace-nowrap"+ >+ {t("delete")}+ </div>+ </li>+ )}+ </ul>+ </div>+ )}+ {link.url && (+ <Link+ href={link.url}+ target="_blank"+ className="bi-box-arrow-up-right btn-circle text-base-content opacity-50 hover:opacity-100 btn btn-sm select-none z-10"+ ></Link>+ )}+ </div>+ </div>++ <div className="w-full">+ <LinkDetails+ activeLink={link}+ className="sm:mt-0 -mt-11"+ mode={mode}+ setMode={(mode: "view" | "edit") => setMode(mode)}+ onUpdateArchive={onUpdateArchive}+ />+ </div>+ </Drawer>);}diff --git a/pages/api/v1/archives/[linkId].ts b/pages/api/v1/archives/[linkId].tsindex a8e054db..aefddc62 100644--- a/pages/api/v1/archives/[linkId].ts+++ b/pages/api/v1/archives/[linkId].ts@@ -13,11 +13,7 @@ import { UsersAndCollections } from "@prisma/client";import { UploadFileSchema } from "@/lib/shared/schemaValidation";import isDemoMode from "@/lib/api/isDemoMode";import getSuffixFromFormat from "@/lib/shared/getSuffixFromFormat";-import DOMPurify from "dompurify";-import { formatAvailable } from "@/lib/shared/formatStats";import { ArchivedFormat } from "@/types/global";-import getLinkTypeFromFormat from "@/lib/shared/getLinkTypeFromFormat";-import handleReadability from "@/lib/api/preservationScheme/handleReadability";export const config = {api: {@@ -233,7 +229,6 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {"image/png","image/jpg","image/jpeg",- "text/plain",];const fileBuffer = validateFile(files.file[0],@@ -253,15 +248,6 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {const { mimetype } = files.file[0];const isPDF = mimetype?.includes("pdf");const isImage = mimetype?.includes("image");- const isReadable = mimetype?.includes("text");-- if (isReadable) {- await handleReadability(fileBuffer.toString(), link, true);-- fs.unlinkSync(files.file[0].filepath);-- return res.status(200).json({ response: files });- }console.log("isPDF", isPDF);@@ -291,7 +277,6 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {pdf: isPDF? `archives/${collectionPermissions.id}/${linkId + suffix}`: undefined,- contentEdited: isReadable ? new Date().toISOString() : undefined,updatedAt: new Date().toISOString(),},});diff --git a/pages/links/[id].tsx b/pages/links/[id].tsxindex 6d43b8c0..bb697698 100644--- a/pages/links/[id].tsx+++ b/pages/links/[id].tsx@@ -19,9 +19,13 @@ const Index = () => {return (<div className="flex h-screen">{getLink.data ? (- <LinkDetails activeLink={getLink.data} standalone />+ <LinkDetails+ activeLink={getLink.data}+ className="sm:max-w-xl sm:m-auto sm:p-5 w-full"+ standalone+ />) : (- <div className="sm:max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">+ <div className="max-w-xl p-5 m-auto w-full flex flex-col items-center gap-5"><div className="w-20 h-20 skeleton rounded-xl"></div><div className="w-full h-10 skeleton rounded-xl"></div><div className="w-full h-10 skeleton rounded-xl"></div>diff --git a/pages/public/links/[id].tsx b/pages/public/links/[id].tsxindex 535561f5..6a340b35 100644--- a/pages/public/links/[id].tsx+++ b/pages/public/links/[id].tsx@@ -19,11 +19,11 @@ const Index = () => {{getLink.data ? (<LinkDetailsactiveLink={getLink.data}- className="sm:w-[80vw] sm:h-[80vh] sm:m-auto w-screen"+ className="sm:max-w-xl sm:m-auto sm:p-5 w-full"standalone/>) : (- <div className="sm:max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">+ <div className="max-w-xl p-5 m-auto w-full flex flex-col items-center gap-5"><div className="w-20 h-20 skeleton rounded-xl"></div><div className="w-full h-10 skeleton rounded-xl"></div><div className="w-full h-10 skeleton rounded-xl"></div>diff --git a/prisma/migrations/20250303224623_remove_field/migration.sql b/prisma/migrations/20250303224623_remove_field/migration.sqlnew file mode 100644index 00000000..351d97f0--- /dev/null+++ b/prisma/migrations/20250303224623_remove_field/migration.sql@@ -0,0 +1,8 @@+/*+ Warnings:++ - You are about to drop the column `contentEdited` on the `Link` table. All the data in the column will be lost.++*/+-- AlterTable+ALTER TABLE "Link" DROP COLUMN "contentEdited";diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex a584592d..8c1f002f 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -169,7 +169,6 @@ model Link {pdf String?readable String?monolith String?- contentEdited DateTime?aiTagged Boolean @default(false)indexVersion Int?lastPreserved DateTime?