⚡️⚡️⚡️ 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
Allow users to enable merging links
Isaac Wise750aa294d0ff
diff --git a/components/CollectionListing.tsx b/components/CollectionListing.tsxindex 01d81d06..1a309c4c 100644--- a/components/CollectionListing.tsx+++ b/components/CollectionListing.tsx@@ -223,11 +223,10 @@ const renderItem = (return (<div ref={provided.innerRef} {...provided.draggableProps} className="mb-1"><div- className={`${- currentPath === `/collections/${collection.id}`+ className={`${currentPath === `/collections/${collection.id}`? "bg-primary/20 is-active": "hover:bg-neutral/20"- } duration-100 flex gap-1 items-center pr-2 pl-1 rounded-md`}+ } duration-100 flex gap-1 items-center pr-2 pl-1 rounded-md`}>{Icon(item as ExtendedTreeItem, onExpand, onCollapse)}diff --git a/components/ModalContent/NewLinkModal.tsx b/components/ModalContent/NewLinkModal.tsxindex 20bcef25..46c9ffe9 100644--- a/components/ModalContent/NewLinkModal.tsx+++ b/components/ModalContent/NewLinkModal.tsx@@ -109,7 +109,6 @@ export default function NewLinkModal({ onClose }: Props) {toast.success(`Created!`);onClose();} else toast.error(response.data as string);-setSubmitLoader(false);return response;diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.tsindex eb82949c..0dcc5dcb 100644--- a/lib/api/controllers/links/postLink.ts+++ b/lib/api/controllers/links/postLink.ts@@ -87,6 +87,28 @@ export default async function postLink(return { response: "Uncaught error.", status: 500 };}+ const user = await prisma.user.findUnique({+ where: {+ id: userId,+ },+ });++ const existingLink = await prisma.link.findFirst({+ where: {+ url: link.url,+ collection: {+ ownerId: userId,+ },+ },+ });++ if (existingLink && user?.mergeDuplicateLinks) {+ return {+ response: "Link already exists",+ status: 409,+ };+ }+const numberOfLinksTheUserHas = await prisma.link.count({where: {collection: {diff --git a/lib/api/controllers/users/userId/updateUserById.ts b/lib/api/controllers/users/userId/updateUserById.tsindex e4e57265..7459d1d7 100644--- a/lib/api/controllers/users/userId/updateUserById.ts+++ b/lib/api/controllers/users/userId/updateUserById.ts@@ -190,6 +190,7 @@ export default async function updateUserById(archiveAsPDF: data.archiveAsPDF,archiveAsWaybackMachine: data.archiveAsWaybackMachine,linksRouteTo: data.linksRouteTo,+ mergeDuplicateLinks: data.mergeDuplicateLinks,password:data.newPassword && data.newPassword !== ""? newHashedPassworddiff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsxindex 2456e92c..b5810456 100644--- a/pages/settings/preference.tsx+++ b/pages/settings/preference.tsx@@ -16,6 +16,8 @@ export default function Appearance() {const { account, updateAccount } = useAccountStore();const [user, setUser] = useState<AccountSettings>(account);+ const [mergeDuplicateLinks, setMergeDuplicateLinks] =+ useState<boolean>(false);const [archiveAsScreenshot, setArchiveAsScreenshot] =useState<boolean>(false);const [archiveAsPDF, setArchiveAsPDF] = useState<boolean>(false);@@ -32,6 +34,7 @@ export default function Appearance() {archiveAsPDF,archiveAsWaybackMachine,linksRouteTo,+ mergeDuplicateLinks,});}, [account,@@ -39,6 +42,7 @@ export default function Appearance() {archiveAsPDF,archiveAsWaybackMachine,linksRouteTo,+ mergeDuplicateLinks,]);function objectIsEmpty(obj: object) {@@ -51,6 +55,7 @@ export default function Appearance() {setArchiveAsPDF(account.archiveAsPDF);setArchiveAsWaybackMachine(account.archiveAsWaybackMachine);setLinksRouteTo(account.linksRouteTo);+ setMergeDuplicateLinks(account.mergeDuplicateLinks);}}, [account]);@@ -144,6 +149,13 @@ export default function Appearance() {<p className="capitalize text-3xl font-thin inline">Link Settings</p><div className="divider my-3"></div>+ <div className="mb-3">+ <Checkbox+ label="Merge duplicate links"+ state={mergeDuplicateLinks}+ onClick={() => setMergeDuplicateLinks(!mergeDuplicateLinks)}+ />+ </div><p>Clicking on Links should:</p><div className="p-3">diff --git a/prisma/migrations/20240305045701_add_merge_duplicate_links/migration.sql b/prisma/migrations/20240305045701_add_merge_duplicate_links/migration.sqlnew file mode 100644index 00000000..cb534b90--- /dev/null+++ b/prisma/migrations/20240305045701_add_merge_duplicate_links/migration.sql@@ -0,0 +1,2 @@+-- AlterTable+ALTER TABLE "User" ADD COLUMN "mergeDuplicateLinks" BOOLEAN NOT NULL DEFAULT false;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 6bdc8deb..64945caa 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -43,6 +43,7 @@ model User {accessTokens AccessToken[]subscriptions Subscription?linksRouteTo LinksRouteTo @default(ORIGINAL)+ mergeDuplicateLinks Boolean @default(false)archiveAsScreenshot Boolean @default(true)archiveAsPDF Boolean @default(true)archiveAsWaybackMachine Boolean @default(false)