Skip to content

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

bug fixed

daniel31x139e417b7f351b
diff --git a/components/LinkDetails.tsx b/components/LinkDetails.tsx
index 0bd4535f..66a55d79 100644
--- a/components/LinkDetails.tsx
+++ b/components/LinkDetails.tsx
@@ -1,13 +1,10 @@
-import React, { useEffect, useRef, useState } from "react";
+import React, { useEffect, useMemo, useRef, useState } from "react";
import {
LinkIncludingShortenedCollectionAndTags,
ArchivedFormat,
} from "@/types/global";
import Link from "next/link";
-import {
- atLeastOneFormatAvailable,
- formatAvailable,
-} from "@/lib/shared/formatStats";
+import { formatAvailable } from "@/lib/shared/formatStats";
import getPublicUserData from "@/lib/client/getPublicUserData";
import { useTranslation } from "next-i18next";
import { useUser } from "@/hooks/store/user";
@@ -111,7 +108,7 @@ export default function LinkDetails({
fetchOwner();
}, [link.collection.ownerId]);
- const isReady = () => {
+ const isReady = useMemo(() => {
return (
link &&
(collectionOwner.archiveAsScreenshot === true ? link.pdf : true) &&
@@ -119,7 +116,7 @@ export default function LinkDetails({
(collectionOwner.archiveAsPDF === true ? link.pdf : true) &&
link.readable
);
- };
+ }, [link, collectionOwner]);
useEffect(() => {
(async () => {
@@ -130,7 +127,7 @@ export default function LinkDetails({
let interval: any;
- if (!isReady()) {
+ if (!isReady) {
interval = setInterval(async () => {
await getLink.mutateAsync({
id: link.id as number,
@@ -206,19 +203,18 @@ export default function LinkDetails({
!standalone && "sm:flex sm:h-[80vh]"
)}
>
- {width >= 640 && atLeastOneFormatAvailable(link) && (
+ {width >= 640 && (
<div className="w-1/2 lg:w-2/3 overflow-y-auto">
{link.id && (
- <Preservation link={link} standalone={standalone || false} />
+ <Preservation
+ link={link}
+ standalone={standalone || false}
+ isReady={!!isReady}
+ />
)}
</div>
)}
- <div
- className={clsx(
- "sm:overflow-y-auto sm:w-full",
- atLeastOneFormatAvailable(link) && "sm:w-1/2 lg:w-1/3"
- )}
- >
+ <div className={clsx("sm:overflow-y-auto sm:w-1/2 lg:w-1/3")}>
{setMode && onClose && (
<div className={clsx("flex justify-center -mb-11 pt-3 relative")}>
{(permissions === true || permissions?.canUpdate) &&
@@ -352,7 +348,7 @@ export default function LinkDetails({
if (iconTriggerRef.current) {
const rect =
iconTriggerRef.current.getBoundingClientRect();
- if (width >= 640 && atLeastOneFormatAvailable(link)) {
+ if (width >= 640) {
setIconPopoverPosition({
top: rect.bottom + window.scrollY,
left: rect.left + rect.width / 2 + window.scrollX, // center of LinkIcon
@@ -386,21 +382,9 @@ export default function LinkDetails({
iconWeight: "",
})
}
- className={clsx(
- width >= 640 &&
- atLeastOneFormatAvailable(link) &&
- "-translate-x-1/2"
- )}
- top={
- width >= 640 && atLeastOneFormatAvailable(link)
- ? iconPopoverPosition.top
- : undefined
- }
- left={
- width >= 640 && atLeastOneFormatAvailable(link)
- ? iconPopoverPosition.left
- : undefined
- }
+ className={clsx("sm:-translate-x-1/2")}
+ top={width >= 640 ? iconPopoverPosition.top : undefined}
+ left={width >= 640 ? iconPopoverPosition.left : undefined}
onClose={() => {
setIconPopover(false);
submit();
@@ -734,7 +718,7 @@ export default function LinkDetails({
</>
) : undefined}
- {!isReady() && !atLeastOneFormatAvailable(link) ? (
+ {!isReady ? (
<div
className={`w-full h-full flex flex-col justify-center p-10`}
>
@@ -751,9 +735,7 @@ export default function LinkDetails({
{t("check_back_later")}
</p>
</div>
- ) : link.url &&
- !isReady() &&
- atLeastOneFormatAvailable(link) ? (
+ ) : link.url && !isReady ? (
<div
className={`w-full h-full flex flex-col justify-center p-5`}
>
diff --git a/components/MobileNavigation.tsx b/components/MobileNavigation.tsx
index 22f3321c..968c08a4 100644
--- a/components/MobileNavigation.tsx
+++ b/components/MobileNavigation.tsx
@@ -6,12 +6,14 @@ import NewCollectionModal from "./ModalContent/NewCollectionModal";
import UploadFileModal from "./ModalContent/UploadFileModal";
import MobileNavigationButton from "./MobileNavigationButton";
import { useTranslation } from "next-i18next";
+import NewNoteModal from "./ModalContent/NewNoteModal";
type Props = {};
export default function MobileNavigation({}: Props) {
const { t } = useTranslation();
const [newLinkModal, setNewLinkModal] = useState(false);
+ const [newNoteModal, setNewNoteModal] = useState(false);
const [newCollectionModal, setNewCollectionModal] = useState(false);
const [uploadFileModal, setUploadFileModal] = useState(false);
@@ -55,6 +57,19 @@ export default function MobileNavigation({}: Props) {
{t("new_link")}
</div>
</li>
+ <li>
+ <div
+ onClick={() => {
+ (document?.activeElement as HTMLElement)?.blur();
+ setNewNoteModal(true);
+ }}
+ tabIndex={0}
+ role="button"
+ className="whitespace-nowrap"
+ >
+ {t("new_note")}
+ </div>
+ </li>
<li>
<div
onClick={() => {
@@ -88,6 +103,7 @@ export default function MobileNavigation({}: Props) {
</div>
</div>
{newLinkModal && <NewLinkModal onClose={() => setNewLinkModal(false)} />}
+ {newNoteModal && <NewNoteModal onClose={() => setNewNoteModal(false)} />}
{newCollectionModal && (
<NewCollectionModal onClose={() => setNewCollectionModal(false)} />
)}
diff --git a/components/ModalContent/NewNoteModal.tsx b/components/ModalContent/NewNoteModal.tsx
index 5b6978cb..bd3f0df2 100644
--- a/components/ModalContent/NewNoteModal.tsx
+++ b/components/ModalContent/NewNoteModal.tsx
@@ -95,7 +95,8 @@ export default function NewNoteModal({ onClose }: Props) {
h1.remove();
}
- const contentWithoutTitle = doc.body.innerHTML || "";
+ const contentWithoutTitle = doc.body.innerHTML.trim() || "<p>a</p>";
+ console.log(contentWithoutTitle);
const file = new File([contentWithoutTitle], title || "Untitled Note", {
type: "text/plain",
diff --git a/components/Preservation/Preservation.tsx b/components/Preservation/Preservation.tsx
index 83148815..a9dd5ece 100644
--- a/components/Preservation/Preservation.tsx
+++ b/components/Preservation/Preservation.tsx
@@ -16,9 +16,11 @@ import { PreservationContent } from "./PreservationContent";
export default function Preservation({
link,
standalone,
+ isReady,
}: {
link: LinkIncludingShortenedCollectionAndTags;
standalone: boolean;
+ isReady: boolean;
}) {
const { t } = useTranslation();
const router = useRouter();
@@ -71,7 +73,7 @@ export default function Preservation({
}, [router.query, link]);
useEffect(() => {
- if (router.pathname.includes("links")) {
+ if (router.pathname.includes("/links/[id]")) {
const query = {
...router.query,
format,
diff --git a/components/Preservation/PreservationContent.tsx b/components/Preservation/PreservationContent.tsx
index 406d57ec..c4a8e760 100644
--- a/components/Preservation/PreservationContent.tsx
+++ b/components/Preservation/PreservationContent.tsx
@@ -6,6 +6,9 @@ import {
ArchivedFormat,
LinkIncludingShortenedCollectionAndTags,
} from "@/types/global";
+import { BeatLoader } from "react-spinners";
+import { useTranslation } from "next-i18next";
+import { atLeastOneFormatAvailable } from "@/lib/shared/formatStats";
type Props = {
format: ArchivedFormat;
@@ -24,6 +27,7 @@ export const PreservationContent: React.FC<Props> = ({
const [monolithLoaded, setMonolithLoaded] = useState(false);
const [imageLoaded, setImageLoaded] = useState(false);
const prevFormatRef = useRef<ArchivedFormat | undefined>(undefined);
+ const { t } = useTranslation();
useEffect(() => {
if (prevFormatRef.current !== format) {
@@ -92,7 +96,7 @@ export const PreservationContent: React.FC<Props> = ({
return (
<>
{!imageLoaded && <PreservationSkeleton />}
- <div className="overflow-auto w-fit mx-auto h-full flex items-center">
+ <div className="overflow-auto w-fit mx-auto h-full">
<img
alt=""
src={`/api/v1/archives/${link.id}?format=${format}&_=${link.updatedAt}`}
@@ -107,5 +111,22 @@ export const PreservationContent: React.FC<Props> = ({
}
};
- return <>{renderFormat()}</>;
+ return (
+ <>
+ {!atLeastOneFormatAvailable(link) ? (
+ <div className={`w-full h-full flex flex-col justify-center p-10`}>
+ <BeatLoader
+ color="oklch(var(--p))"
+ className="mx-auto mb-3"
+ size={30}
+ />
+
+ <p className="text-center text-2xl">{t("preservation_in_queue")}</p>
+ <p className="text-center text-lg">{t("check_back_later")}</p>
+ </div>
+ ) : (
+ renderFormat()
+ )}
+ </>
+ );
};
diff --git a/components/TextEditor.tsx b/components/TextEditor.tsx
index 6509b00a..f4d6681f 100644
--- a/components/TextEditor.tsx
+++ b/components/TextEditor.tsx
@@ -1,4 +1,3 @@
-// TextEditor.tsx
import React, {
useEffect,
useState,
diff --git a/lib/api/preservationScheme/handleReadability.ts b/lib/api/preservationScheme/handleReadability.ts
index a64e98f0..b07fd134 100644
--- a/lib/api/preservationScheme/handleReadability.ts
+++ b/lib/api/preservationScheme/handleReadability.ts
@@ -10,6 +10,8 @@ const handleReadablility = async (
link: Link,
keepContent?: boolean
) => {
+ console.log("articleText", content);
+
const window = new JSDOM("").window;
const purify = DOMPurify(window);
const cleanedUpContent = purify.sanitize(content);
@@ -18,13 +20,27 @@ const handleReadablility = async (
link?.url ? { url: link.url || "" } : undefined
);
- const article = new Readability(dom.window.document).parse();
+ let article = new Readability(dom.window.document).parse();
const articleText = article?.textContent
.replace(/ +(?= )/g, "") // strip out multiple spaces
.replace(/(\r\n|\n|\r)/gm, " ") // strip out line breaks
.slice(0, 2047);
- if (articleText && articleText !== "") {
+ if ((articleText && articleText !== "") || link.type === "readable") {
+ if (!article) {
+ article = {
+ title: "",
+ byline: null,
+ dir: null,
+ lang: null,
+ content: "<p></p>",
+ textContent: "",
+ length: 1,
+ excerpt: "",
+ siteName: null,
+ } as any;
+ }
+
const collectionId = (
await prisma.link.findUnique({
where: { id: link.id },