commit
1f0a952a63
|
@ -2,7 +2,11 @@ import {
|
||||||
CollectionIncludingMembersAndLinkCount,
|
CollectionIncludingMembersAndLinkCount,
|
||||||
LinkIncludingShortenedCollectionAndTags,
|
LinkIncludingShortenedCollectionAndTags,
|
||||||
} from "@/types/global";
|
} from "@/types/global";
|
||||||
import { faFolder, faEllipsis } from "@fortawesome/free-solid-svg-icons";
|
import {
|
||||||
|
faFolder,
|
||||||
|
faEllipsis,
|
||||||
|
faLink,
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
@ -31,8 +35,18 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
|
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
|
const { links } = useLinkStore();
|
||||||
|
|
||||||
const { account } = useAccountStore();
|
const { account } = useAccountStore();
|
||||||
|
|
||||||
|
let shortendURL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
shortendURL = new URL(link.url).host.toLowerCase();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] =
|
||||||
useState<CollectionIncludingMembersAndLinkCount>(
|
useState<CollectionIncludingMembersAndLinkCount>(
|
||||||
collections.find(
|
collections.find(
|
||||||
|
@ -46,7 +60,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
(e) => e.id === link.collection.id
|
(e) => e.id === link.collection.id
|
||||||
) as CollectionIncludingMembersAndLinkCount
|
) as CollectionIncludingMembersAndLinkCount
|
||||||
);
|
);
|
||||||
}, [collections]);
|
}, [collections, links]);
|
||||||
|
|
||||||
const { removeLink, updateLink } = useLinkStore();
|
const { removeLink, updateLink } = useLinkStore();
|
||||||
|
|
||||||
|
@ -144,7 +158,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
<div className="flex items-baseline gap-1">
|
<div className="flex items-baseline gap-1">
|
||||||
<p className="text-sm text-sky-500 font-bold">{count + 1}.</p>
|
<p className="text-sm text-sky-500 font-bold">{count + 1}.</p>
|
||||||
<p className="text-lg text-sky-700 font-bold truncate capitalize w-full pr-8">
|
<p className="text-lg text-sky-700 font-bold truncate capitalize w-full pr-8">
|
||||||
{link.name}
|
{link.name || link.description}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-3 items-center my-3">
|
<div className="flex gap-3 items-center my-3">
|
||||||
|
@ -159,6 +173,10 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex items-center gap-1 w-full pr-20 text-gray-500">
|
||||||
|
<FontAwesomeIcon icon={faLink} className="mt-1 w-4 h-4" />
|
||||||
|
<p className="truncate w-full">{shortendURL}</p>
|
||||||
|
</div>
|
||||||
<div className="flex items-center gap-1 text-gray-500">
|
<div className="flex items-center gap-1 text-gray-500">
|
||||||
<FontAwesomeIcon icon={faCalendarDays} className="w-4 h-4" />
|
<FontAwesomeIcon icon={faCalendarDays} className="w-4 h-4" />
|
||||||
<p>{formattedDate}</p>
|
<p>{formattedDate}</p>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import useCollectionStore from "@/store/collections";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import SubmitButton from "../../SubmitButton";
|
import SubmitButton from "../../SubmitButton";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
type Props =
|
type Props =
|
||||||
| {
|
| {
|
||||||
|
@ -70,8 +71,6 @@ export default function AddOrEditLink({
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// const shortendURL = method === "UPDATE" ? new URL(link.url).host.toLowerCase() : undefined;
|
|
||||||
|
|
||||||
const setTags = (e: any) => {
|
const setTags = (e: any) => {
|
||||||
const tagNames = e.map((e: any) => {
|
const tagNames = e.map((e: any) => {
|
||||||
return { name: e.label };
|
return { name: e.label };
|
||||||
|
@ -119,41 +118,29 @@ export default function AddOrEditLink({
|
||||||
className="text-gray-500 my-2 text-center truncate w-full"
|
className="text-gray-500 my-2 text-center truncate w-full"
|
||||||
title={link.url}
|
title={link.url}
|
||||||
>
|
>
|
||||||
Edit <span className="underline">{link.url}</span>
|
<Link href={link.url} target="_blank" className=" font-bold">
|
||||||
|
{link.url}
|
||||||
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<div className="grid sm:grid-cols-2 gap-3">
|
{method === "CREATE" ? (
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-sky-700 mb-2">
|
<p className="text-sm text-sky-700 mb-2 font-bold">
|
||||||
Name
|
Address (URL)
|
||||||
<RequiredBadge />
|
<RequiredBadge />
|
||||||
</p>
|
</p>
|
||||||
<input
|
<input
|
||||||
value={link.name}
|
value={link.url}
|
||||||
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="e.g. Example Link"
|
placeholder="e.g. http://example.com/"
|
||||||
className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100"
|
className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : null}
|
||||||
{method === "CREATE" ? (
|
<hr />
|
||||||
<div>
|
<div className="grid sm:grid-cols-2 gap-3">
|
||||||
<p className="text-sm text-sky-700 mb-2">
|
|
||||||
URL
|
|
||||||
<RequiredBadge />
|
|
||||||
</p>
|
|
||||||
<input
|
|
||||||
value={link.url}
|
|
||||||
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. http://example.com/"
|
|
||||||
className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-sky-700 mb-2">Collection</p>
|
<p className="text-sm text-sky-700 mb-2">Collection</p>
|
||||||
<CollectionSelection
|
<CollectionSelection
|
||||||
|
@ -173,7 +160,7 @@ export default function AddOrEditLink({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={method === "UPDATE" ? "sm:col-span-2" : ""}>
|
<div>
|
||||||
<p className="text-sm text-sky-700 mb-2">Tags</p>
|
<p className="text-sm text-sky-700 mb-2">Tags</p>
|
||||||
<TagSelection
|
<TagSelection
|
||||||
onChange={setTags}
|
onChange={setTags}
|
||||||
|
@ -182,6 +169,18 @@ export default function AddOrEditLink({
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="sm:col-span-2">
|
||||||
|
<p className="text-sm text-sky-700 mb-2">Name</p>
|
||||||
|
<input
|
||||||
|
value={link.name}
|
||||||
|
onChange={(e) => setLink({ ...link, name: e.target.value })}
|
||||||
|
type="text"
|
||||||
|
placeholder="e.g. Example Link"
|
||||||
|
className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="sm:col-span-2">
|
<div className="sm:col-span-2">
|
||||||
<p className="text-sm text-sky-700 mb-2">Description</p>
|
<p className="text-sm text-sky-700 mb-2">Description</p>
|
||||||
<textarea
|
<textarea
|
||||||
|
|
|
@ -150,7 +150,7 @@ export default function LinkDetails({ link }: Props) {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-col gap- justify-end drop-shadow">
|
<div className="flex flex-col min-h-[3rem] justify-end drop-shadow">
|
||||||
<p className="text-2xl text-sky-700 capitalize break-words hyphens-auto">
|
<p className="text-2xl text-sky-700 capitalize break-words hyphens-auto">
|
||||||
{link.name}
|
{link.name}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default async function archive(
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 300000 });
|
await page.goto(url, { waitUntil: "domcontentloaded" });
|
||||||
|
|
||||||
await autoScroll(page);
|
await autoScroll(page);
|
||||||
|
|
||||||
|
@ -53,7 +53,13 @@ export default async function archive(
|
||||||
|
|
||||||
const autoScroll = async (page: Page) => {
|
const autoScroll = async (page: Page) => {
|
||||||
await page.evaluate(async () => {
|
await page.evaluate(async () => {
|
||||||
await new Promise<void>((resolve, reject) => {
|
const timeoutPromise = new Promise<void>((_, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
reject(new Error("Auto scroll took too long (more than 20 seconds)."));
|
||||||
|
}, 20000);
|
||||||
|
});
|
||||||
|
|
||||||
|
const scrollingPromise = new Promise<void>((resolve) => {
|
||||||
let totalHeight = 0;
|
let totalHeight = 0;
|
||||||
let distance = 100;
|
let distance = 100;
|
||||||
let scrollDown = setInterval(() => {
|
let scrollDown = setInterval(() => {
|
||||||
|
@ -68,6 +74,6 @@ const autoScroll = async (page: Page) => {
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 2000));
|
await Promise.race([scrollingPromise, timeoutPromise]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default async function postCollection(
|
||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
name: collection.name,
|
name: collection.name.trim(),
|
||||||
description: collection.description,
|
description: collection.description,
|
||||||
color: collection.color,
|
color: collection.color,
|
||||||
members: {
|
members: {
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default async function updateCollection(
|
||||||
},
|
},
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
name: collection.name,
|
name: collection.name.trim(),
|
||||||
description: collection.description,
|
description: collection.description,
|
||||||
color: collection.color,
|
color: collection.color,
|
||||||
isPublic: collection.isPublic,
|
isPublic: collection.isPublic,
|
||||||
|
|
|
@ -10,11 +10,19 @@ export default async function postLink(
|
||||||
link: LinkIncludingShortenedCollectionAndTags,
|
link: LinkIncludingShortenedCollectionAndTags,
|
||||||
userId: number
|
userId: number
|
||||||
) {
|
) {
|
||||||
|
try {
|
||||||
|
new URL(link.url);
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
response:
|
||||||
|
"Please enter a valid Address for the Link. (It should start with http/https)",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
link.collection.name = link.collection.name.trim();
|
link.collection.name = link.collection.name.trim();
|
||||||
|
|
||||||
if (!link.name) {
|
if (!link.collection.name) {
|
||||||
return { response: "Please enter a valid name for the link.", status: 400 };
|
|
||||||
} else if (!link.collection.name) {
|
|
||||||
link.collection.name = "Unnamed Collection";
|
link.collection.name = "Unnamed Collection";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +53,8 @@ export default async function postLink(
|
||||||
|
|
||||||
const newLink: Link = await prisma.link.create({
|
const newLink: Link = await prisma.link.create({
|
||||||
data: {
|
data: {
|
||||||
name: link.name,
|
|
||||||
url: link.url,
|
url: link.url,
|
||||||
|
name: link.name,
|
||||||
description,
|
description,
|
||||||
collection: {
|
collection: {
|
||||||
connectOrCreate: {
|
connectOrCreate: {
|
||||||
|
@ -57,7 +65,7 @@ export default async function postLink(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
name: link.collection.name,
|
name: link.collection.name.trim(),
|
||||||
ownerId: userId,
|
ownerId: userId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -66,12 +74,12 @@ export default async function postLink(
|
||||||
connectOrCreate: link.tags.map((tag) => ({
|
connectOrCreate: link.tags.map((tag) => ({
|
||||||
where: {
|
where: {
|
||||||
name_ownerId: {
|
name_ownerId: {
|
||||||
name: tag.name,
|
name: tag.name.trim(),
|
||||||
ownerId: link.collection.ownerId,
|
ownerId: link.collection.ownerId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
name: tag.name,
|
name: tag.name.trim(),
|
||||||
owner: {
|
owner: {
|
||||||
connect: {
|
connect: {
|
||||||
id: link.collection.ownerId,
|
id: link.collection.ownerId,
|
||||||
|
|
|
@ -5,7 +5,7 @@ export default async function getTitle(url: string) {
|
||||||
|
|
||||||
// regular expression to find the <title> tag
|
// regular expression to find the <title> tag
|
||||||
let match = text.match(/<title.*>([^<]*)<\/title>/);
|
let match = text.match(/<title.*>([^<]*)<\/title>/);
|
||||||
if (match) return match[1] + " [AUTO GENERATED]";
|
if (match) return match[1];
|
||||||
else return "";
|
else return "";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
|
@ -236,7 +236,7 @@ export default function Index() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{links[0] ? (
|
{links[0] ? (
|
||||||
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
<div className="grid grid-cols-1 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
||||||
{links
|
{links
|
||||||
.filter((e) => e.collectionId === Number(router.query.id))
|
.filter((e) => e.collectionId === Number(router.query.id))
|
||||||
.map((e, i) => {
|
.map((e, i) => {
|
||||||
|
|
|
@ -66,7 +66,7 @@ export default function Index() {
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
<div className="grid grid-cols-1 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
||||||
{links
|
{links
|
||||||
.filter((e) => e.tags.some((e) => e.id === Number(router.query.id)))
|
.filter((e) => e.tags.some((e) => e.id === Number(router.query.id)))
|
||||||
.map((e, i) => {
|
.map((e, i) => {
|
||||||
|
|
Ŝarĝante…
Reference in New Issue