⚡️⚡️⚡️ 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
names should be auto generated instead of descriptions + add default value to name field
daniel31x13bcb6aea119ca
diff --git a/components/ModalContent/NewLinkModal.tsx b/components/ModalContent/NewLinkModal.tsxindex 46c9ffe9..756f0e4f 100644--- a/components/ModalContent/NewLinkModal.tsx+++ b/components/ModalContent/NewLinkModal.tsx@@ -155,7 +155,7 @@ export default function NewLinkModal({ onClose }: Props) {<TextInputvalue={link.name}onChange={(e) => setLink({ ...link, name: e.target.value })}- placeholder="e.g. Example Link"+ placeholder="Will be auto generated if left empty."className="bg-base-200"/></div>@@ -177,7 +177,7 @@ export default function NewLinkModal({ onClose }: Props) {onChange={(e) =>setLink({ ...link, description: e.target.value })}- placeholder="Will be auto generated if nothing is provided."+ placeholder="Notes, thoughts, etc."className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100"/></div>diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.tsindex 4c42f6cc..7f77aeb3 100644--- a/lib/api/controllers/links/postLink.ts+++ b/lib/api/controllers/links/postLink.ts@@ -160,12 +160,13 @@ export default async function postLink(link.collection.name = link.collection.name.trim();- const description =- link.description && link.description !== ""- ? link.description- : link.url- ? await getTitle(link.url)- : undefined;+ const title =+ !(link.name && link.name !== "") && link.url+ ? await getTitle(link.url)+ : "";++ const name =+ link.name && link.name !== "" ? link.name : link.url ? title : "";const validatedUrl = link.url ? await validateUrlSize(link.url) : undefined;@@ -184,8 +185,8 @@ export default async function postLink(const newLink = await prisma.link.create({data: {url: link.url?.trim().replace(/\/+$/, "") || null,- name: link.name,- description,+ name,+ description: link.description,type: linkType,collection: {connect: {diff --git a/prisma/migrations/20240525002215_add_default_value_to_link_name/migration.sql b/prisma/migrations/20240525002215_add_default_value_to_link_name/migration.sqlnew file mode 100644index 00000000..b91c845e--- /dev/null+++ b/prisma/migrations/20240525002215_add_default_value_to_link_name/migration.sql@@ -0,0 +1,2 @@+-- AlterTable+ALTER TABLE "Link" ALTER COLUMN "name" SET DEFAULT '';diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex bd4e9824..6bc32004 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -123,7 +123,7 @@ model UsersAndCollections {model Link {id Int @id @default(autoincrement())- name String+ name String @default("")type String @default("url")description String @default("")pinnedBy User[]diff --git a/scripts/migration/descriptionToName.js b/scripts/migration/descriptionToName.jsnew file mode 100644index 00000000..16b85cc3--- /dev/null+++ b/scripts/migration/descriptionToName.js@@ -0,0 +1,70 @@+// [Optional, but recommended]++// We decided that the "name" field should be the auto-generated field instead of the "description" field, so we need to+// move the data from the "description" field to the "name" field for links that have an empty name.++// This script is meant to be run only once.++const { PrismaClient } = require("@prisma/client");++const prisma = new PrismaClient();++async function main() {+ console.log("Starting...");++ const count = await prisma.link.count({+ where: {+ name: "",+ description: {+ not: "",+ },+ },+ });++ console.log(+ `Applying the changes to ${count} ${+ count == 1 ? "link" : "links"+ } in 10 seconds...`+ );++ await new Promise((resolve) => setTimeout(resolve, 10000));++ console.log("Applying the changes...");++ const links = await prisma.link.findMany({+ where: {+ name: "",+ description: {+ not: "",+ },+ },+ select: {+ id: true,+ description: true,+ },+ });++ for (const link of links) {+ await prisma.link.update({+ where: {+ id: link.id,+ },+ data: {+ name: link.description,+ description: "",+ },+ });+ }++ console.log("Done!");+}++main()+ .catch((e) => {+ throw e;+ })+ .finally(async () => {+ await prisma.$disconnect();+ });++// Run the script with `node scripts/migration/descriptionToName.js`