⚡️⚡️⚡️ 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
remove note modal to focus on advanced bookmarking functionality
daniel31x137b3a4e48c1c9
diff --git a/components/LinkViews/LinkComponents/LinkIcon.tsx b/components/LinkViews/LinkComponents/LinkIcon.tsxindex 25a41ef9..6d00c258 100644--- a/components/LinkViews/LinkComponents/LinkIcon.tsx+++ b/components/LinkViews/LinkComponents/LinkIcon.tsx@@ -74,11 +74,6 @@ export default function LinkIcon({iconClasses={iconClasses}icon="bi-file-earmark-image"/>- ) : link.type === "readable" ? (- <LinkPlaceholderIcon- iconClasses={iconClasses}- icon="bi-file-earmark-text"- />) : // : link.type === "monolith" ? (// <LinkPlaceholderIcon// iconClasses={iconClasses + dimension}diff --git a/components/LinkViews/LinkComponents/LinkTypeBadge.tsx b/components/LinkViews/LinkComponents/LinkTypeBadge.tsxindex 0bfd0b28..c985ec17 100644--- a/components/LinkViews/LinkComponents/LinkTypeBadge.tsx+++ b/components/LinkViews/LinkComponents/LinkTypeBadge.tsx@@ -22,8 +22,6 @@ export default function LinkTypeBadge({return "bi-file-earmark-pdf";case "image":return "bi-file-earmark-image";- case "readable":- return "bi-file-earmark-text";default:return "bi-link-45deg";}@@ -45,9 +43,7 @@ export default function LinkTypeBadge({) : (<div className="flex gap-1 item-center select-none text-neutral duration-100 max-w-full w-fit"><i className={typeIcon() + ` text-md leading-none`}></i>- <p className="text-xs truncate">- {link.type === "readable" ? "note" : link.type}- </p>+ <p className="text-xs truncate">{link.type}</p></div>);}diff --git a/components/MobileNavigation.tsx b/components/MobileNavigation.tsxindex 968c08a4..22f3321c 100644--- a/components/MobileNavigation.tsx+++ b/components/MobileNavigation.tsx@@ -6,14 +6,12 @@ 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);@@ -57,19 +55,6 @@ 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><divonClick={() => {@@ -103,7 +88,6 @@ 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.tsxdeleted file mode 100644index bd3f0df2..00000000--- a/components/ModalContent/NewNoteModal.tsx+++ /dev/null@@ -1,192 +0,0 @@-import React, { useEffect, useState, useRef } from "react";-import CollectionSelection from "@/components/InputSelect/CollectionSelection";-import TagSelection from "@/components/InputSelect/TagSelection";-import unescapeString from "@/lib/client/unescapeString";-import { useRouter } from "next/router";-import Modal from "../Modal";-import { useTranslation } from "next-i18next";-import { useCollections } from "@/hooks/store/collections";-import { useUploadFile } from "@/hooks/store/links";-import toast from "react-hot-toast";-import { PostLinkSchemaType } from "@/lib/shared/schemaValidation";-import TextEditor, { TextEditorRef } from "../TextEditor";-import DOMPurify from "dompurify";--type Props = {- onClose: () => void;-};--export default function NewNoteModal({ onClose }: Props) {- const { t } = useTranslation();- const initial = {- name: "",- description: "",- type: "readable",- tags: [],- collection: {- id: undefined,- name: "",- },- } as PostLinkSchemaType;-- const [link, setLink] = useState<PostLinkSchemaType>(initial);- const [submitLoader, setSubmitLoader] = useState(false);- const [optionsExpanded, setOptionsExpanded] = useState(false);- const router = useRouter();- const { data: collections = [] } = useCollections();-- const editorRef = useRef<TextEditorRef>(null);-- const setCollection = (e: any) => {- if (e?.__isNew__) e.value = undefined;- setLink({- ...link,- collection: { id: e?.value, name: e?.label },- });- };-- const setTags = (e: any) => {- const tagNames = e.map((e: any) => ({ name: e.label }));- setLink({ ...link, tags: tagNames });- };-- useEffect(() => {- if (router.pathname.startsWith("/collections/") && router.query.id) {- const currentCollection = collections.find(- (e) => e.id === Number(router.query.id)- );-- if (currentCollection && currentCollection.ownerId)- setLink({- ...initial,- collection: {- id: currentCollection.id,- name: currentCollection.name,- },- });- } else- setLink({- ...initial,- collection: { name: "Unorganized" },- });- }, [router.pathname, router.query.id, collections]);-- const uploadFile = useUploadFile();-- const submit = async () => {- if (submitLoader) return;- setSubmitLoader(true);-- const load = toast.loading(t("creating_link"));-- try {- const editor = editorRef.current?.getEditor();- if (!editor) throw new Error("Editor not initialized");-- const sanitizedHTML = DOMPurify.sanitize(editor.getHTML());-- const parser = new DOMParser();- const doc = parser.parseFromString(sanitizedHTML, "text/html");-- const h1 = doc.querySelector("h1");- const title = h1 ? h1.textContent?.trim() : link.name;-- if (h1) {- h1.remove();- }-- const contentWithoutTitle = doc.body.innerHTML.trim() || "<p>a</p>";- console.log(contentWithoutTitle);-- const file = new File([contentWithoutTitle], title || "Untitled Note", {- type: "text/plain",- });-- await uploadFile.mutateAsync(- { link, file },- {- onSettled: (data, error) => {- setSubmitLoader(false);- toast.dismiss(load);-- if (error) {- toast.error(error.message);- } else {- onClose();- toast.success(t("created_success"));- }- },- }- );- } catch (error: any) {- setSubmitLoader(false);- toast.dismiss(load);- toast.error(error.message || "An error occurred");- }- };-- return (- <Modal toggleModal={onClose}>- <p className="text-xl font-thin">{t("write_new_note")}</p>- <div className="divider mb-2 mt-1"></div>- <TextEditor ref={editorRef} editable />- <div className={"mt-2"}>- {optionsExpanded && (- <div className="mt-5">- <div className="grid gap-3">- <div>- <p className="mb-2">{t("tags")}</p>- <TagSelection- onChange={setTags}- defaultValue={link.tags?.map((e) => ({- label: e.name,- value: e.id,- }))}- />- </div>- <div>- <p className="mb-2">{t("collection")}</p>- {link.collection?.name && (- <CollectionSelection- onChange={setCollection}- defaultValue={{- value: link.collection?.id,- label: link.collection?.name || "Unorganized",- }}- />- )}- </div>- <div className="sm:col-span-2">- <p className="mb-2">{t("description")}</p>- <textarea- value={unescapeString(link.description || "") || ""}- onChange={(e) =>- setLink({ ...link, description: e.target.value })- }- placeholder={t("link_description_placeholder")}- className="resize-none w-full h-32 rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"- />- </div>- </div>- </div>- )}- </div>- <div className="flex justify-between items-center mt-5">- <div- onClick={() => setOptionsExpanded(!optionsExpanded)}- className={`rounded-md cursor-pointer btn btn-sm btn-ghost duration-100 flex items-center px-2 w-fit text-sm`}- >- <p>{optionsExpanded ? t("hide_options") : t("more_options")}</p>- <i className={`bi-chevron-${optionsExpanded ? "up" : "down"}`}></i>- </div>- <button- className="btn btn-accent dark:border-violet-400 text-white"- onClick={submit}- disabled={submitLoader}- >- {submitLoader ? t("creating...") : t("create_link")}- </button>- </div>- </Modal>- );-}diff --git a/components/Navbar.tsx b/components/Navbar.tsxindex 9a9856bf..fddf5e56 100644--- a/components/Navbar.tsx+++ b/components/Navbar.tsx@@ -12,7 +12,6 @@ import { dropdownTriggerer } from "@/lib/client/utils";import MobileNavigation from "./MobileNavigation";import ProfileDropdown from "./ProfileDropdown";import { useTranslation } from "next-i18next";-import NewNoteModal from "./ModalContent/NewNoteModal";export default function Navbar() {const { t } = useTranslation();@@ -38,7 +37,6 @@ export default function Navbar() {const [newLinkModal, setNewLinkModal] = useState(false);const [newCollectionModal, setNewCollectionModal] = useState(false);const [uploadFileModal, setUploadFileModal] = useState(false);- const [newNoteModal, setNewNoteModal] = useState(false);return (<div className="flex justify-between gap-2 items-center pl-3 pr-4 py-2 border-solid border-b-neutral-content border-b">@@ -85,19 +83,6 @@ export default function Navbar() {{t("new_link")}</div></li>- <li>- <div- onClick={() => {- (document?.activeElement as HTMLElement)?.blur();- setNewNoteModal(true);- }}- tabIndex={0}- role="button"- className="whitespace-nowrap flex gap-2"- >- {t("new_note")}- </div>- </li><li><divonClick={() => {@@ -148,7 +133,6 @@ export default function Navbar() {{uploadFileModal && (<UploadFileModal onClose={() => setUploadFileModal(false)} />)}- {newNoteModal && <NewNoteModal onClose={() => setNewNoteModal(false)} />}</div>);}diff --git a/components/TextEditor.tsx b/components/TextEditor.tsxdeleted file mode 100644index 5d965590..00000000--- a/components/TextEditor.tsx+++ /dev/null@@ -1,132 +0,0 @@-import React, {- useEffect,- useState,- forwardRef,- useImperativeHandle,-} from "react";-import { formatAvailable } from "@/lib/shared/formatStats";-import {- ArchivedFormat,- LinkIncludingShortenedCollectionAndTags,-} from "@/types/global";-import { useRouter } from "next/router";-import { useTranslation } from "next-i18next";-import clsx from "clsx";-import usePermissions from "@/hooks/usePermissions";-import { EditorContent, useEditor } from "@tiptap/react";-import StarterKit from "@tiptap/starter-kit";-import Image from "@tiptap/extension-image";-import TipTapLink from "@tiptap/extension-link";-import Highlight from "@tiptap/extension-highlight";-import TextAlign from "@tiptap/extension-text-align";-import MenuBar from "@/components/Editor/MenuBar";-import TaskItem from "@tiptap/extension-task-item";-import TaskList from "@tiptap/extension-task-list";-import ListItem from "@tiptap/extension-list-item";-import Placeholder from "@tiptap/extension-placeholder";-import Document from "@tiptap/extension-document";--type Props = {- link?: LinkIncludingShortenedCollectionAndTags;- className?: string;- editable?: boolean;-};--export type TextEditorRef = {- getEditor: () => any;-};--const TextEditor = forwardRef<TextEditorRef, Props>(- ({ link, className, editable }, ref) => {- const { t } = useTranslation();- const [linkContent, setLinkContent] = useState("");-- const editor = useEditor({- extensions: [- Document.extend({- content: "heading block*",- }),- TaskList,- TaskItem.configure({- nested: true,- }),- StarterKit.configure({- document: false,- }),- Image,- ListItem,- Highlight,- TextAlign.configure({- types: ["heading", "paragraph"],- }),- TipTapLink.configure({- openOnClick: false,- }),- Placeholder.configure({- placeholder: ({ node }: any) => {- if (node.type.name === "heading") {- return t("add_a_title_placeholder");- }-- return t("write_notes_here_placeholder");- },- }),- ],- immediatelyRender: false,- content: linkContent || `<h1>${link?.name || ""}</h1>\n<p></p>`,- editable: editable || false,- editorProps: {- attributes: {- class: clsx(- "w-full h-[calc(80vh-10.75rem)] reader-view rounded-md bg-base-200 focus:outline-none border-neutral-content focus:border-primary border-solid border p-3 overflow-auto duration-100"- ),- },- },- });-- useImperativeHandle(ref, () => ({- getEditor: () => editor,- }));-- const router = useRouter();- const isPublicRoute = router.pathname.startsWith("/public");-- useEffect(() => {- const fetchLinkContent = async (- l: LinkIncludingShortenedCollectionAndTags- ) => {- if (formatAvailable(l, "readable")) {- const response = await fetch(- `/api/v1/archives/${l?.id}?format=${ArchivedFormat.readability}&_=${l.updatedAt}`- );- const data = await response?.json();- const content = data?.content || "";- const combinedContent = `<h1>${l.name}</h1>\n${content}`;- setLinkContent(combinedContent);- }- };-- if (link) {- fetchLinkContent(link);- }- }, [link]);-- useEffect(() => {- const a = editor?.getText();- console.log(a);- }, [editable, editor]);-- return (- editor && (- <div className={clsx(className)}>- <MenuBar editor={editor} />- <EditorContent editor={editor} />- </div>- )- );- }-);--TextEditor.displayName = "TextEditor";--export default TextEditor;diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.tsindex e649faff..76e0eb85 100644--- a/lib/api/controllers/links/postLink.ts+++ b/lib/api/controllers/links/postLink.ts@@ -96,7 +96,6 @@ export default async function postLink(data: {url: link.url?.trim() || null,name,- preview: link.type === "readable" ? "unavailable" : undefined,description: link.description,type: linkType,createdBy: {diff --git a/lib/api/preservationScheme/handleReadability.ts b/lib/api/preservationScheme/handleReadability.tsindex 0a143516..01e5830f 100644--- a/lib/api/preservationScheme/handleReadability.ts+++ b/lib/api/preservationScheme/handleReadability.ts@@ -13,32 +13,15 @@ const handleReadablility = async (const window = new JSDOM("").window;const purify = DOMPurify(window);const cleanedUpContent = purify.sanitize(content);- const dom = new JSDOM(- cleanedUpContent,- link?.url ? { url: link.url || "" } : undefined- );+ const dom = new JSDOM(cleanedUpContent, { url: link.url || "" });- let article = new Readability(dom.window.document).parse();+ const 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 !== "") || link.type === "readable") {- if (!article) {- article = {- title: "",- byline: null,- dir: null,- lang: null,- content: "<p></p>",- textContent: "",- length: 1,- excerpt: "",- siteName: null,- } as any;- }-+ if (articleText && articleText !== "") {const collectionId = (await prisma.link.findUnique({where: { id: link.id },diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.tsindex 054a72e3..30a9e952 100644--- a/lib/shared/schemaValidation.ts+++ b/lib/shared/schemaValidation.ts@@ -97,7 +97,7 @@ export const PostSessionSchema = z.object({});export const PostLinkSchema = z.object({- type: z.enum(["url", "pdf", "image", "readable"]).nullish(),+ type: z.enum(["url", "pdf", "image"]).nullish(),url: z.string().trim().max(2048).url().optional(),name: z.string().trim().max(2048).optional(),description: z.string().trim().max(2048).optional(),diff --git a/package.json b/package.jsonindex 903798ec..12a53337 100644--- a/package.json+++ b/package.json@@ -36,7 +36,6 @@"@tiptap/extension-highlight": "^2.11.2","@tiptap/extension-image": "^2.11.2","@tiptap/extension-link": "^2.11.2",- "@tiptap/extension-placeholder": "^2.11.5","@tiptap/extension-task-item": "^2.11.2","@tiptap/extension-task-list": "^2.11.2","@tiptap/extension-text-align": "^2.11.2",diff --git a/public/locales/en/common.json b/public/locales/en/common.jsonindex 16395055..9695504a 100644--- a/public/locales/en/common.json+++ b/public/locales/en/common.json@@ -463,9 +463,5 @@"search_for_links": "Search for Links","search_query_invalid_symbol": "The search query should not contain '%'.","open_modal_new_tab": "Open this modal in a new tab",- "file": "File",- "write_new_note": "Write a New Note",- "new_note": "New Note",- "add_a_title_placeholder": "Add a title...",- "write_notes_here_placeholder": "Write some notes here..."+ "file": "File"}\ No newline at end of filediff --git a/styles/globals.css b/styles/globals.cssindex 2009ce98..d30e3bde 100644--- a/styles/globals.css+++ b/styles/globals.css@@ -297,22 +297,6 @@cursor: pointer;}-.reader-view h1.is-editor-empty:first-child::before {- color: oklch(var(--n));- content: attr(data-placeholder);- float: left;- height: 0;- pointer-events: none;-}--.reader-view h1 + p.is-empty::before {- color: oklch(var(--n));- content: attr(data-placeholder);- float: left;- height: 0;- pointer-events: none;-}-.read-only ul[data-type="taskList"] {pointer-events: none;}diff --git a/yarn.lock b/yarn.lockindex b3396f15..b6f859e4 100644--- a/yarn.lock+++ b/yarn.lock@@ -2116,11 +2116,6 @@resolved "https://registry.yarnpkg.com/@tiptap/extension-paragraph/-/extension-paragraph-2.11.2.tgz#b4e99129b1c5959e2926b9563ced89755e0d4d81"integrity sha512-iydTjeZbPJuqctOaAx7QebLPvz9J/hBxPptuhe4GZmqInknAk7+SFJagYeGNb14wfXKOvDZ9DMqv6mBiqSA90Q==-"@tiptap/extension-placeholder@^2.11.5":- version "2.11.5"- resolved "https://registry.yarnpkg.com/@tiptap/extension-placeholder/-/extension-placeholder-2.11.5.tgz#de8412b486865b379f121a502ae3de8be7fa2d27"- integrity sha512-Pr+0Ju/l2ZvXMd9VQxtaoSZbs0BBp1jbBDqwms88ctpyvQFRfLSfSkqudQcSHyw2ROOz2E31p/7I7fpI8Y0CLA==-"@tiptap/extension-strike@^2.11.2":version "2.11.2"resolved "https://registry.yarnpkg.com/@tiptap/extension-strike/-/extension-strike-2.11.2.tgz#9b5b698da5a024219e2ecf438c3b503d9b812fbe"