Skip to content

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

WIP

daniel31x13b32151eb7ee3
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx b/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
index 0f096d74..b67f910b 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
@@ -24,16 +24,18 @@ import { Button } from "@/components/ui/button";
type Props = {
link: LinkIncludingShortenedCollectionAndTags;
collection: CollectionIncludingMembersAndLinkCount;
- btnStyle?: string;
linkModal: boolean;
+ className?: string;
setLinkModal: (value: boolean) => void;
+ ghost?: boolean;
};
export default function LinkActions({
link,
- btnStyle,
linkModal,
+ className,
setLinkModal,
+ ghost,
}: Props) {
const { t } = useTranslation();
@@ -73,12 +75,9 @@ export default function LinkActions({
<>
{isPublicRoute ? (
<Button
- variant="simple"
+ variant={ghost ? "ghost" : "simple"}
size="icon"
- className={clsx(
- "absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20",
- btnStyle
- )}
+ className={clsx(className)}
onClick={() => setLinkModal(true)}
>
<i title="More" className="bi-info-circle text-xl" />
@@ -88,12 +87,9 @@ export default function LinkActions({
<DropdownMenuTrigger asChild>
<Button
asChild
- variant="simple"
+ variant={ghost ? "ghost" : "simple"}
size="icon"
- className={clsx(
- "absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20",
- btnStyle
- )}
+ className={clsx(className)}
onMouseDown={(e) => e.preventDefault()}
>
<button>
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
index c46e0900..be059bbb 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
@@ -250,6 +250,7 @@ export default function LinkCard({ link, columns, editMode }: Props) {
collection={collection}
linkModal={linkModal}
setLinkModal={(e) => setLinkModal(e)}
+ className="absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20"
/>
{!isPublicRoute && <LinkPin link={link} />}
</div>
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
index cc710f9f..8566d7dd 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
@@ -159,6 +159,7 @@ export default function LinkCardCompact({ link, editMode }: Props) {
collection={collection}
linkModal={linkModal}
setLinkModal={(e) => setLinkModal(e)}
+ className="absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20"
/>
</div>
<div className="last:hidden rounded-none my-0 mx-1 border-t border-base-300 h-[1px]"></div>
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
index 03df64eb..5960b84a 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
@@ -266,6 +266,7 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
collection={collection}
linkModal={linkModal}
setLinkModal={(e) => setLinkModal(e)}
+ className="absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20"
/>
{!isPublic && <LinkPin link={link} />}
</div>
diff --git a/apps/web/components/Preservation/PreservationContent.tsx b/apps/web/components/Preservation/PreservationContent.tsx
index 42036175..3e186bfe 100644
--- a/apps/web/components/Preservation/PreservationContent.tsx
+++ b/apps/web/components/Preservation/PreservationContent.tsx
@@ -13,13 +13,7 @@ import {
atLeastOneFormatAvailable,
formatAvailable,
} from "@linkwarden/lib/formatStats";
-import {
- Tooltip,
- TooltipContent,
- TooltipProvider,
- TooltipTrigger,
-} from "@/components/ui/tooltip";
-import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import PreservationNavbar from "./PreservationNavbar";
type Props = {
link?: LinkIncludingShortenedCollectionAndTags;
@@ -51,63 +45,11 @@ export const PreservationContent: React.FC<Props> = ({ link, format }) => {
format ?? ArchivedFormat.readability
);
- const screenshotFormat = findAvailableImageFormat(link!);
-
- const potentialTabs = [
- {
- type: "readable" as const,
- format: ArchivedFormat.readability,
- icon: "bi-file-earmark-text",
- name: "Readable",
- },
- {
- type: "image" as const,
- format: screenshotFormat,
- icon: "bi-file-earmark-image",
- name: "Screenshot",
- },
- {
- type: "monolith" as const,
- format: ArchivedFormat.monolith,
- icon: "bi-filetype-html",
- name: "Webpage",
- },
- {
- type: "pdf" as const,
- format: ArchivedFormat.pdf,
- icon: "bi-file-earmark-pdf",
- name: "PDF",
- },
- ].filter((tab) => {
- if (tab.format == null) return false;
- return formatAvailable(link!, tab.type);
- });
-
- const activeTabIndex = potentialTabs.findIndex(
- (tab) => tab.format === currentFormat
- );
-
- function handleTabChange(newIndex: number) {
- if (newIndex >= potentialTabs.length) return;
- const newFormat = potentialTabs[newIndex].format!;
-
- setCurrentFormat(newFormat);
- router.push(
- {
- pathname: router.pathname,
- query: { ...router.query, format: newFormat },
- },
- undefined,
- { shallow: true }
- );
- }
-
useEffect(() => {
if (!router.isReady) return;
- const queryVal = router.query.format;
- if (queryVal) {
- const qFormat = parseInt(queryVal as string, 10);
+ if (router.query.format) {
+ const query = Number(router.query.format as string);
const allFormats = [
ArchivedFormat.readability,
ArchivedFormat.monolith,
@@ -116,18 +58,16 @@ export const PreservationContent: React.FC<Props> = ({ link, format }) => {
ArchivedFormat.pdf,
];
- if (allFormats.includes(qFormat)) {
- setCurrentFormat(qFormat);
+ if (allFormats.includes(query)) {
+ setCurrentFormat(query);
return;
}
}
if (format !== undefined) {
setCurrentFormat(format);
- } else if (potentialTabs.length > 0) {
- setCurrentFormat(potentialTabs[0].format!);
}
- }, [router.query.format, router.isReady, format, potentialTabs]);
+ }, [router.query.format, router.isReady, format]);
useEffect(() => {
if (prevFormatRef.current !== currentFormat) {
@@ -225,46 +165,7 @@ export const PreservationContent: React.FC<Props> = ({ link, format }) => {
return (
<div className="relative bg-base-200">
- {link.url && potentialTabs.length > 1 && (
- <Tabs
- value={activeTabIndex.toString()}
- onValueChange={(val) => handleTabChange(Number(val))}
- className={
- "w-fit absolute left-1/2 -translate-x-1/2 bg-base-100 top-2 text-sm shadow-md rounded-full"
- }
- >
- <TabsList className="flex flex-row gap-1 rounded-full h-9">
- {potentialTabs
- .map((tab) => ({
- icon: tab.icon,
- name: tab.name,
- }))
- .map((tab, idx) => (
- <TooltipProvider key={idx}>
- <Tooltip>
- <TooltipTrigger asChild>
- <TabsTrigger
- value={String(idx)}
- className={clsx(
- "flex gap-1 items-center rounded-full aspect-square h-7 w-7"
- )}
- data-state={
- idx === activeTabIndex ? "active" : "inactive"
- }
- >
- {tab.icon && <i className={`text-lg ${tab.icon}`} />}
- </TabsTrigger>
- </TooltipTrigger>
-
- {tab.name && (
- <TooltipContent side="bottom">{tab.name}</TooltipContent>
- )}
- </Tooltip>
- </TooltipProvider>
- ))}
- </TabsList>
- </Tabs>
- )}
+ <PreservationNavbar link={link} format={format} />
{!atLeastOneFormatAvailable(link) ? (
<div className={`w-full h-full flex flex-col justify-center p-10`}>
<BeatLoader
diff --git a/apps/web/components/Preservation/PreservationNavbar.tsx b/apps/web/components/Preservation/PreservationNavbar.tsx
new file mode 100644
index 00000000..31dc91d0
--- /dev/null
+++ b/apps/web/components/Preservation/PreservationNavbar.tsx
@@ -0,0 +1,174 @@
+import {
+ ArchivedFormat,
+ CollectionIncludingMembersAndLinkCount,
+ LinkIncludingShortenedCollectionAndTags,
+} from "@linkwarden/types";
+import React, { useEffect, useState } from "react";
+import {
+ DropdownMenu,
+ DropdownMenuCheckboxItem,
+ DropdownMenuContent,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { Button } from "@/components/ui/button";
+import { useTranslation } from "next-i18next";
+import Link from "next/link";
+import { useRouter } from "next/router";
+import { formatAvailable } from "@linkwarden/lib/formatStats";
+import LinkActions from "../LinkViews/LinkComponents/LinkActions";
+import { useCollections } from "@linkwarden/router/collections";
+
+type Props = {
+ link: LinkIncludingShortenedCollectionAndTags;
+ format?: ArchivedFormat;
+};
+
+const PreservationNavbar = ({ link, format }: Props) => {
+ const { data: collections = [] } = useCollections();
+
+ const [collection, setCollection] =
+ useState<CollectionIncludingMembersAndLinkCount>(
+ collections.find(
+ (e) => e.id === link.collection.id
+ ) as CollectionIncludingMembersAndLinkCount
+ );
+
+ const [linkModal, setLinkModal] = useState(false);
+
+ useEffect(() => {
+ setCollection(
+ collections.find(
+ (e) => e.id === link.collection.id
+ ) as CollectionIncludingMembersAndLinkCount
+ );
+ }, [collections]);
+
+ const { t } = useTranslation();
+ const router = useRouter();
+
+ function handleTabChange(newIndex: number) {
+ router.push(
+ {
+ pathname: router.pathname,
+ query: { ...router.query, format: newIndex },
+ },
+ undefined,
+ { shallow: true }
+ );
+ }
+
+ return (
+ <div className="max-w-5xl mx-auto py-5 flex gap-2 justify-between">
+ <Button variant="ghost" size="icon" asChild>
+ <Link href={`/dashboard`}>
+ <i className="bi-chevron-left text-xl" />
+ </Link>
+ </Button>
+ <DropdownMenu>
+ <DropdownMenuTrigger>
+ <Button variant="ghost" className="h-8">
+ {format === ArchivedFormat.readability
+ ? t("readable")
+ : format === ArchivedFormat.monolith
+ ? t("webpage")
+ : format === ArchivedFormat.pdf
+ ? t("pdf")
+ : t("screenshot")}
+ <i className="bi-chevron-down" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ {formatAvailable(link, "readable") && (
+ <DropdownMenuCheckboxItem
+ onSelect={() =>
+ router.push(
+ {
+ query: {
+ ...router.query,
+ format: ArchivedFormat.readability,
+ },
+ },
+ undefined,
+ { shallow: true }
+ )
+ }
+ checked={format === ArchivedFormat.readability}
+ >
+ {t("readable")}
+ </DropdownMenuCheckboxItem>
+ )}
+ {formatAvailable(link, "monolith") && (
+ <DropdownMenuCheckboxItem
+ onSelect={() =>
+ router.push(
+ {
+ query: {
+ ...router.query,
+ format: ArchivedFormat.monolith,
+ },
+ },
+ undefined,
+ { shallow: true }
+ )
+ }
+ checked={format === ArchivedFormat.monolith}
+ >
+ {t("webpage")}
+ </DropdownMenuCheckboxItem>
+ )}
+ {formatAvailable(link, "image") && (
+ <DropdownMenuCheckboxItem
+ onSelect={() =>
+ router.push(
+ {
+ query: {
+ ...router.query,
+ format: link?.image?.endsWith(".png")
+ ? ArchivedFormat.png
+ : ArchivedFormat.jpeg,
+ },
+ },
+ undefined,
+ { shallow: true }
+ )
+ }
+ checked={
+ format === ArchivedFormat.png || format === ArchivedFormat.jpeg
+ }
+ >
+ {t("screenshot")}
+ </DropdownMenuCheckboxItem>
+ )}
+ {formatAvailable(link, "pdf") && (
+ <DropdownMenuCheckboxItem
+ onSelect={() =>
+ router.push(
+ {
+ query: {
+ ...router.query,
+ format: ArchivedFormat.pdf,
+ },
+ },
+ undefined,
+ { shallow: true }
+ )
+ }
+ checked={format === ArchivedFormat.pdf}
+ >
+ {t("pdf")}
+ </DropdownMenuCheckboxItem>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {/* <LinkActions
+ link={link}
+ collection={collection}
+ linkModal={linkModal}
+ setLinkModal={(e) => setLinkModal(e)}
+ ghost
+ /> */}
+ </div>
+ );
+};
+
+export default PreservationNavbar;
diff --git a/apps/web/components/Preservation/PreservationPageContent.tsx b/apps/web/components/Preservation/PreservationPageContent.tsx
index 6f04bde8..f874d0fd 100644
--- a/apps/web/components/Preservation/PreservationPageContent.tsx
+++ b/apps/web/components/Preservation/PreservationPageContent.tsx
@@ -1,10 +1,11 @@
import React, { useEffect } from "react";
import { useRouter } from "next/router";
-import { useGetLink } from "@linkwarden/router/links";
+import { useGetLink, useLinks } from "@linkwarden/router/links";
import { PreservationContent } from "./PreservationContent";
export default function PreservationPageContent() {
const router = useRouter();
+ const { links } = useLinks();
let isPublicRoute = router.pathname.startsWith("/public") ? true : undefined;
@@ -34,7 +35,7 @@ export default function PreservationPageContent() {
return () => {
if (interval) clearInterval(interval);
};
- }, []);
+ }, [links]);
return (
<div className="w-screen h-screen bg-base-200">
diff --git a/apps/web/components/Preservation/ReadableView.tsx b/apps/web/components/Preservation/ReadableView.tsx
index c2e496b3..9211eaa1 100644
--- a/apps/web/components/Preservation/ReadableView.tsx
+++ b/apps/web/components/Preservation/ReadableView.tsx
@@ -277,7 +277,7 @@ export default function ReadableView({ link }: Props) {
};
return (
- <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 flex-col gap-3 items-start p-3 max-w-screen-lg mx-auto bg-base-200 mt-5">
<div className="flex gap-3 items-start">
<div className="flex flex-col w-full gap-1">
<p className="md:text-4xl text-xl">