2023-06-05 15:47:01 -05:00
|
|
|
import LinkCard from "@/components/PublicPage/LinkCard";
|
2023-06-14 17:34:54 -05:00
|
|
|
import useDetectPageBottom from "@/hooks/useDetectPageBottom";
|
2023-05-29 14:40:23 -05:00
|
|
|
import getPublicCollectionData from "@/lib/client/getPublicCollectionData";
|
|
|
|
import { PublicCollectionIncludingLinks } from "@/types/global";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import React, { useEffect, useState } from "react";
|
2023-05-28 00:55:49 -05:00
|
|
|
|
|
|
|
export default function PublicCollections() {
|
2023-05-29 14:40:23 -05:00
|
|
|
const router = useRouter();
|
2023-06-14 17:34:54 -05:00
|
|
|
const hasReachedBottom = useDetectPageBottom();
|
2023-05-29 14:40:23 -05:00
|
|
|
|
|
|
|
const [data, setData] = useState<PublicCollectionIncludingLinks>();
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-06-02 22:50:16 -05:00
|
|
|
if (router.query.id) {
|
|
|
|
getPublicCollectionData(
|
2023-06-15 07:39:30 -05:00
|
|
|
Number(router.query.id),
|
2023-06-14 17:34:54 -05:00
|
|
|
data as PublicCollectionIncludingLinks,
|
|
|
|
setData
|
2023-06-02 22:50:16 -05:00
|
|
|
);
|
|
|
|
}
|
2023-05-31 09:30:45 -05:00
|
|
|
|
|
|
|
// document
|
|
|
|
// .querySelector("body")
|
|
|
|
// ?.classList.add(
|
|
|
|
// "bg-gradient-to-br",
|
|
|
|
// "from-slate-50",
|
|
|
|
// "to-sky-50",
|
|
|
|
// "min-h-screen"
|
|
|
|
// );
|
2023-05-29 14:40:23 -05:00
|
|
|
}, []);
|
|
|
|
|
2023-06-14 17:34:54 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (hasReachedBottom && router.query.id) {
|
|
|
|
getPublicCollectionData(
|
2023-06-15 07:39:30 -05:00
|
|
|
Number(router.query.id),
|
2023-06-14 17:34:54 -05:00
|
|
|
data as PublicCollectionIncludingLinks,
|
|
|
|
setData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, [hasReachedBottom]);
|
|
|
|
|
2023-05-31 09:30:45 -05:00
|
|
|
return data ? (
|
|
|
|
<div className="max-w-4xl mx-auto p-5 bg">
|
2023-06-02 22:50:16 -05:00
|
|
|
<div
|
|
|
|
className={`text-center bg-gradient-to-tr from-sky-100 from-10% via-gray-100 via-20% rounded-3xl shadow-lg p-5`}
|
|
|
|
>
|
2023-05-31 09:30:45 -05:00
|
|
|
<p className="text-5xl bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent font-bold mb-5 capitalize">
|
|
|
|
{data.name}
|
|
|
|
</p>
|
|
|
|
|
2023-06-26 18:35:12 -05:00
|
|
|
{data.description && (
|
|
|
|
<>
|
|
|
|
<hr className="mt-5 max-w-[30rem] mx-auto border-1 border-slate-400" />
|
|
|
|
<p className="mt-2 text-gray-500">{data.description}</p>
|
|
|
|
</>
|
|
|
|
)}
|
2023-05-31 09:30:45 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-5 my-8">
|
2023-06-09 17:31:14 -05:00
|
|
|
{data?.links?.map((e, i) => {
|
2023-06-05 15:47:01 -05:00
|
|
|
return <LinkCard key={i} link={e} count={i} />;
|
2023-05-31 09:30:45 -05:00
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<p className="text-center font-bold text-gray-500">
|
|
|
|
List created with <span className="text-sky-500">Linkwarden.</span>
|
|
|
|
</p>
|
2023-05-29 14:40:23 -05:00
|
|
|
</div>
|
2023-05-31 09:30:45 -05:00
|
|
|
) : (
|
|
|
|
<></>
|
2023-05-29 14:40:23 -05:00
|
|
|
);
|
2023-05-28 00:55:49 -05:00
|
|
|
}
|