Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

wip

daniel31x13dd061e9dc89a
diff --git a/components/Drawer.tsx b/components/Drawer.tsx
index 7400e44f..1e4c1e21 100644
--- a/components/Drawer.tsx
+++ b/components/Drawer.tsx
@@ -1,6 +1,7 @@
import React, { ReactNode, useEffect } from "react";
import { Drawer as D } from "vaul";
import clsx from "clsx";
+import useWindowDimensions from "@/hooks/useWindowDimensions";
type Props = {
toggleDrawer: Function;
@@ -16,9 +17,10 @@ export default function Drawer({
dismissible = true,
}: Props) {
const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);
+ const { width } = useWindowDimensions();
useEffect(() => {
- if (window.innerWidth >= 640) {
+ if (width >= 640) {
document.body.style.overflow = "hidden";
document.body.style.position = "relative";
return () => {
@@ -28,7 +30,7 @@ export default function Drawer({
}
}, []);
- if (window.innerWidth < 640) {
+ if (width < 640) {
return (
<D.Root
open={drawerIsOpen}
diff --git a/components/Preservation/PreservationContent.tsx b/components/Preservation/PreservationContent.tsx
index a01eb296..e7e700f1 100644
--- a/components/Preservation/PreservationContent.tsx
+++ b/components/Preservation/PreservationContent.tsx
@@ -9,26 +9,22 @@ import {
import { BeatLoader } from "react-spinners";
import { useTranslation } from "next-i18next";
import { atLeastOneFormatAvailable } from "@/lib/shared/formatStats";
+import Tab from "../Tab";
type Props = {
- format: ArchivedFormat;
- isExpanded: boolean;
link?: LinkIncludingShortenedCollectionAndTags;
- standalone?: boolean;
+ format?: ArchivedFormat; // Optional now, for backward compatibility
};
-export const PreservationContent: React.FC<Props> = ({
- link,
- format,
- isExpanded,
- standalone,
-}) => {
+export const PreservationContent: React.FC<Props> = ({ link, format }) => {
const [pdfLoaded, setPdfLoaded] = useState(false);
const [monolithLoaded, setMonolithLoaded] = useState(false);
const [imageLoaded, setImageLoaded] = useState(false);
const prevFormatRef = useRef<ArchivedFormat | undefined>(undefined);
const { t } = useTranslation();
+ const [activeTabIndex, setActiveTabIndex] = useState<number>(0);
+
useEffect(() => {
if (prevFormatRef.current !== format) {
setPdfLoaded(false);
@@ -46,11 +42,7 @@ export const PreservationContent: React.FC<Props> = ({
case ArchivedFormat.readability:
return (
<div className="overflow-auto w-full h-full">
- <ReadableView
- link={link}
- isExpanded={isExpanded}
- standalone={standalone || false}
- />
+ <ReadableView link={link} />
</div>
);
case ArchivedFormat.monolith:
@@ -60,13 +52,8 @@ export const PreservationContent: React.FC<Props> = ({
<iframe
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.monolith}&_=${link.updatedAt}`}
className={clsx(
- "w-full border-none",
- monolithLoaded ? "block" : "hidden",
- isExpanded
- ? "h-full"
- : standalone
- ? "h-[calc(100vh-3.75rem)]"
- : "h-[calc(80vh-3.75rem)]"
+ "w-full border-none h-screen",
+ monolithLoaded ? "block" : "hidden"
)}
onLoad={() => setMonolithLoaded(true)}
/>
@@ -79,13 +66,8 @@ export const PreservationContent: React.FC<Props> = ({
<iframe
src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.pdf}&_=${link.updatedAt}`}
className={clsx(
- "w-full border-none",
- pdfLoaded ? "block" : "hidden",
- isExpanded
- ? "h-full"
- : standalone
- ? "h-[calc(100vh-3.75rem)]"
- : "h-[calc(80vh-3.75rem)]"
+ "w-full border-none h-screen",
+ pdfLoaded ? "block" : "hidden"
)}
onLoad={() => setPdfLoaded(true)}
/>
@@ -96,14 +78,12 @@ export const PreservationContent: React.FC<Props> = ({
return (
<>
{!imageLoaded && <PreservationSkeleton />}
- <div className="overflow-auto mx-auto h-full">
- <img
- alt=""
- src={`/api/v1/archives/${link.id}?format=${format}&_=${link.updatedAt}`}
- className={clsx("w-fit mx-auto", !imageLoaded && "hidden")}
- onLoad={() => setImageLoaded(true)}
- />
- </div>
+ <img
+ alt=""
+ src={`/api/v1/archives/${link.id}?format=${format}&_=${link.updatedAt}`}
+ className={clsx("w-fit mx-auto", !imageLoaded && "hidden")}
+ onLoad={() => setImageLoaded(true)}
+ />
</>
);
default:
@@ -112,7 +92,33 @@ export const PreservationContent: React.FC<Props> = ({
};
return (
- <>
+ <div className="relative bg-base-200">
+ {link.url && (
+ <Tab
+ tabs={[
+ {
+ icon: "bi-file-earmark-text",
+ name: "Readable",
+ },
+ {
+ icon: "bi-file-earmark-image",
+ name: "Screenshot",
+ },
+ {
+ icon: "bi-filetype-html",
+ name: "Webpage",
+ },
+ {
+ icon: "bi-file-earmark-pdf",
+ name: "PDF",
+ },
+ ]}
+ activeTabIndex={activeTabIndex}
+ setActiveTabIndex={setActiveTabIndex}
+ className="w-fit absolute left-1/2 -translate-x-1/2 rounded-full bg-base-100 top-2 text-sm shadow-md"
+ hideName
+ />
+ )}
{!atLeastOneFormatAvailable(link) ? (
<div className={`w-full h-full flex flex-col justify-center p-10`}>
<BeatLoader
@@ -127,6 +133,6 @@ export const PreservationContent: React.FC<Props> = ({
) : (
renderFormat()
)}
- </>
+ </div>
);
};
diff --git a/components/Preservation/PreservationPageContent.tsx b/components/Preservation/PreservationPageContent.tsx
index bfad4ef0..bd7e743e 100644
--- a/components/Preservation/PreservationPageContent.tsx
+++ b/components/Preservation/PreservationPageContent.tsx
@@ -34,11 +34,7 @@ export default function PreservationPageContent() {
return (
<div className="w-screen h-screen bg-base-200">
- <PreservationContent
- link={link}
- format={Number(router.query.format)}
- isExpanded={true}
- />
+ <PreservationContent link={link} format={Number(router.query.format)} />
</div>
);
}
diff --git a/components/Preservation/ReadableView.tsx b/components/Preservation/ReadableView.tsx
index 052806f7..404bd12b 100644
--- a/components/Preservation/ReadableView.tsx
+++ b/components/Preservation/ReadableView.tsx
@@ -16,14 +16,11 @@ import usePermissions from "@/hooks/usePermissions";
type Props = {
link: LinkIncludingShortenedCollectionAndTags;
- isExpanded: boolean;
- standalone: boolean;
};
-export default function ReadableView({ link, isExpanded, standalone }: Props) {
+export default function ReadableView({ link }: Props) {
const { t } = useTranslation();
const [linkContent, setLinkContent] = useState("");
- const [isEditing, setIsEditing] = useState(false);
const router = useRouter();
const isPublicRoute = router.pathname.startsWith("/public");
@@ -44,30 +41,25 @@ export default function ReadableView({ link, isExpanded, standalone }: Props) {
}, [link]);
return (
- <div className="flex flex-col gap-3 items-start p-3 max-w-screen-lg mx-auto bg-base-200">
- {!isEditing && (
- <div className="flex gap-3 items-start">
- <div className="flex flex-col w-full gap-1">
- <p className="md:text-4xl text-2xl">
- {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" />
- {isValidUrl(link?.url || "") &&
- new URL(link?.url as string).host}
- </Link>
- )}
- </div>
+ <div className="flex flex-col gap-3 items-start p-3 max-w-screen-lg mx-auto bg-base-200 mt-10">
+ <div className="flex gap-3 items-start">
+ <div className="flex flex-col w-full gap-1">
+ <p className="md:text-4xl text-2xl">
+ {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" />
+ {isValidUrl(link?.url || "") && new URL(link?.url as string).host}
+ </Link>
+ )}
</div>
- )}
+ </div>
<div className="text-sm text-neutral flex justify-between w-full gap-2">
<LinkDate link={link} />
diff --git a/components/Tab.tsx b/components/Tab.tsx
new file mode 100644
index 00000000..72270926
--- /dev/null
+++ b/components/Tab.tsx
@@ -0,0 +1,77 @@
+import clsx from "clsx";
+import { useEffect, useRef, useState } from "react";
+
+type Props = {
+ tabs: { name?: string; icon?: string }[];
+ activeTabIndex: number;
+ setActiveTabIndex: Function;
+ className?: string;
+ hideName?: boolean;
+};
+
+const Tab = ({
+ tabs,
+ activeTabIndex,
+ setActiveTabIndex,
+ className,
+ hideName,
+}: Props) => {
+ const tabsRef = useRef<(HTMLElement | null)[]>([]);
+ const [tabUnderlineWidth, setTabUnderlineWidth] = useState(0);
+ const [tabUnderlineLeft, setTabUnderlineLeft] = useState(0);
+ const [isFirstRender, setIsFirstRender] = useState(true);
+
+ useEffect(() => {
+ const timer = setTimeout(() => {
+ setIsFirstRender(false);
+ }, 100);
+
+ return () => clearTimeout(timer);
+ }, []);
+
+ useEffect(() => {
+ if (activeTabIndex === null) {
+ return;
+ }
+
+ const setTabPosition = () => {
+ const currentTab = tabsRef.current[activeTabIndex] as HTMLElement;
+ setTabUnderlineLeft(currentTab?.offsetLeft ?? 0);
+ setTabUnderlineWidth(currentTab?.clientWidth ?? 0);
+ };
+
+ setTabPosition();
+ }, [activeTabIndex]);
+
+ return (
+ <div className={clsx("flew-row flex backdrop-blur-sm h-8 px-1", className)}>
+ <span
+ className={`absolute bottom-0 top-0 -z-10 flex overflow-hidden rounded-3xl py-1 ${
+ isFirstRender ? "" : "duration-100"
+ }`}
+ style={{ left: tabUnderlineLeft, width: tabUnderlineWidth }}
+ >
+ <span className="h-full w-full rounded-3xl bg-primary/50" />
+ </span>
+ {tabs.map((tab, index) => {
+ const isActive = activeTabIndex === index;
+ return (
+ <button
+ key={index}
+ ref={(el) => (tabsRef.current[index] = el)}
+ className={`${
+ isActive ? `` : `hover:opacity-75 duration-100`
+ } my-auto cursor-pointer select-none rounded-full px-2 text-center flex gap-1 items-center`}
+ onClick={() => setActiveTabIndex(index)}
+ title={tab.name}
+ >
+ {tab.icon && <i className={`text-lg ${tab.icon}`}></i>}
+ {!hideName && tab.name && <p>{tab.name}</p>}
+ </button>
+ );
+ })}
+ </div>
+ );
+};
+
+export default Tab;