⚡️⚡️⚡️ 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
WIP
daniel31x13032f96191e68
diff --git a/components/ModalContent/LinkModal.tsx b/components/ModalContent/LinkModal.tsxindex c3793ac1..acf166f4 100644--- a/components/ModalContent/LinkModal.tsx+++ b/components/ModalContent/LinkModal.tsx@@ -62,7 +62,7 @@ export default function LinkModal({setMode("view");}}>- View+ {t("view")}</div><divclassName={clsx(@@ -73,7 +73,7 @@ export default function LinkModal({setMode("edit");}}>- Edit+ {t("edit")}</div></div>)}diff --git a/components/Preservation.tsx b/components/Preservation.tsxnew file mode 100644index 00000000..a38fe269--- /dev/null+++ b/components/Preservation.tsx@@ -0,0 +1,199 @@+import React, { useEffect, useState } from "react";+import { useRouter } from "next/router";+import { ArchivedFormat } from "@/types/global";+import { useTranslation } from "next-i18next";+import ReadableView from "@/components/ReadableView";+import { useGetLink } from "@/hooks/store/links";+import clsx from "clsx";+import Link from "next/link";+import Icon from "./Icon";+import unescapeString from "@/lib/client/unescapeString";+import isValidUrl from "@/lib/shared/isValidUrl";+import { IconWeight } from "@phosphor-icons/react";+import LinkIcon from "./LinkViews/LinkComponents/LinkIcon";+import LinkDate from "./LinkViews/LinkComponents/LinkDate";+import { formatAvailable } from "@/lib/shared/formatStats";++export default function Preservation() {+ const { data: link, ...getLink } = useGetLink();+ const { t } = useTranslation();+ const router = useRouter();+ const isPublicRoute = router.pathname.startsWith("/public");++ const [format, setFormat] = useState<ArchivedFormat>(+ Number(router.query.format)+ );++ // A useEffect that changes the query string when the format changes+ useEffect(() => {+ router.push(+ {+ query: {+ id: router.query.id,+ format: format,+ },+ },+ undefined,+ { shallow: true }+ );+ }, [format]);++ useEffect(() => {+ getLink.mutateAsync({+ id: Number(router.query.id),+ isPublicRoute: isPublicRoute,+ });++ let interval: NodeJS.Timeout | null = null;+ if (+ link &&+ (!link?.image || !link?.pdf || !link?.readable || !link?.monolith)+ ) {+ interval = setInterval(+ () =>+ getLink.mutateAsync({+ id: link.id as number,+ }),+ 5000+ );+ } else {+ if (interval) {+ clearInterval(interval);+ }+ }+ }, []);++ return (+ <div+ className={clsx(+ getLink.isPending ? "flex h-screen" : "relative",+ "max-w-screen-lg h-full mx-auto p-3"+ )}+ >+ {link?.id && (+ <div className={`flex flex-col gap-3 items-start`}>+ <div className="flex gap-3 items-start">+ <div className="flex flex-col w-full gap-1">+ <p className="md:text-4xl text-2xl pr-10">+ {unescapeString(+ link?.name || link?.description || link?.url || ""+ )}+ </p>+ {link?.url && (+ <Link+ href={link?.url || ""}+ title={link?.url}+ target="_blank"+ className="hover:opacity-60 duration-100 break-all text-sm flex items-center gap-1 text-neutral w-fit"+ >+ <i className="bi-link-45deg"></i>++ {isValidUrl(link?.url || "") &&+ new URL(link?.url as string).host}+ </Link>+ )}+ </div>+ </div>++ <p className="text-sm text-neutral mb-3 flex justify-between items-center w-full gap-2 flex-wrap">+ <LinkDate link={link} />+ <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 w-full sm:w-fit">+ {formatAvailable(link, "pdf") && (+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold w-full text-center",+ format === ArchivedFormat.pdf && "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setFormat(ArchivedFormat.pdf);+ }}+ >+ {t("pdf")}+ </div>+ )}+ {formatAvailable(link, "monolith") && (+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold w-full text-center",+ format === ArchivedFormat.monolith &&+ "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setFormat(ArchivedFormat.monolith);+ }}+ >+ {t("webpage")}+ </div>+ )}+ {formatAvailable(link, "readable") && (+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold w-full text-center",+ format === ArchivedFormat.readability &&+ "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setFormat(ArchivedFormat.readability);+ }}+ >+ {t("readable")}+ </div>+ )}+ {formatAvailable(link, "image") && (+ <div+ className={clsx(+ "py-1 px-2 cursor-pointer duration-100 rounded-full font-semibold w-full text-center",+ format ===+ (link?.image?.endsWith("png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg) && "bg-primary bg-opacity-50"+ )}+ onClick={() => {+ setFormat(+ link?.image?.endsWith("png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg+ );+ }}+ >+ {t("image")}+ </div>+ )}+ </div>+ </p>+ </div>+ )}+ {link?.id &&+ Number(router.query.format) === ArchivedFormat.readability ? (+ <ReadableView link={link} />+ ) : link?.id &&+ Number(router.query.format) === ArchivedFormat.monolith ? (+ <iframe+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.monolith}`}+ className="w-full h-screen border-none rounded-md"+ ></iframe>+ ) : link?.id && Number(router.query.format) === ArchivedFormat.pdf ? (+ <iframe+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.pdf}`}+ className="w-full h-screen border-none rounded-md"+ ></iframe>+ ) : link?.id && Number(router.query.format) === ArchivedFormat.png ? (+ <img+ alt=""+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.png}`}+ className="w-fit mx-auto rounded-md"+ />+ ) : link?.id && Number(router.query.format) === ArchivedFormat.jpeg ? (+ <img+ alt=""+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}`}+ className="w-fit mx-auto rounded-md"+ />+ ) : getLink.error ? (+ <p>{t("not_found_404")}</p>+ ) : (+ <></>+ )}+ </div>+ );+}diff --git a/components/ReadableView.tsx b/components/ReadableView.tsxindex c4a59857..2df375ad 100644--- a/components/ReadableView.tsx+++ b/components/ReadableView.tsx@@ -1,20 +1,13 @@-import unescapeString from "@/lib/client/unescapeString";import { formatAvailable } from "@/lib/shared/formatStats";-import isValidUrl from "@/lib/shared/isValidUrl";import {ArchivedFormat,LinkIncludingShortenedCollectionAndTags,} from "@/types/global";-import ColorThief, { RGBColor } from "colorthief";import DOMPurify from "dompurify";-import Image from "next/image";-import Link from "next/link";import { useRouter } from "next/router";import React, { useEffect, useState } from "react";import { useTranslation } from "next-i18next";-import { useGetLink } from "@/hooks/store/links";-import { IconWeight } from "@phosphor-icons/react";-import Icon from "./Icon";+import clsx from "clsx";type LinkContent = {title: string;@@ -35,17 +28,9 @@ type Props = {export default function ReadableView({ link }: Props) {const { t } = useTranslation();const [linkContent, setLinkContent] = useState<LinkContent>();- const [imageError, setImageError] = useState<boolean>(false);- const [colorPalette, setColorPalette] = useState<RGBColor[]>();-- const [date, setDate] = useState<Date | string>();-- const colorThief = new ColorThief();const router = useRouter();- const getLink = useGetLink();-useEffect(() => {const fetchLinkContent = async () => {if (router.query.id && formatAvailable(link, "readable")) {@@ -60,221 +45,61 @@ export default function ReadableView({ link }: Props) {};fetchLinkContent();-- setDate(link.importDate || link.createdAt);}, [link]);- useEffect(() => {- if (link) getLink.mutateAsync({ id: link.id as number });-- let interval: NodeJS.Timeout | null = null;- if (- link &&- (!link?.image || !link?.pdf || !link?.readable || !link?.monolith)- ) {- interval = setInterval(- () =>- getLink.mutateAsync({- id: link.id as number,- }),- 5000- );- } else {- if (interval) {- clearInterval(interval);- }- }-- return () => {- if (interval) {- clearInterval(interval);- }- };- }, [link?.image, link?.pdf, link?.readable, link?.monolith]);-- const rgbToHex = (r: number, g: number, b: number): string =>- "#" +- [r, g, b]- .map((x) => {- const hex = x.toString(16);- return hex.length === 1 ? "0" + hex : hex;- })- .join("");-- useEffect(() => {- const banner = document.getElementById("link-banner");- const bannerInner = document.getElementById("link-banner-inner");-- if (colorPalette && banner && bannerInner) {- if (colorPalette[0] && colorPalette[1]) {- banner.style.background = `linear-gradient(to bottom, ${rgbToHex(- colorPalette[0][0],- colorPalette[0][1],- colorPalette[0][2]- )}20, ${rgbToHex(- colorPalette[1][0],- colorPalette[1][1],- colorPalette[1][2]- )}20)`;- }-- if (colorPalette[2] && colorPalette[3]) {- bannerInner.style.background = `linear-gradient(to bottom, ${rgbToHex(- colorPalette[2][0],- colorPalette[2][1],- colorPalette[2][2]- )}30, ${rgbToHex(- colorPalette[3][0],- colorPalette[3][1],- colorPalette[3][2]- )})30`;- }- }- }, [colorPalette]);-return (- <div className={`flex flex-col max-w-screen-md h-full mx-auto p-5`}>- <div- id="link-banner"- className="link-banner relative bg-opacity-10 border-neutral-content p-3 border mb-3"- >- <div id="link-banner-inner" className="link-banner-inner"></div>-- <div className={`flex flex-col gap-3 items-start`}>- <div className="flex gap-3 items-start">- {!imageError && link?.url && (- <Image- src={`https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${link.url}&size=32`}- width={42}- height={42}- alt=""- id={"favicon-" + link.id}- className="bg-white shadow rounded-md p-1 select-none mt-1"- draggable="false"- onLoad={(e) => {- try {- const color = colorThief.getPalette(- e.target as HTMLImageElement,- 4- );-- setColorPalette(color);- } catch (err) {- console.log(err);- }- }}- onError={(e) => {- setImageError(true);- }}- />- )}- <div className="flex flex-col">- <p className="text-xl pr-10">- {unescapeString(- link?.name || link?.description || link?.url || ""- )}- </p>- {link?.url && (- <Link- href={link?.url || ""}- title={link?.url}- target="_blank"- className="hover:opacity-60 duration-100 break-all text-sm flex items-center gap-1 text-neutral w-fit"- >- <i className="bi-link-45deg"></i>-- {isValidUrl(link?.url || "") &&- new URL(link?.url as string).host}- </Link>- )}+ <div+ className={clsx(+ "flex flex-col gap-5 h-full rounded-md p-3",+ linkContent?.content && "bg-base-200"+ )}+ >+ {link?.readable?.startsWith("archives") ? (+ <>+ {linkContent?.content ? (+ <div+ className="line-break px-1 reader-view"+ dangerouslySetInnerHTML={{+ __html: DOMPurify.sanitize(linkContent?.content || "") || "",+ }}+ ></div>+ ) : (+ <div className="p-5 m-auto w-full flex flex-col items-center gap-5">+ <div className="w-full mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-full mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-full mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-full mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-full mr-auto h-4 skeleton rounded-md"></div>+ <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div></div>- </div>-- <div className="flex gap-1 items-center flex-wrap">- <Link- href={`/collections/${link?.collection.id}`}- className="flex items-center gap-1 cursor-pointer hover:opacity-60 duration-100 mr-2 z-10"- >- {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>- )}- <p- title={link?.collection.name}- className="text-lg truncate max-w-[12rem]"- >- {link?.collection.name}- </p>- </Link>- {link?.tags?.map((e, i) => (- <Link key={i} href={`/tags/${e.id}`} className="z-10">- <p- title={e.name}- className="btn btn-xs btn-ghost truncate max-w-[19rem]"- >- #{e.name}- </p>- </Link>- ))}- </div>-- <p className="min-w-fit text-sm text-neutral">- {date- ? new Date(date).toLocaleString("en-US", {- year: "numeric",- month: "long",- day: "numeric",- })- : undefined}+ )}+ </>+ ) : (+ <div+ className={`w-full h-full flex flex-col justify-center p-10 ${+ !link?.readable ? "skeleton" : ""+ }`}+ >+ <svg+ xmlns="http://www.w3.org/2000/svg"+ width="16"+ height="16"+ fill="currentColor"+ className="w-1/4 min-w-[7rem] max-w-[15rem] h-auto mx-auto mb-5"+ viewBox="0 0 16 16"+ >+ <path d="m14.12 10.163 1.715.858c.22.11.22.424 0 .534L8.267 15.34a.598.598 0 0 1-.534 0L.165 11.555a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.66zM7.733.063a.598.598 0 0 1 .534 0l7.568 3.784a.3.3 0 0 1 0 .535L8.267 8.165a.598.598 0 0 1-.534 0L.165 4.382a.299.299 0 0 1 0-.535L7.733.063z" />+ <path d="m14.12 6.576 1.715.858c.22.11.22.424 0 .534l-7.568 3.784a.598.598 0 0 1-.534 0L.165 7.968a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.659z" />+ </svg>+ <p className="text-center text-2xl">+ {t("link_preservation_in_queue")}</p>-- {link?.name ? <p>{unescapeString(link?.description)}</p> : undefined}+ <p className="text-center text-lg mt-2">{t("check_back_later")}</p></div>- </div>-- <div className="flex flex-col gap-5 h-full">- {link?.readable?.startsWith("archives") ? (- <div- className="line-break px-1 reader-view"- dangerouslySetInnerHTML={{- __html: DOMPurify.sanitize(linkContent?.content || "") || "",- }}- ></div>- ) : (- <div- className={`w-full h-full flex flex-col justify-center p-10 ${- !link?.readable ? "skeleton" : ""- }`}- >- <svg- xmlns="http://www.w3.org/2000/svg"- width="16"- height="16"- fill="currentColor"- className="w-1/4 min-w-[7rem] max-w-[15rem] h-auto mx-auto mb-5"- viewBox="0 0 16 16"- >- <path d="m14.12 10.163 1.715.858c.22.11.22.424 0 .534L8.267 15.34a.598.598 0 0 1-.534 0L.165 11.555a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.66zM7.733.063a.598.598 0 0 1 .534 0l7.568 3.784a.3.3 0 0 1 0 .535L8.267 8.165a.598.598 0 0 1-.534 0L.165 4.382a.299.299 0 0 1 0-.535L7.733.063z" />- <path d="m14.12 6.576 1.715.858c.22.11.22.424 0 .534l-7.568 3.784a.598.598 0 0 1-.534 0L.165 7.968a.299.299 0 0 1 0-.534l1.716-.858 5.317 2.659c.505.252 1.1.252 1.604 0l5.317-2.659z" />- </svg>- <p className="text-center text-2xl">- {t("link_preservation_in_queue")}- </p>- <p className="text-center text-lg mt-2">{t("check_back_later")}</p>- </div>- )}- </div>+ )}</div>);}diff --git a/hooks/store/links.tsx b/hooks/store/links.tsxindex a7f115aa..aa8c52b3 100644--- a/hooks/store/links.tsx+++ b/hooks/store/links.tsx@@ -261,7 +261,7 @@ const useGetLink = () => {return data.response;},- onSuccess: (data) => {+ onSuccess: (data: LinkIncludingShortenedCollectionAndTags) => {queryClient.setQueryData(["dashboardData"], (oldData: any) => {if (!oldData?.links) return undefined;return {diff --git a/pages/preserved/[id].tsx b/pages/preserved/[id].tsxindex 0259cb3a..4c336e43 100644--- a/pages/preserved/[id].tsx+++ b/pages/preserved/[id].tsx@@ -1,73 +1,8 @@-import React, { useEffect } from "react";-import { useRouter } from "next/router";-import { ArchivedFormat } from "@/types/global";-import ReadableView from "@/components/ReadableView";import getServerSideProps from "@/lib/client/getServerSideProps";-import { useGetLink } from "@/hooks/store/links";-import clsx from "clsx";+import Preservation from "@/components/Preservation";export default function Index() {- const getLink = useGetLink();-- const router = useRouter();-- useEffect(() => {- if (router.query.id) {- getLink.mutateAsync({ id: Number(router.query.id) });- }- }, []);-- return (- <div className={clsx(getLink.isPending ? "flex h-screen" : "relative")}>- {/* <div className="fixed left-1/2 transform -translate-x-1/2 w-fit py-1 px-3 bg-base-200 border border-neutral-content rounded-md">- Readable- </div> */}- {getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.readability ? (- <ReadableView link={getLink.data} />- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.monolith ? (- <iframe- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.monolith}`}- className="w-full h-screen border-none"- ></iframe>- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.pdf ? (- <iframe- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.pdf}`}- className="w-full h-screen border-none"- ></iframe>- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.png ? (- <img- alt=""- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.png}`}- className="w-fit mx-auto"- />- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.jpeg ? (- <img- alt=""- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.jpeg}`}- className="w-fit mx-auto"- />- ) : getLink.error ? (- <p>404 - Not found</p>- ) : (- <div className="max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>- </div>- )}- </div>- );+ return <Preservation />;}export { getServerSideProps };diff --git a/pages/public/preserved/[id].tsx b/pages/public/preserved/[id].tsxindex cca75a2f..4c336e43 100644--- a/pages/public/preserved/[id].tsx+++ b/pages/public/preserved/[id].tsx@@ -1,74 +1,8 @@-import React, { useEffect } from "react";-import { useRouter } from "next/router";-import { ArchivedFormat } from "@/types/global";-import { useTranslation } from "next-i18next";-import ReadableView from "@/components/ReadableView";import getServerSideProps from "@/lib/client/getServerSideProps";-import { useGetLink } from "@/hooks/store/links";-import clsx from "clsx";+import Preservation from "@/components/Preservation";export default function Index() {- const getLink = useGetLink();- const { t } = useTranslation();- const router = useRouter();-- useEffect(() => {- if (router.query.id) {- getLink.mutateAsync({ id: Number(router.query.id), isPublicRoute: true });- }- }, []);-- return (- <div className={clsx(getLink.isPending ? "flex h-screen" : "relative")}>- {/* <div className="fixed left-1/2 transform -translate-x-1/2 w-fit py-1 px-3 bg-base-200 border border-neutral-content rounded-md">- t("readable")- </div> */}- {getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.readability ? (- <ReadableView link={getLink.data} />- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.monolith ? (- <iframe- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.monolith}`}- className="w-full h-screen border-none"- ></iframe>- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.pdf ? (- <iframe- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.pdf}`}- className="w-full h-screen border-none"- ></iframe>- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.png ? (- <img- alt=""- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.png}`}- className="w-fit mx-auto"- />- ) : getLink.data?.id &&- Number(router.query.format) === ArchivedFormat.jpeg ? (- <img- alt=""- src={`/api/v1/archives/${getLink.data.id}?format=${ArchivedFormat.jpeg}`}- className="w-fit mx-auto"- />- ) : getLink.error ? (- <p>{t("not_found_404")}</p>- ) : (- <div className="max-w-3xl p-5 m-auto w-full flex flex-col items-center gap-5">- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-3/4 mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-full mr-auto h-4 skeleton rounded-md"></div>- <div className="w-5/6 mr-auto h-4 skeleton rounded-md"></div>- </div>- )}- </div>- );+ return <Preservation />;}export { getServerSideProps };diff --git a/styles/globals.css b/styles/globals.cssindex 02380866..7f8919b7 100644--- a/styles/globals.css+++ b/styles/globals.css@@ -167,12 +167,6 @@border-width: 1px;}-/* For the Link banner */-.link-banner {- border-radius: 1rem;- height: fit-content;-}-.react-select__indicator-separator {display: none;}