urls are now editable
This commit is contained in:
parent
7bd3872195
commit
8bb6e32bfa
|
@ -327,30 +327,6 @@ export default function LinkDetails({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{link.url && (
|
|
||||||
<>
|
|
||||||
<br />
|
|
||||||
|
|
||||||
<p className="text-sm mb-2 text-neutral">{t("link")}</p>
|
|
||||||
|
|
||||||
<div className="relative">
|
|
||||||
<div className="rounded-md p-2 bg-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14">
|
|
||||||
<Link
|
|
||||||
href={link.url}
|
|
||||||
title={link.url}
|
|
||||||
target="_blank"
|
|
||||||
className={clsx(mode === "edit" && "pointer-events-none")}
|
|
||||||
>
|
|
||||||
{link.url}
|
|
||||||
</Link>
|
|
||||||
<div className="absolute right-0 px-2 bg-base-200">
|
|
||||||
<CopyButton text={link.url} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{mode === "edit" && (
|
{mode === "edit" && (
|
||||||
<>
|
<>
|
||||||
<br />
|
<br />
|
||||||
|
@ -369,6 +345,41 @@ export default function LinkDetails({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{link.url && mode === "view" ? (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<p className="text-sm mb-2 text-neutral">{t("link")}</p>
|
||||||
|
|
||||||
|
<div className="relative">
|
||||||
|
<div className="rounded-md p-2 bg-base-200 hide-scrollbar overflow-x-auto whitespace-nowrap flex justify-between items-center gap-2 pr-14">
|
||||||
|
<Link href={link.url} title={link.url} target="_blank">
|
||||||
|
{link.url}
|
||||||
|
</Link>
|
||||||
|
<div className="absolute right-0 px-2 bg-base-200">
|
||||||
|
<CopyButton text={link.url} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : activeLink.url ? (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p className="text-sm mb-2 text-neutral relative w-fit flex justify-between">
|
||||||
|
{t("link")}
|
||||||
|
</p>
|
||||||
|
<TextInput
|
||||||
|
value={link.url || ""}
|
||||||
|
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
||||||
|
placeholder={t("placeholder_example_link")}
|
||||||
|
className="bg-base-200"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : undefined}
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { prisma } from "@/lib/api/db";
|
||||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||||
import { UsersAndCollections } from "@prisma/client";
|
import { UsersAndCollections } from "@prisma/client";
|
||||||
import getPermission from "@/lib/api/getPermission";
|
import getPermission from "@/lib/api/getPermission";
|
||||||
import { moveFiles } from "@/lib/api/manageLinkFiles";
|
import { moveFiles, removeFiles } from "@/lib/api/manageLinkFiles";
|
||||||
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
|
|
||||||
export default async function updateLinkById(
|
export default async function updateLinkById(
|
||||||
userId: number,
|
userId: number,
|
||||||
|
@ -89,16 +90,32 @@ export default async function updateLinkById(
|
||||||
status: 401,
|
status: 401,
|
||||||
};
|
};
|
||||||
else {
|
else {
|
||||||
|
const oldLink = await prisma.link.findUnique({
|
||||||
|
where: {
|
||||||
|
id: linkId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (oldLink && oldLink?.url !== data.url) {
|
||||||
|
await removeFiles(oldLink.id, oldLink.collectionId);
|
||||||
|
}
|
||||||
|
|
||||||
const updatedLink = await prisma.link.update({
|
const updatedLink = await prisma.link.update({
|
||||||
where: {
|
where: {
|
||||||
id: linkId,
|
id: linkId,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
url: data.url,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
icon: data.icon,
|
icon: data.icon,
|
||||||
iconWeight: data.iconWeight,
|
iconWeight: data.iconWeight,
|
||||||
color: data.color,
|
color: data.color,
|
||||||
|
image: oldLink?.url !== data.url ? null : undefined,
|
||||||
|
pdf: oldLink?.url !== data.url ? null : undefined,
|
||||||
|
readable: oldLink?.url !== data.url ? null : undefined,
|
||||||
|
monolith: oldLink?.url !== data.url ? null : undefined,
|
||||||
|
preview: oldLink?.url !== data.url ? null : undefined,
|
||||||
collection: {
|
collection: {
|
||||||
connect: {
|
connect: {
|
||||||
id: data.collection.id,
|
id: data.collection.id,
|
||||||
|
|
|
@ -54,7 +54,20 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||||
response: "Invalid URL.",
|
response: "Invalid URL.",
|
||||||
});
|
});
|
||||||
|
|
||||||
await deleteArchivedFiles(link);
|
await prisma.link.update({
|
||||||
|
where: {
|
||||||
|
id: link.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
image: null,
|
||||||
|
pdf: null,
|
||||||
|
readable: null,
|
||||||
|
monolith: null,
|
||||||
|
preview: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await removeFiles(link.id, link.collection.id);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
response: "Link is being archived.",
|
response: "Link is being archived.",
|
||||||
|
@ -72,20 +85,3 @@ const getTimezoneDifferenceInMinutes = (future: Date, past: Date) => {
|
||||||
|
|
||||||
return diffInMinutes;
|
return diffInMinutes;
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteArchivedFiles = async (link: Link & { collection: Collection }) => {
|
|
||||||
await prisma.link.update({
|
|
||||||
where: {
|
|
||||||
id: link.id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
image: null,
|
|
||||||
pdf: null,
|
|
||||||
readable: null,
|
|
||||||
monolith: null,
|
|
||||||
preview: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await removeFiles(link.id, link.collection.id);
|
|
||||||
};
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue