Skip to content

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

feat(web): hide navbar in readable view

daniel31x131211b6b1ef1d
diff --git a/apps/web/components/Preservation/PreservationNavbar.tsx b/apps/web/components/Preservation/PreservationNavbar.tsx
index 7f023802..56978cc6 100644
--- a/apps/web/components/Preservation/PreservationNavbar.tsx
+++ b/apps/web/components/Preservation/PreservationNavbar.tsx
@@ -17,13 +17,15 @@ import { useRouter } from "next/router";
import { formatAvailable } from "@linkwarden/lib/formatStats";
import LinkActions from "../LinkViews/LinkComponents/LinkActions";
import { useCollections } from "@linkwarden/router/collections";
+import clsx from "clsx";
type Props = {
link: LinkIncludingShortenedCollectionAndTags;
format?: ArchivedFormat;
+ className?: string;
};
-const PreservationNavbar = ({ link, format }: Props) => {
+const PreservationNavbar = ({ link, format, className }: Props) => {
const { data: collections = [] } = useCollections();
const [collection, setCollection] =
@@ -46,17 +48,40 @@ const PreservationNavbar = ({ link, format }: Props) => {
const { t } = useTranslation();
const router = useRouter();
+ const handleDownload = () => {
+ const path = `/api/v1/archives/${link?.id}?format=${format}`;
+ fetch(path)
+ .then((response) => {
+ if (response.ok) {
+ const anchorElement = document.createElement("a");
+ anchorElement.href = path;
+ anchorElement.download =
+ format === ArchivedFormat.monolith
+ ? "Webpage"
+ : format === ArchivedFormat.pdf
+ ? "PDF"
+ : "Screenshot";
+ anchorElement.click();
+ } else {
+ console.error("Failed to download file");
+ }
+ })
+ .catch((error) => {
+ console.error("Error:", error);
+ });
+ };
+
return (
- <div className="p-2 z-10 bg-base-100 backdrop-blur bg-opacity-80 shadow">
- <div className="max-w-5xl flex gap-2 justify-between mx-auto">
+ <div className={clsx("p-2 z-10 bg-base-100", className)}>
+ <div className="max-w-6xl flex gap-2 justify-between mx-auto">
<Button variant="ghost" size="icon" asChild>
<Link href={`/dashboard`}>
- <i className="bi-chevron-left text-xl" />
+ <i className="bi-chevron-left text-xl text-neutral" />
</Link>
</Button>
<DropdownMenu>
<DropdownMenuTrigger>
- <Button variant="ghost" className="h-8">
+ <Button variant="ghost" className="h-8 text-neutral">
{format === ArchivedFormat.readability
? t("readable")
: format === ArchivedFormat.monolith
@@ -151,13 +176,29 @@ const PreservationNavbar = ({ link, format }: Props) => {
)}
</DropdownMenuContent>
</DropdownMenu>
- <LinkActions
- link={link}
- collection={collection}
- linkModal={linkModal}
- setLinkModal={(e) => setLinkModal(e)}
- ghost
- />
+
+ <div className="flex gap-2 items-center text-neutral">
+ {format === ArchivedFormat.readability ? (
+ <Button
+ variant="ghost"
+ size="icon"
+ className="font-extralight text-lg"
+ >
+ Aa
+ </Button>
+ ) : (
+ <Button variant="ghost" size="icon" onClick={handleDownload}>
+ <i className="bi-cloud-arrow-down text-xl" />
+ </Button>
+ )}
+ <LinkActions
+ link={link}
+ collection={collection}
+ linkModal={linkModal}
+ setLinkModal={(e) => setLinkModal(e)}
+ ghost
+ />
+ </div>
</div>
</div>
);
diff --git a/apps/web/components/Preservation/PreservationPageContent.tsx b/apps/web/components/Preservation/PreservationPageContent.tsx
index 0da5d18f..7988ecb3 100644
--- a/apps/web/components/Preservation/PreservationPageContent.tsx
+++ b/apps/web/components/Preservation/PreservationPageContent.tsx
@@ -1,13 +1,18 @@
-import React, { useEffect } from "react";
+import React, { useEffect, useRef, useState } from "react";
import { useRouter } from "next/router";
import { useGetLink, useLinks } from "@linkwarden/router/links";
import { PreservationContent } from "./PreservationContent";
import PreservationNavbar from "./PreservationNavbar";
+import { ArchivedFormat } from "@linkwarden/types";
export default function PreservationPageContent() {
const router = useRouter();
const { links } = useLinks();
+ const [showNavbar, setShowNavbar] = useState(true);
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const lastScrollTop = useRef(0);
+
let isPublicRoute = router.pathname.startsWith("/public") ? true : undefined;
const { data: link, refetch } = useGetLink({
@@ -35,12 +40,50 @@ export default function PreservationPageContent() {
};
}, [links]);
+ useEffect(() => {
+ const container = scrollRef.current;
+ if (!container) return;
+
+ const onScroll = () => {
+ const st = container.scrollTop;
+ // if scrolling down and beyond a small threshold, hide
+ if (st - 10 > lastScrollTop.current) {
+ if (Number(router.query.format) === ArchivedFormat.readability)
+ setShowNavbar(false);
+ }
+ // if scrolling up, show
+ else if (st < lastScrollTop.current - 10) {
+ setShowNavbar(true);
+ }
+ lastScrollTop.current = st <= 0 ? 0 : st; // for Mobile or negative
+ };
+
+ container.addEventListener("scroll", onScroll, { passive: true });
+ return () => container.removeEventListener("scroll", onScroll);
+ }, [router.query.format]);
+
return (
<div>
{link?.id && (
- <PreservationNavbar link={link} format={Number(router.query.format)} />
+ <PreservationNavbar
+ link={link}
+ format={Number(router.query.format)}
+ className={`
+ transform transition-transform duration-200 ease-in-out
+ ${
+ showNavbar
+ ? "translate-y-0"
+ : "-translate-y-full fixed top-0 left-0 right-0"
+ }
+ `}
+ />
)}
- <div className="bg-base-200 overflow-y-auto w-screen h-[calc(100vh-3rem)]">
+ <div
+ className={`bg-base-200 overflow-y-auto w-screen ${
+ showNavbar ? "h-[calc(100vh-3rem)]" : "h-screen"
+ }`}
+ ref={scrollRef}
+ >
<PreservationContent link={link} format={Number(router.query.format)} />
</div>
</div>