Allow users to enable merging links
This commit is contained in:
parent
281b376eac
commit
750aa294d0
|
@ -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)}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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 !== ""
|
||||
? newHashedPassword
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "mergeDuplicateLinks" BOOLEAN NOT NULL DEFAULT false;
|
|
@ -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)
|
||||
|
|
Ŝarĝante…
Reference in New Issue