el.xwx.moe/pages/public/collections/[id].tsx

127 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-10-05 11:19:31 -05:00
"use client";
2023-06-05 15:47:01 -05:00
import LinkCard from "@/components/PublicPage/LinkCard";
2023-05-29 14:40:23 -05:00
import getPublicCollectionData from "@/lib/client/getPublicCollectionData";
2023-11-15 12:12:06 -06:00
import { CollectionIncludingMembersAndLinkCount, Sort } from "@/types/global";
2023-05-29 14:40:23 -05:00
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { motion, Variants } from "framer-motion";
2023-10-11 11:18:45 -05:00
import Head from "next/head";
2023-11-15 12:12:06 -06:00
import useLinks from "@/hooks/useLinks";
import useLinkStore from "@/store/links";
const cardVariants: Variants = {
offscreen: {
y: 50,
opacity: 0,
},
onscreen: {
y: 0,
opacity: 1,
transition: {
duration: 0.4,
},
},
};
2023-05-28 00:55:49 -05:00
export default function PublicCollections() {
2023-11-15 12:12:06 -06:00
const { links } = useLinkStore();
2023-05-29 14:40:23 -05:00
const router = useRouter();
2023-11-15 12:12:06 -06:00
const [searchFilter, setSearchFilter] = useState({
name: true,
url: true,
description: true,
textContent: true,
tags: true,
});
const [filterDropdown, setFilterDropdown] = useState(false);
const [sortDropdown, setSortDropdown] = useState(false);
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
useLinks({
sort: sortBy,
searchQueryString: router.query.q
? decodeURIComponent(router.query.q as string)
: undefined,
searchByName: searchFilter.name,
searchByUrl: searchFilter.url,
searchByDescription: searchFilter.description,
searchByTextContent: searchFilter.textContent,
searchByTags: searchFilter.tags,
});
const [collection, setCollection] =
useState<CollectionIncludingMembersAndLinkCount>();
2023-05-29 14:40:23 -05:00
2023-09-05 13:12:27 -05:00
document.body.style.background = "white";
2023-05-29 14:40:23 -05:00
useEffect(() => {
2023-06-02 22:50:16 -05:00
if (router.query.id) {
2023-11-15 12:12:06 -06:00
getPublicCollectionData(Number(router.query.id), setCollection);
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-11-15 12:12:06 -06:00
return collection ? (
2023-05-31 09:30:45 -05:00
<div className="max-w-4xl mx-auto p-5 bg">
2023-11-15 12:12:06 -06:00
{collection ? (
2023-10-11 11:18:45 -05:00
<Head>
2023-11-15 12:12:06 -06:00
<title>{collection.name} | Linkwarden</title>
2023-10-11 11:18:45 -05:00
<meta
property="og:title"
2023-11-15 12:12:06 -06:00
content={`${collection.name} | Linkwarden`}
2023-10-11 11:18:45 -05:00
key="title"
/>
</Head>
) : undefined}
2023-06-02 22:50:16 -05:00
<div
className={`border border-solid border-sky-100 text-center bg-gradient-to-tr from-sky-100 from-10% via-gray-100 via-20% rounded-3xl shadow-lg p-5`}
2023-06-02 22:50:16 -05:00
>
2023-11-15 12:12:06 -06:00
<p className="text-5xl text-black mb-5 capitalize">{collection.name}</p>
2023-05-31 09:30:45 -05:00
2023-11-15 12:12:06 -06:00
{collection.description && (
2023-06-26 18:35:12 -05:00
<>
<hr className="mt-5 max-w-[30rem] mx-auto border-1 border-slate-400" />
2023-11-15 12:12:06 -06:00
<p className="mt-2 text-gray-500">{collection.description}</p>
2023-06-26 18:35:12 -05:00
</>
)}
2023-05-31 09:30:45 -05:00
</div>
<div className="flex flex-col gap-5 my-8">
2023-11-15 12:12:06 -06:00
{links
?.filter((e) => e.collectionId === Number(router.query.id))
.map((e, i) => {
return (
<motion.div
key={i}
initial="offscreen"
whileInView="onscreen"
viewport={{ once: true, amount: 0.8 }}
>
<motion.div variants={cardVariants}>
<LinkCard link={e as any} count={i} />
</motion.div>
</motion.div>
2023-11-15 12:12:06 -06:00
);
})}
2023-05-31 09:30:45 -05:00
</div>
2023-07-13 17:19:49 -05:00
{/* <p className="text-center font-bold text-gray-500">
2023-08-11 00:11:02 -05:00
List created with <span className="text-black">Linkwarden.</span>
2023-07-13 17:19:49 -05:00
</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
}