Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

Merge remote-tracking branch 'upstream/dev' into tags-in-public-collection

Oliver Schwamb24d45f8e8e69
diff --cc components/ModalContent/EditCollectionSharingModal.tsx
index d4d587b5,921c3bb9..5f50018a
--- a/components/ModalContent/EditCollectionSharingModal.tsx
+++ b/components/ModalContent/EditCollectionSharingModal.tsx
@@@ -125,51 -131,15 +131,40 @@@ export default function EditCollectionS
</div>
)}
+ {permissions === true && collection.isPublic && (
+ <div>
+ <p>Show tags in public collection</p>
+
+ <label className="label cursor-pointer justify-start gap-2">
+ <input
+ type="checkbox"
+ checked={collection.tagsArePublic}
+ onChange={() =>
+ setCollection({
+ ...collection,
+ tagsArePublic: !collection.tagsArePublic,
+ })
+ }
+ className="checkbox checkbox-primary"
+ />
+ <span className="label-text">Show tags in public collection</span>
+ </label>
+
+ <p className="text-neutral text-sm">
+ This will let <b>Anyone</b> view this collections tags and search
+ this collections links by them.
+ </p>
+ </div>
+ )}
-
- {collection.isPublic ? (
- <div className={permissions === true ? "pl-5" : ""}>
- <p className="mb-2">Sharable Link (Click to copy)</p>
- <div
- onClick={() => {
- try {
- navigator.clipboard
- .writeText(publicCollectionURL)
- .then(() => toast.success("Copied!"));
- } catch (err) {
- console.log(err);
- }
- }}
- className="w-full hide-scrollbar overflow-x-auto whitespace-nowrap rounded-md p-2 bg-base-200 border-neutral-content border-solid border outline-none hover:border-primary dark:hover:border-primary duration-100 cursor-text"
- >
+ {collection.isPublic && (
+ <div>
+ <p className="mb-2">{t("sharable_link")}</p>
+ <div className="w-full hide-scrollbar overflow-x-auto whitespace-nowrap rounded-md p-2 bg-base-200 border-neutral-content border-solid border flex items-center gap-2 justify-between">
{publicCollectionURL}
+ <CopyButton text={publicCollectionURL} />
</div>
</div>
- ) : null}
+ )}
{permissions === true && <div className="divider my-3"></div>}
diff --cc lib/api/controllers/collections/collectionId/updateCollectionById.ts
index 0985c7bd,569090a5..2aed55f3
--- a/lib/api/controllers/collections/collectionId/updateCollectionById.ts
+++ b/lib/api/controllers/collections/collectionId/updateCollectionById.ts
@@@ -61,8 -75,9 +75,10 @@@ export default async function updateCol
name: data.name.trim(),
description: data.description,
color: data.color,
+ icon: data.icon,
+ iconWeight: data.iconWeight,
isPublic: data.isPublic,
+ tagsArePublic: data.tagsArePublic,
parent:
data.parentId && data.parentId !== ("root" as any)
? {
diff --cc lib/api/controllers/public/links/getPublicLinksUnderCollection.ts
index 5f59fd08,b03de3a0..0e3873f0
--- a/lib/api/controllers/public/links/getPublicLinksUnderCollection.ts
+++ b/lib/api/controllers/public/links/getPublicLinksUnderCollection.ts
@@@ -1,12 -1,13 +1,13 @@@
import { prisma } from "@/lib/api/db";
- import { LinkRequestQuery, Sort } from "@/types/global";
+ import { LinkRequestQuery, Order, Sort } from "@/types/global";
export default async function getLink(
- query: Omit<LinkRequestQuery, "tagId" | "pinnedOnly">
+ query: Omit<LinkRequestQuery, "tagId" | "pinnedOnly">, takeAll = false
) {
- const POSTGRES_IS_ENABLED = process.env.DATABASE_URL.startsWith("postgresql");
+ const POSTGRES_IS_ENABLED =
+ process.env.DATABASE_URL?.startsWith("postgresql");
- let order: any;
+ let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };
diff --cc pages/public/collections/[id].tsx
index 4e51724f,d49660f4..f72922a5
--- a/pages/public/collections/[id].tsx
+++ b/pages/public/collections/[id].tsx
@@@ -1,9 -1,9 +1,10 @@@
"use client";
import getPublicCollectionData from "@/lib/client/getPublicCollectionData";
import {
+ AccountSettings,
CollectionIncludingMembersAndLinkCount,
Sort,
+ TagIncludingLinkCount,
ViewMode,
} from "@/types/global";
import { useRouter } from "next/router";
@@@ -20,62 -17,23 +18,43 @@@ import Link from "next/link"
import useLocalSettingsStore from "@/store/localSettings";
import SearchBar from "@/components/SearchBar";
import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal";
- import ViewDropdown from "@/components/ViewDropdown";
- import CardView from "@/components/LinkViews/Layouts/CardView";
- import ListView from "@/components/LinkViews/Layouts/ListView";
+ import { useTranslation } from "next-i18next";
+ import getServerSideProps from "@/lib/client/getServerSideProps";
+ import LinkListOptions from "@/components/LinkListOptions";
+ import { usePublicLinks } from "@/hooks/store/publicLinks";
+ import Links from "@/components/LinkViews/Links";
+import useTagStore from "@/store/tags";
+import { Disclosure, Transition } from "@headlessui/react";
- // import GridView from "@/components/LinkViews/Layouts/GridView";
-
- const cardVariants: Variants = {
- offscreen: {
- y: 50,
- opacity: 0,
- },
- onscreen: {
- y: 0,
- opacity: 1,
- transition: {
- duration: 0.4,
- },
- },
- };
export default function PublicCollections() {
- const { links } = useLinkStore();
- const { settings } = useLocalSettingsStore();
+ const { t } = useTranslation();
+
- const { settings } = useLocalSettingsStore();
++const { settings } = useLocalSettingsStore();
const router = useRouter();
- const [collectionOwner, setCollectionOwner] = useState({
- id: null as unknown as number,
- name: "",
- username: "",
- image: "",
- archiveAsScreenshot: undefined as unknown as boolean,
- archiveAsPDF: undefined as unknown as boolean,
- });
+ const [collectionOwner, setCollectionOwner] = useState<
+ Partial<AccountSettings>
+ >({});
+ const { tags, setTags } = useTagStore();
+ const handleTagSelection = (tag: TagIncludingLinkCount | undefined) => {
+ if (tag) {
+ Object.keys(searchFilter).forEach((v) => searchFilter[(v as keyof {name: boolean, url: boolean, description: boolean, tags: boolean, textContent: boolean})] = false)
+ searchFilter.tags = true;
+ return router.push(
+ "/public/collections/" +
+ router.query.id +
+ "?q=" +
+ encodeURIComponent(tag.name || "")
+ );
+ } else {
+ return router.push(
+ "/public/collections/" +
+ router.query.id)
+ }
+ }
+
const [searchFilter, setSearchFilter] = useState({
name: true,
url: true,
@@@ -100,10 -60,16 +81,16 @@@
const [collection, setCollection] =
useState<CollectionIncludingMembersAndLinkCount>();
-
useEffect(() => {
if (router.query.id) {
- getPublicCollectionData(Number(router.query.id), setCollection);
- setTags(Number(router.query.id))
+ getPublicCollectionData(Number(router.query.id)).then((res) => {
+ if (res.status === 400) {
+ router.push("/dashboard");
+ } else {
+ setCollection(res.response);
++ setTags(Number(router.query.id))
+ }
+ });
}
}, []);
@@@ -121,204 -84,138 +105,222 @@@
const [editCollectionSharingModal, setEditCollectionSharingModal] =
useState(false);
- const [viewMode, setViewMode] = useState<string>(
- localStorage.getItem("viewMode") || ViewMode.Card
+ const [viewMode, setViewMode] = useState<ViewMode>(
+ (localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card
);
- const linkView = {
- [ViewMode.Card]: CardView,
- // [ViewMode.Grid]: GridView,
- [ViewMode.List]: ListView,
- };
-
- const [tagDisclosure, setTagDisclosure] = useState<boolean>(() => {
- const storedValue = localStorage.getItem("tagDisclosureForPublicCollection" + collection?.id);
- return storedValue ? storedValue === "true" : true;
- });
- useEffect(() => {
- localStorage.setItem("tagDisclosureForPublicCollection" + collection?.id, tagDisclosure ? "true" : "false");
- }, [tagDisclosure]);
-
- // @ts-ignore
- const LinkComponent = linkView[viewMode];
++const [tagDisclosure, setTagDisclosure] = useState<boolean>(() => {
++ const storedValue = localStorage.getItem(
++ "tagDisclosureForPublicCollection" + collection?.id
++ );
++ return storedValue ? storedValue === "true" : true;
++});
++useEffect(() => {
++ localStorage.setItem(
++ "tagDisclosureForPublicCollection" + collection?.id,
++ tagDisclosure ? "true" : "false"
++ );
++}, [tagDisclosure]);
+
- return collection ? (
- <div
- className="h-96"
- style={{
- backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
- settings.theme === "dark" ? "#262626" : "#f3f4f6"
- } 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
- }}
- >
- {collection ? (
- <Head>
- <title>{collection.name} | Linkwarden</title>
- <meta
- property="og:title"
- content={`${collection.name} | Linkwarden`}
- key="title"
- />
- </Head>
- ) : undefined}
- <div className="lg:w-3/4 w-full mx-auto p-5 bg">
- <div className="flex items-center justify-between">
- <p className="text-4xl font-thin mb-2 capitalize mt-10">
- {collection.name}
- </p>
- <div className="flex gap-2 items-center mt-8 min-w-fit">
- <ToggleDarkMode />
+ if (!collection) return <></>;
+ else
+ return (
+ <div
+ className="h-96"
+ style={{
+ backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
+ settings.theme === "dark" ? "#262626" : "#f3f4f6"
+ } 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
+ }}
+ >
+ {collection && (
+ <Head>
+ <title>{collection.name} | Linkwarden</title>
+ <meta
+ property="og:title"
+ content={`${collection.name} | Linkwarden`}
+ key="title"
+ />
+ </Head>
+ )}
+ <div className="lg:w-3/4 w-full mx-auto p-5 bg">
+ <div className="flex items-center justify-between">
+ <p className="text-4xl font-thin mb-2 capitalize mt-10">
+ {collection.name}
+ </p>
+ <div className="flex gap-2 items-center mt-8 min-w-fit">
+ <ToggleDarkMode />
- <Link href="https://linkwarden.app/" target="_blank">
- <Image
- src={`/icon.png`}
- width={551}
- height={551}
- alt="Linkwarden"
- title="Created with Linkwarden"
- className="h-8 w-fit mx-auto rounded"
- />
- </Link>
+ <Link href="https://linkwarden.app/" target="_blank">
+ <Image
+ src={`/icon.png`}
+ width={551}
+ height={551}
+ alt="Linkwarden"
+ title={t("list_created_with_linkwarden")}
+ className="h-8 w-fit mx-auto rounded"
+ />
+ </Link>
+ </div>
</div>
- </div>
- <div className="mt-3">
- <div className={`min-w-[15rem]`}>
- <div className="flex gap-1 justify-center sm:justify-end items-center w-fit">
- <div
- className="flex items-center btn px-2 btn-ghost rounded-full"
- onClick={() => setEditCollectionSharingModal(true)}
- >
- {collectionOwner.id ? (
- <ProfilePhoto
- src={collectionOwner.image || undefined}
- name={collectionOwner.name}
- />
- ) : undefined}
- {collection.members
- .sort((a, b) => (a.userId as number) - (b.userId as number))
- .map((e, i) => {
- return (
- <ProfilePhoto
- key={i}
- src={e.user.image ? e.user.image : undefined}
- className="-ml-3"
- name={e.user.name}
- />
- );
- })
- .slice(0, 3)}
- {collection.members.length - 3 > 0 ? (
- <div className={`avatar drop-shadow-md placeholder -ml-3`}>
- <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
- <span>+{collection.members.length - 3}</span>
+ <div className="mt-3">
+ <div className={`min-w-[15rem]`}>
+ <div className="flex gap-1 justify-center sm:justify-end items-center w-fit">
+ <div
+ className="flex items-center btn px-2 btn-ghost rounded-full"
+ onClick={() => setEditCollectionSharingModal(true)}
+ >
+ {collectionOwner.id && (
+ <ProfilePhoto
+ src={collectionOwner.image || undefined}
+ name={collectionOwner.name}
+ />
+ )}
+ {collection.members
+ .sort((a, b) => (a.userId as number) - (b.userId as number))
+ .map((e, i) => {
+ return (
+ <ProfilePhoto
+ key={i}
+ src={e.user.image ? e.user.image : undefined}
+ className="-ml-3"
+ name={e.user.name}
+ />
+ );
+ })
+ .slice(0, 3)}
+ {collection.members.length - 3 > 0 && (
+ <div className={`avatar drop-shadow-md placeholder -ml-3`}>
+ <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
+ <span>+{collection.members.length - 3}</span>
+ </div>
</div>
- </div>
- ) : null}
- </div>
+ )}
+ </div>
- <p className="text-neutral text-sm font-semibold">
- By {collectionOwner.name}
- {collection.members.length > 0
- ? ` and ${collection.members.length} others`
- : undefined}
- .
- </p>
+ <p className="text-neutral text-sm">
+ {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,
+ })}
+ </p>
+ </div>
</div>
</div>
- </div>
-
- <p className="mt-5">{collection.description}</p>
- <div className="divider mt-5 mb-0"></div>
+ <p className="mt-5">{collection.description}</p>
- <div className="flex mb-5 mt-10 flex-col gap-5">
- <div className="flex justify-between gap-3">
- <SearchBar
- placeholder={`Search ${collection._count?.links} Links`}
- />
+ <div className="divider mt-5 mb-0"></div>
- <div className="flex gap-2 items-center w-fit">
- <FilterSearchDropdown
- searchFilter={searchFilter}
- setSearchFilter={setSearchFilter}
+ <div className="flex mb-5 mt-10 flex-col gap-5">
+ <LinkListOptions
+ t={t}
+ viewMode={viewMode}
+ setViewMode={setViewMode}
+ sortBy={sortBy}
+ setSortBy={setSortBy}
+ searchFilter={searchFilter}
+ setSearchFilter={setSearchFilter}
+ >
+ <SearchBar
+ placeholder={
+ collection._count?.links === 1
+ ? t("search_count_link", {
+ count: collection._count?.links,
+ })
+ : t("search_count_links", {
+ count: collection._count?.links,
+ })
+ }
/>
-
- <SortDropdown sortBy={sortBy} setSort={setSortBy} />
-
- <ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
- </div>
- </div>
- {collection.tagsArePublic && tags[0] && (
- <Disclosure defaultOpen={tagDisclosure}>
- <Disclosure.Button
- onClick={() => {
- setTagDisclosure(!tagDisclosure);
- }}
- className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
- >
- <p className="text-sm">Browse by topic</p>
- <i
- className={`bi-chevron-down ${
- tagDisclosure ? "rotate-reverse" : "rotate"
- }`}
- ></i>
- </Disclosure.Button>
- <Transition
- enter="transition duration-100 ease-out"
- enterFrom="transform opacity-0 -translate-y-3"
- enterTo="transform opacity-100 translate-y-0"
- leave="transition duration-100 ease-out"
- leaveFrom="transform opacity-100 translate-y-0"
- leaveTo="transform opacity-0 -translate-y-3"
- >
- <Disclosure.Panel>
- <div className="flex gap-2 mt-2 mb-6 flex-wrap">
- <button className="max-w-full" onClick={() => handleTagSelection(undefined)}>
- <div
- className="
- bg-neutral-content/20 hover:bg-neutral/20 duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8"
- >
- <i className="text-primary bi-hash text-2xl text-primary drop-shadow"></i>
- <p className="truncate pr-7">All</p>
- <div className="text-neutral drop-shadow text-neutral text-xs">
- {collection._count?.links}
- </div>
- </div>
- </button>
- {tags
- .sort((a, b) => a.name.localeCompare(b.name))
- .map((e, i) => {
- const active = router.query.q === e.name;
- return (
- <button className="max-w-full" key={i} onClick={() => handleTagSelection(e)}>
+ </LinkListOptions>
-
++ {collection.tagsArePublic && tags[0] && (
++ <Disclosure defaultOpen={tagDisclosure}>
++ <Disclosure.Button
++ onClick={() => {
++ setTagDisclosure(!tagDisclosure);
++ }}
++ className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
++ >
++ <p className="text-sm">Browse by topic</p>
++ <i
++ className={`bi-chevron-down ${
++ tagDisclosure ? "rotate-reverse" : "rotate"
++ }`}
++ ></i>
++ </Disclosure.Button>
++ <Transition
++ enter="transition duration-100 ease-out"
++ enterFrom="transform opacity-0 -translate-y-3"
++ enterTo="transform opacity-100 translate-y-0"
++ leave="transition duration-100 ease-out"
++ leaveFrom="transform opacity-100 translate-y-0"
++ leaveTo="transform opacity-0 -translate-y-3"
++ >
++ <Disclosure.Panel>
++ <div className="flex gap-2 mt-2 mb-6 flex-wrap">
++ <button
++ className="max-w-full"
++ onClick={() => handleTagSelection(undefined)}
++ >
+ <div
- className={`
- ${
- active
- ? "bg-primary/20"
- : "bg-neutral-content/20 hover:bg-neutral/20"
- } duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8`}
++ className="
++ bg-neutral-content/20 hover:bg-neutral/20 duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8"
+ >
- <i className="bi-hash text-2xl text-primary drop-shadow"></i>
- <p className="truncate pr-7">{e.name}</p>
- <div className="drop-shadow text-neutral text-xs">
- {e._count?.links}
++ <i className="text-primary bi-hash text-2xl text-primary drop-shadow"></i>
++ <p className="truncate pr-7">All</p>
++ <div className="text-neutral drop-shadow text-neutral text-xs">
++ {collection._count?.links}
+ </div>
+ </div>
+ </button>
- );
- })
- }
- </div>
- </Disclosure.Panel>
- </Transition>
- </Disclosure>)}
- {links[0] ? (
- <LinkComponent
- links={links
- .filter((e) => e.collectionId === Number(router.query.id))
- .map((e, i) => {
++ {tags
++ .sort((a, b) => a.name.localeCompare(b.name))
++ .map((e, i) => {
++ const active = router.query.q === e.name;
++ return (
++ <button
++ className="max-w-full"
++ key={i}
++ onClick={() => handleTagSelection(e)}
++ >
++ <div
++ className={`
++ ${
++ active
++ ? "bg-primary/20"
++ : "bg-neutral-content/20 hover:bg-neutral/20"
++ } duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 rounded-md h-8`}
++ >
++ <i className="bi-hash text-2xl text-primary drop-shadow"></i>
++ <p className="truncate pr-7">{e.name}</p>
++ <div className="drop-shadow text-neutral text-xs">
++ {e._count?.links}
++ </div>
++ </div>
++ </button>
++ );
++ })}
++ </div>
++ </Disclosure.Panel>
++ </Transition>
++ </Disclosure>
++ )}
+ <Links
+ links={
+ links?.map((e, i) => {
const linkWithCollectionData = {
...e,
collection: collection, // Append collection data