"use client"; import getPublicCollectionData from "@/lib/client/getPublicCollectionData"; import { AccountSettings, CollectionIncludingMembersAndLinkCount, Sort, ViewMode, } from "@linkwarden/types"; import { useRouter } from "next/router"; import React, { useEffect, useState } from "react"; import Head from "next/head"; import ProfilePhoto from "@/components/ProfilePhoto"; import ToggleDarkMode from "@/components/ToggleDarkMode"; import getPublicUserData from "@/lib/client/getPublicUserData"; import Image from "next/image"; import Link from "next/link"; import SearchBar from "@/components/SearchBar"; import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal"; import { useTranslation } from "next-i18next"; import getServerSideProps from "@/lib/client/getServerSideProps"; import LinkListOptions from "@/components/LinkListOptions"; import { usePublicLinks } from "@linkwarden/router/publicLinks"; import Links from "@/components/LinkViews/Links"; import { usePublicTags } from "@linkwarden/router/publicTags"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { useUser } from "@linkwarden/router/user"; import { Separator } from "@/components/ui/separator"; export default function PublicCollections() { const { t } = useTranslation(); const { data: user } = useUser(); const router = useRouter(); const [collectionOwner, setCollectionOwner] = useState< Partial >({}); const handleTagSelection = (tag: string | undefined) => { if (tag) { return router.push( "/public/collections/" + router.query.id + "?q=" + encodeURIComponent(tag || "") ); } else { return router.push("/public/collections/" + router.query.id); } }; const [sortBy, setSortBy] = useState( Number(localStorage.getItem("sortBy")) ?? Sort.DateNewestFirst ); const { data: tags } = usePublicTags(); const { links, data } = usePublicLinks({ sort: sortBy, searchQueryString: router.query.q ? decodeURIComponent(router.query.q as string) : undefined, }); const [collection, setCollection] = useState(); useEffect(() => { if (router.query.id) { getPublicCollectionData(Number(router.query.id)).then((res) => { if (res.status === 400) { router.push("/dashboard"); } else { setCollection(res.response); } }); } }, []); useEffect(() => { if (collection) { getPublicUserData(collection.ownerId as number).then((owner) => setCollectionOwner(owner) ); } }, [collection]); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [viewMode, setViewMode] = useState( (localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card ); if (!collection) return <>; else return (
{collection && ( {collection.name} | Linkwarden )}

{collection.name}

setEditCollectionSharingModal(true)} > {collectionOwner.id && ( )} {collection.members .sort( (a, b) => (a.userId as number) - (b.userId as number) ) .map((e, i) => { return ( ); }) .slice(0, 3)} {collection.members.length - 3 > 0 && (
+{collection.members.length - 3}
)}

{collection.members.length > 0 && collection.members.length === 1 ? t("by_author_and_other", { author: collectionOwner.name, count: collection.members.length, }) : collection.members.length > 0 && collection.members.length !== 1 ? t("by_author_and_others", { author: collectionOwner.name, count: collection.members.length, }) : t("by_author", { author: collectionOwner.name, })}

{collection.description}

{t("linkwarden_icon")}

{t("list_created_with_linkwarden")}

{t("rss_feed")}

{tags && tags[0] && (
{tags .map((t) => t.name) .filter((item, pos, self) => self.indexOf(item) === pos) .sort((a, b) => a.localeCompare(b)) .map((e, i) => { const active = router.query.q === e; return ( ); })}
)} { const linkWithCollectionData = { ...e, collection: collection, // Append collection data }; return linkWithCollectionData; }) as any } layout={viewMode} useData={data} /> {!data.isLoading && links && !links[0] && (

{t("nothing_found")}

)} {/*

List created with Linkwarden.

*/}
{editCollectionSharingModal && ( setEditCollectionSharingModal(false)} activeCollection={collection} /> )}
); } export { getServerSideProps };