"use client"; import getPublicCollectionData from "@/lib/client/getPublicCollectionData"; import { CollectionIncludingMembersAndLinkCount, Sort, ViewMode, } from "@/types/global"; 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 useLocalSettingsStore from "@/store/localSettings"; 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 { useCollections } from "@/hooks/store/collections"; import { usePublicLinks } from "@/hooks/store/publicLinks"; import Links from "@/components/LinkViews/Links"; export default function PublicCollections() { const { t } = useTranslation(); const { settings } = useLocalSettingsStore(); const { data: collections = [] } = useCollections(); const router = useRouter(); const [collectionOwner, setCollectionOwner] = useState({ id: null as unknown as number, name: "", username: "", image: "", archiveAsScreenshot: undefined as unknown as boolean, archiveAsMonolith: undefined as unknown as boolean, archiveAsPDF: undefined as unknown as boolean, }); const [searchFilter, setSearchFilter] = useState({ name: true, url: true, description: true, tags: true, textContent: false, }); const [sortBy, setSortBy] = useState( Number(localStorage.getItem("sortBy")) ?? Sort.DateNewestFirst ); const { links, data } = usePublicLinks({ 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(); useEffect(() => { if (router.query.id) { getPublicCollectionData(Number(router.query.id), setCollection); } }, [collections]); useEffect(() => { const fetchOwner = async () => { if (collection) { const owner = await getPublicUserData(collection.ownerId as number); setCollectionOwner(owner); } }; fetchOwner(); }, [collection]); const [editCollectionSharingModal, setEditCollectionSharingModal] = useState(false); const [viewMode, setViewMode] = useState( (localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card ); return collection ? (
{collection ? ( {collection.name} | Linkwarden ) : undefined}

{collection.name}

Linkwarden
setEditCollectionSharingModal(true)} > {collectionOwner.id ? ( ) : undefined} {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}
) : null}

{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}

{ const linkWithCollectionData = { ...e, collection: collection, // Append collection data }; return linkWithCollectionData; }) as any } layout={viewMode} placeholderCount={1} useData={data} /> {!data.isLoading && links && !links[0] && (

{t("collection_is_empty")}

)} {/*

List created with Linkwarden.

*/}
{editCollectionSharingModal ? ( setEditCollectionSharingModal(false)} activeCollection={collection} /> ) : undefined}
) : ( <> ); } export { getServerSideProps };