⚡️⚡️⚡️ 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
feat: quick look at the preserved formats
daniel31x13848e0bf50efd
diff --git a/components/LinkDetails.tsx b/components/LinkDetails.tsxindex f83fbb0c..4acf799a 100644--- a/components/LinkDetails.tsx+++ b/components/LinkDetails.tsx@@ -4,7 +4,10 @@ import {ArchivedFormat,} from "@/types/global";import Link from "next/link";-import { formatAvailable } from "@/lib/shared/getArchiveValidity";+import {+ atLeastOneFormatAvailable,+ formatAvailable,+} from "@/lib/shared/formatStats";import PreservedFormatRow from "@/components/PreserverdFormatRow";import getPublicUserData from "@/lib/client/getPublicUserData";import { useTranslation } from "next-i18next";@@ -104,15 +107,6 @@ export default function LinkDetails({);};- const atLeastOneFormatAvailable = () => {- return (- formatAvailable(link, "image") ||- formatAvailable(link, "pdf") ||- formatAvailable(link, "readable") ||- formatAvailable(link, "monolith")- );- };-useEffect(() => {(async () => {await getLink.mutateAsync({@@ -580,7 +574,7 @@ export default function LinkDetails({</>) : undefined}- {!isReady() && !atLeastOneFormatAvailable() ? (+ {!isReady() && !atLeastOneFormatAvailable(link) ? (<divclassName={`w-full h-full flex flex-col justify-center p-10`}>@@ -597,7 +591,9 @@ export default function LinkDetails({{t("check_back_later")}</p></div>- ) : link.url && !isReady() && atLeastOneFormatAvailable() ? (+ ) : link.url &&+ !isReady() &&+ atLeastOneFormatAvailable(link) ? (<divclassName={`w-full h-full flex flex-col justify-center p-5`}>diff --git a/components/LinkViews/LinkComponents/LinkCard.tsx b/components/LinkViews/LinkComponents/LinkCard.tsxindex d598ca84..75b94359 100644--- a/components/LinkViews/LinkComponents/LinkCard.tsx+++ b/components/LinkViews/LinkComponents/LinkCard.tsx@@ -10,7 +10,10 @@ import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";import Image from "next/image";-import { formatAvailable } from "@/lib/shared/getArchiveValidity";+import {+ atLeastOneFormatAvailable,+ formatAvailable,+} from "@/lib/shared/formatStats";import LinkIcon from "./LinkIcon";import useOnScreen from "@/hooks/useOnScreen";import { generateLinkHref } from "@/lib/client/generateLinkHref";@@ -24,6 +27,7 @@ import { useGetLink, useLinks } from "@/hooks/store/links";import { useRouter } from "next/router";import useLocalSettingsStore from "@/store/localSettings";import LinkPin from "./LinkPin";+import LinkFormats from "./LinkFormats";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -199,6 +203,13 @@ export default function LinkCard({ link, columns, editMode }: Props) {<LinkIcon link={link} /></div>)}+ {show.preserved_formats &&+ link.type === "url" &&+ atLeastOneFormatAvailable(link) && (+ <div className="absolute bottom-0 right-0 m-2 bg-base-200 bg-opacity-60 px-1 rounded-md">+ <LinkFormats link={link} />+ </div>+ )}</div><hr className="divider my-0 border-t border-neutral-content h-[1px]" /></div>diff --git a/components/LinkViews/LinkComponents/LinkFormats.tsx b/components/LinkViews/LinkComponents/LinkFormats.tsxnew file mode 100644index 00000000..3b6321f4--- /dev/null+++ b/components/LinkViews/LinkComponents/LinkFormats.tsx@@ -0,0 +1,95 @@+import { formatAvailable } from "@/lib/shared/formatStats";+import {+ ArchivedFormat,+ LinkIncludingShortenedCollectionAndTags,+} from "@/types/global";+import { useTranslation } from "next-i18next";+import Link from "next/link";+import { useRouter } from "next/router";++export default function LinkFormats({+ link,+}: {+ link: LinkIncludingShortenedCollectionAndTags;+}) {+ const { t } = useTranslation();++ const router = useRouter();++ let isPublic = router.pathname.startsWith("/public") ? true : undefined;++ return (+ <div className="flex gap-1 text-neutral">+ {formatAvailable(link, "monolith") && (+ <Link+ href={`${isPublic ? "/public" : ""}/preserved/${link?.id}?format=${+ ArchivedFormat.monolith+ }`}+ target="_blank"+ onClick={(e) => {+ e.stopPropagation();+ }}+ className="hover:opacity-70 duration-100"+ >+ <i+ className="bi-filetype-html text-md leading-none"+ title={t("webpage")}+ ></i>+ </Link>+ )}+ {formatAvailable(link, "image") && (+ <Link+ href={`${isPublic ? "/public" : ""}/preserved/${link?.id}?format=${+ link?.image?.endsWith("png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg+ }`}+ target="_blank"+ onClick={(e) => {+ e.stopPropagation();+ }}+ className="hover:opacity-70 duration-100"+ >+ <i+ className="bi-file-earmark-image text-md leading-none"+ title={t("image")}+ ></i>+ </Link>+ )}+ {formatAvailable(link, "pdf") && (+ <Link+ href={`${isPublic ? "/public" : ""}/preserved/${link?.id}?format=${+ ArchivedFormat.pdf+ }`}+ target="_blank"+ onClick={(e) => {+ e.stopPropagation();+ }}+ className="hover:opacity-70 duration-100"+ >+ <i+ className="bi-file-earmark-pdf text-md leading-none"+ title={t("pdf")}+ ></i>+ </Link>+ )}+ {formatAvailable(link, "readable") && (+ <Link+ href={`${isPublic ? "/public" : ""}/preserved/${link?.id}?format=${+ ArchivedFormat.readability+ }`}+ target="_blank"+ onClick={(e) => {+ e.stopPropagation();+ }}+ className="hover:opacity-70 duration-100"+ >+ <i+ className="bi-file-earmark-text text-md leading-none"+ title={t("readable")}+ ></i>+ </Link>+ )}+ </div>+ );+}diff --git a/components/LinkViews/LinkComponents/LinkIcon.tsx b/components/LinkViews/LinkComponents/LinkIcon.tsxindex 4def762a..6d00c258 100644--- a/components/LinkViews/LinkComponents/LinkIcon.tsx+++ b/components/LinkViews/LinkComponents/LinkIcon.tsx@@ -20,7 +20,8 @@ export default function LinkIcon({}) {let iconClasses: string = clsx("rounded flex item-center justify-center shadow select-none z-10 w-12 h-12",- !hideBackground && "rounded-md backdrop-blur-xl bg-opacity-50 p-1",+ !hideBackground &&+ "rounded-md backdrop-blur-xl bg-white/30 dark:bg-black/30 bg-opacity-50 p-1",className);diff --git a/components/LinkViews/LinkComponents/LinkList.tsx b/components/LinkViews/LinkComponents/LinkList.tsxindex 3b4e46b3..1fa60b38 100644--- a/components/LinkViews/LinkComponents/LinkList.tsx+++ b/components/LinkViews/LinkComponents/LinkList.tsx@@ -21,6 +21,8 @@ import { useLinks } from "@/hooks/store/links";import useLocalSettingsStore from "@/store/localSettings";import LinkPin from "./LinkPin";import { useRouter } from "next/router";+import { atLeastOneFormatAvailable } from "@/lib/shared/formatStats";+import LinkFormats from "./LinkFormats";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -123,9 +125,18 @@ export default function LinkCardCompact({ link, editMode }: Props) {<div className="w-[calc(100%-56px)] ml-2">{show.name && (- <p className="line-clamp-1 mr-8 text-primary select-none">- {unescapeString(link.name)}- </p>+ <div className="flex gap-1 mr-20">+ <p className="truncate text-primary">+ {unescapeString(link.name)}+ </p>+ {show.preserved_formats &&+ link.type === "url" &&+ atLeastOneFormatAvailable(link) && (+ <div className="pl-1 inline-block text-lg">+ <LinkFormats link={link} />+ </div>+ )}+ </div>)}<div className="mt-1 flex flex-col sm:flex-row sm:items-center gap-2 text-xs text-neutral">diff --git a/components/LinkViews/LinkComponents/LinkMasonry.tsx b/components/LinkViews/LinkComponents/LinkMasonry.tsxindex 19030238..5438d7ec 100644--- a/components/LinkViews/LinkComponents/LinkMasonry.tsx+++ b/components/LinkViews/LinkComponents/LinkMasonry.tsx@@ -10,7 +10,10 @@ import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";import Image from "next/image";-import { formatAvailable } from "@/lib/shared/getArchiveValidity";+import {+ atLeastOneFormatAvailable,+ formatAvailable,+} from "@/lib/shared/formatStats";import Link from "next/link";import LinkIcon from "./LinkIcon";import useOnScreen from "@/hooks/useOnScreen";@@ -26,6 +29,7 @@ import useLocalSettingsStore from "@/store/localSettings";import clsx from "clsx";import LinkPin from "./LinkPin";import { useRouter } from "next/router";+import LinkFormats from "./LinkFormats";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -196,9 +200,16 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {<div className="p-3 flex flex-col gap-2 h-full min-h-14">{show.name && (- <p className="hyphens-auto w-full text-primary text-sm">+ <div className="hyphens-auto w-full text-primary text-sm">{unescapeString(link.name)}- </p>+ {show.preserved_formats &&+ link.type === "url" &&+ atLeastOneFormatAvailable(link) && (+ <div className="pl-1 inline-block">+ <LinkFormats link={link} />+ </div>+ )}+ </div>)}{show.link && <LinkTypeBadge link={link} />}diff --git a/components/LinkViews/LinkComponents/LinkTypeBadge.tsx b/components/LinkViews/LinkComponents/LinkTypeBadge.tsxindex 5a47c683..c985ec17 100644--- a/components/LinkViews/LinkComponents/LinkTypeBadge.tsx+++ b/components/LinkViews/LinkComponents/LinkTypeBadge.tsx@@ -1,6 +1,5 @@import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";import Link from "next/link";-import React from "react";export default function LinkTypeBadge({link,@@ -17,6 +16,17 @@ export default function LinkTypeBadge({}}+ const typeIcon = () => {+ switch (link.type) {+ case "pdf":+ return "bi-file-earmark-pdf";+ case "image":+ return "bi-file-earmark-image";+ default:+ return "bi-link-45deg";+ }+ };+return link.url && shortendURL ? (<Linkhref={link.url || ""}@@ -31,6 +41,9 @@ export default function LinkTypeBadge({<p className="text-xs truncate">{shortendURL}</p></Link>) : (- <div className="badge badge-primary badge-sm select-none">{link.type}</div>+ <div className="flex gap-1 item-center select-none text-neutral duration-100 max-w-full w-fit">+ <i className={typeIcon() + ` text-md leading-none`}></i>+ <p className="text-xs truncate">{link.type}</p>+ </div>);}diff --git a/components/ReadableView.tsx b/components/ReadableView.tsxindex 6c36b65b..c4a59857 100644--- a/components/ReadableView.tsx+++ b/components/ReadableView.tsx@@ -1,5 +1,5 @@import unescapeString from "@/lib/client/unescapeString";-import { formatAvailable } from "@/lib/shared/getArchiveValidity";+import { formatAvailable } from "@/lib/shared/formatStats";import isValidUrl from "@/lib/shared/isValidUrl";import {ArchivedFormat,diff --git a/lib/client/generateLinkHref.ts b/lib/client/generateLinkHref.tsindex a7ffd690..b376b258 100644--- a/lib/client/generateLinkHref.ts+++ b/lib/client/generateLinkHref.ts@@ -4,7 +4,7 @@ import {LinkIncludingShortenedCollectionAndTags,} from "@/types/global";import { LinksRouteTo } from "@prisma/client";-import { formatAvailable } from "../shared/getArchiveValidity";+import { formatAvailable } from "../shared/formatStats";export const generateLinkHref = (link: LinkIncludingShortenedCollectionAndTags,diff --git a/lib/shared/getArchiveValidity.ts b/lib/shared/formatStats.tssimilarity index 54%rename from lib/shared/getArchiveValidity.tsrename to lib/shared/formatStats.tsindex 48e961fe..20a66c29 100644--- a/lib/shared/getArchiveValidity.ts+++ b/lib/shared/formatStats.ts@@ -7,3 +7,14 @@ export function formatAvailable() {return link && link[format] && link[format] !== "unavailable";}++export const atLeastOneFormatAvailable = (+ link: Link | LinkIncludingShortenedCollectionAndTags+) => {+ return (+ formatAvailable(link, "image") ||+ formatAvailable(link, "pdf") ||+ formatAvailable(link, "readable") ||+ formatAvailable(link, "monolith")+ );+};diff --git a/store/localSettings.ts b/store/localSettings.tsindex 6ce76ea4..752967ba 100644--- a/store/localSettings.ts+++ b/store/localSettings.ts@@ -13,6 +13,7 @@ type LocalSettings = {tags: boolean;icon: boolean;collection: boolean;+ preserved_formats: boolean;date: boolean;};columns: number;@@ -38,6 +39,7 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({tags: true,icon: true,collection: true,+ preserved_formats: true,date: true,},columns: 0,@@ -100,18 +102,20 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({localStorage.setItem("columns", columns.toString());const storedShow = localStorage.getItem("show");+ const defaultShow = {+ link: true,+ name: true,+ description: true,+ image: true,+ tags: true,+ icon: true,+ collection: true,+ preserved_formats: true,+ date: true,+ };const show = storedShow- ? JSON.parse(storedShow)- : {- link: true,- name: true,- description: true,- image: true,- tags: true,- icon: true,- collection: true,- date: true,- };+ ? { ...defaultShow, ...JSON.parse(storedShow) }+ : defaultShow;localStorage.setItem("show", JSON.stringify(show));set({