minor changes

This commit is contained in:
daniel31x13
2024-11-02 20:43:53 -04:00
parent 2e1e94112f
commit 4febe1ace5
21 changed files with 4603 additions and 21657 deletions
+17 -10
View File
@@ -1,5 +1,5 @@
import getPublicLinksUnderCollection from "@/lib/api/controllers/public/links/getPublicLinksUnderCollection";
import getTags from "@/lib/api/controllers/tags/getTags";
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery } from "@/types/global";
import type { NextApiRequest, NextApiResponse } from "next";
@@ -22,14 +22,21 @@ export default async function collections(
.json({ response: "Please choose a valid collection." });
}
const links = await getPublicLinksUnderCollection(convertedData, true);
const tags = await getTags();
const tagsInLinks = links.response.map(l => l.tags).flat().filter((value, index, self) =>
index === self.findIndex((t) => (
t.name === value.name
))).map(t => t.id);
const tagsWithCount = tags.response.filter(tag => tagsInLinks.includes(tag.id));
return res.status(links.status).json({ response: tagsWithCount });
const collection = await prisma.collection.findFirst({
where: {
id: convertedData.collectionId,
isPublic: true,
},
});
if (!collection) {
return res.status(404).json({ response: "Collection not found." });
}
const tags = await getTags({
collectionId: collection.id,
});
return res.status(tags.status).json({ response: tags.response });
}
}
+3 -1
View File
@@ -7,7 +7,9 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
if (!user) return;
if (req.method === "GET") {
const tags = await getTags(user.id);
const tags = await getTags({
userId: user.id,
});
return res.status(tags.status).json({ response: tags.response });
}
}
+44 -85
View File
@@ -4,7 +4,6 @@ import {
AccountSettings,
CollectionIncludingMembersAndLinkCount,
Sort,
TagIncludingLinkCount,
ViewMode,
} from "@/types/global";
import { useRouter } from "next/router";
@@ -23,7 +22,7 @@ import getServerSideProps from "@/lib/client/getServerSideProps";
import LinkListOptions from "@/components/LinkListOptions";
import { usePublicLinks } from "@/hooks/store/publicLinks";
import Links from "@/components/LinkViews/Links";
import { Disclosure, Transition } from "@headlessui/react";
import { usePublicTags } from "@/hooks/store/publicTags";
export default function PublicCollections() {
const { t } = useTranslation();
@@ -74,7 +73,9 @@ export default function PublicCollections() {
Number(localStorage.getItem("sortBy")) ?? Sort.DateNewestFirst
);
const { links, linksForWholeCollection, data } = usePublicLinks({
const { data: tags } = usePublicTags();
const { links, data } = usePublicLinks({
sort: sortBy,
searchQueryString: router.query.q
? decodeURIComponent(router.query.q as string)
@@ -114,19 +115,6 @@ export default function PublicCollections() {
(localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card
);
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]);
if (!collection) return <></>;
else
return (
@@ -251,84 +239,55 @@ export default function PublicCollections() {
}
/>
</LinkListOptions>
{linksForWholeCollection?.flatMap((l) => l.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"
{tags && tags[0] && (
<div className="flex gap-2 mt-2 mb-6 flex-wrap">
<button
className="max-w-full"
onClick={() => handleTagSelection(undefined)}
>
<p className="text-sm">{t("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">
<div
className={`${
!router.query.q
? "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="text-primary bi-hash text-2xl drop-shadow"></i>
<p className="truncate pr-7">{t("all_links")}</p>
<div className="text-neutral drop-shadow text-xs">
{collection._count?.links}
</div>
</div>
</button>
{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 (
<button
className="max-w-full"
onClick={() => handleTagSelection(undefined)}
key={i}
onClick={() => handleTagSelection(e)}
>
<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"
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="text-primary bi-hash text-2xl text-primary drop-shadow"></i>
<p className="truncate pr-7">{t("all_links")}</p>
<div className="text-neutral drop-shadow text-neutral text-xs">
{collection._count?.links}
<i className="bi-hash text-2xl text-primary drop-shadow"></i>
<p className="truncate pr-7">{e}</p>
<div className="drop-shadow text-neutral text-xs">
{tags.filter((t) => t.name === e)[0]._count.links}
</div>
</div>
</button>
{linksForWholeCollection
.flatMap((l) => l.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 (
<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}</p>
<div className="drop-shadow text-neutral text-xs">
{
linksForWholeCollection.filter((l) =>
l.tags.map((t) => t.name).includes(e)
).length
}
</div>
</div>
</button>
);
})}
</div>
</Disclosure.Panel>
</Transition>
</Disclosure>
);
})}
</div>
)}
<Links
links={