⚡️⚡️⚡️ 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
final touch
daniel31x1388d73703f8a0
diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsxindex dcbbe0ff..ec586ea6 100644--- a/components/InputSelect/CollectionSelection.tsx+++ b/components/InputSelect/CollectionSelection.tsx@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";import { styles } from "./styles";import { Options } from "./types";import CreatableSelect from "react-select/creatable";+import Select from "react-select";type Props = {onChange: any;@@ -14,12 +15,14 @@ type Props = {value?: number;}| undefined;+ creatable?: boolean;};export default function CollectionSelection({onChange,defaultValue,showDefaultValue = true,+ creatable = true,}: Props) {const { collections } = useCollectionStore();const router = useRouter();@@ -47,16 +50,31 @@ export default function CollectionSelection({setOptions(formatedCollections);}, [collections]);- return (- <CreatableSelect- isClearable={false}- className="react-select-container"- classNamePrefix="react-select"- onChange={onChange}- options={options}- styles={styles}- defaultValue={showDefaultValue ? defaultValue : null}- // menuPosition="fixed"- />- );+ if (creatable) {+ return (+ <CreatableSelect+ isClearable={false}+ className="react-select-container"+ classNamePrefix="react-select"+ onChange={onChange}+ options={options}+ styles={styles}+ defaultValue={showDefaultValue ? defaultValue : null}+ // menuPosition="fixed"+ />+ );+ } else {+ return (+ <Select+ isClearable={false}+ className="react-select-container"+ classNamePrefix="react-select"+ onChange={onChange}+ options={options}+ styles={styles}+ defaultValue={showDefaultValue ? defaultValue : null}+ // menuPosition="fixed"+ />+ );+ }}diff --git a/components/ModalContent/BulkEditLinksModal.tsx b/components/ModalContent/BulkEditLinksModal.tsxindex e5527466..07b3914a 100644--- a/components/ModalContent/BulkEditLinksModal.tsx+++ b/components/ModalContent/BulkEditLinksModal.tsx@@ -20,6 +20,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {const setCollection = (e: any) => {const collectionId = e?.value || null;+ console.log(updatedValues);setUpdatedValues((prevValues) => ({ ...prevValues, collectionId }));};@@ -66,6 +67,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {<CollectionSelectionshowDefaultValue={false}onChange={setCollection}+ creatable={false}/></div>@@ -74,7 +76,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {<TagSelection onChange={setTags} /></div></div>- <div className="ml-auto w-1/2 p-3">+ <div className="sm:ml-auto w-1/2 p-3"><label className="flex items-center gap-2 "><inputtype="checkbox"diff --git a/components/ModalContent/EditLinkModal.tsx b/components/ModalContent/EditLinkModal.tsxindex 9ba27fef..b77b76c7 100644--- a/components/ModalContent/EditLinkModal.tsx+++ b/components/ModalContent/EditLinkModal.tsx@@ -124,6 +124,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {label: "Unorganized",}}+ creatable={false}/>) : null}</div>diff --git a/lib/api/controllers/links/linkId/updateLinkById.ts b/lib/api/controllers/links/linkId/updateLinkById.tsindex 6944999f..62b2945c 100644--- a/lib/api/controllers/links/linkId/updateLinkById.ts+++ b/lib/api/controllers/links/linkId/updateLinkById.ts@@ -16,6 +16,10 @@ export default async function updateLinkById(};const collectionIsAccessible = await getPermission({ userId, linkId });+ const targetCollectionIsAccessible = await getPermission({+ userId,+ collectionId: data.collection.id,+ });const memberHasAccess = collectionIsAccessible?.members.some((e: UsersAndCollections) => e.userId === userId && e.canUpdate@@ -25,6 +29,28 @@ export default async function updateLinkById(collectionIsAccessible?.ownerId === data.collection.ownerId &&data.collection.ownerId === userId;+ const targetCollectionsAccessible =+ targetCollectionIsAccessible?.ownerId === userId;++ const targetCollectionMatchesData = data.collection.id+ ? data.collection.id === targetCollectionIsAccessible?.id+ : true && data.collection.name+ ? data.collection.name === targetCollectionIsAccessible?.name+ : true && data.collection.ownerId+ ? data.collection.ownerId === targetCollectionIsAccessible?.ownerId+ : true;++ if (!targetCollectionsAccessible)+ return {+ response: "Target collection is not accessible.",+ status: 401,+ };+ else if (!targetCollectionMatchesData)+ return {+ response: "Target collection does not match the data.",+ status: 401,+ };+const unauthorizedSwitchCollection =!isCollectionOwner && collectionIsAccessible?.id !== data.collection.id;diff --git a/lib/api/getPermission.ts b/lib/api/getPermission.tsindex 61dc5c50..93dd04ce 100644--- a/lib/api/getPermission.ts+++ b/lib/api/getPermission.ts@@ -3,12 +3,14 @@ import { prisma } from "@/lib/api/db";type Props = {userId: number;collectionId?: number;+ collectionName?: string;linkId?: number;};export default async function getPermission({userId,collectionId,+ collectionName,linkId,}: Props) {if (linkId) {@@ -24,10 +26,11 @@ export default async function getPermission({});return check;- } else if (collectionId) {+ } else if (collectionId || collectionName) {const check = await prisma.collection.findFirst({where: {- id: collectionId,+ id: collectionId || undefined,+ name: collectionName || undefined,OR: [{ ownerId: userId }, { members: { some: { userId } } }],},include: { members: true },diff --git a/store/links.ts b/store/links.tsindex 01935e41..408a3eea 100644--- a/store/links.ts+++ b/store/links.ts@@ -152,6 +152,11 @@ const useLinkStore = create<LinkStore>()((set) => ({links.some((link) => link.id === e.id)? {...e,+ collectionId: newData.collectionId ?? e.collectionId,+ collection: {+ ...e.collection,+ id: newData.collectionId ?? e.collection.id,+ },tags: removePreviousTags? [...(newData.tags ?? [])]: [...e.tags, ...(newData.tags ?? [])],