bug fix + cleaner code/logic
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
import getCollection from "@/lib/api/controllers/public/getCollection";
|
||||
import { PublicLinkRequestQuery } from "@/types/global";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function collections(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const query: PublicLinkRequestQuery = req.query;
|
||||
|
||||
if (!query) {
|
||||
if (!req?.query?.body) {
|
||||
return res
|
||||
.status(401)
|
||||
.json({ response: "Please choose a valid collection." });
|
||||
}
|
||||
|
||||
if (req.method === "GET") {
|
||||
const collection = await getCollection(query);
|
||||
const collection = await getCollection(req?.query?.body as string);
|
||||
return res
|
||||
.status(collection.status)
|
||||
.json({ response: collection.response });
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
if (req.method === "GET") {
|
||||
const links = await getLinks(session.user.id, req.query);
|
||||
const links = await getLinks(session.user.id, req?.query?.body as string);
|
||||
return res.status(links.status).json({ response: links.response });
|
||||
} else if (req.method === "POST") {
|
||||
const newlink = await postLink(req.body, session.user.id);
|
||||
|
||||
@@ -221,9 +221,11 @@ export default function Index() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
||||
{links.map((e, i) => {
|
||||
return <LinkCard key={i} link={e} count={i} />;
|
||||
})}
|
||||
{links
|
||||
.filter((e) => e.collectionId === Number(router.query.id))
|
||||
.map((e, i) => {
|
||||
return <LinkCard key={i} link={e} count={i} />;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
|
||||
+6
-4
@@ -35,7 +35,7 @@ export default function Dashboard() {
|
||||
return storedValue ? storedValue === "true" : true;
|
||||
});
|
||||
|
||||
useLinks({ pinnedOnly: true });
|
||||
useLinks({ pinnedOnly: true, sort: 0 });
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(
|
||||
@@ -134,9 +134,11 @@ export default function Dashboard() {
|
||||
leaveTo="transform opacity-0 -translate-y-3"
|
||||
>
|
||||
<Disclosure.Panel className="flex flex-col gap-5 w-full">
|
||||
{links.map((e, i) => (
|
||||
<LinkCard key={i} link={e} count={i} />
|
||||
))}
|
||||
{links
|
||||
.filter((e) => e.pinnedBy)
|
||||
.map((e, i) => (
|
||||
<LinkCard key={i} link={e} count={i} />
|
||||
))}
|
||||
</Disclosure.Panel>
|
||||
</Transition>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function PublicCollections() {
|
||||
useEffect(() => {
|
||||
if (router.query.id) {
|
||||
getPublicCollectionData(
|
||||
router.query.id as string,
|
||||
Number(router.query.id),
|
||||
data as PublicCollectionIncludingLinks,
|
||||
setData
|
||||
);
|
||||
@@ -33,7 +33,7 @@ export default function PublicCollections() {
|
||||
useEffect(() => {
|
||||
if (hasReachedBottom && router.query.id) {
|
||||
getPublicCollectionData(
|
||||
router.query.id as string,
|
||||
Number(router.query.id),
|
||||
data as PublicCollectionIncludingLinks,
|
||||
setData
|
||||
);
|
||||
|
||||
+5
-3
@@ -67,9 +67,11 @@ export default function Index() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 gap-5">
|
||||
{links.map((e, i) => {
|
||||
return <LinkCard key={i} link={e} count={i} />;
|
||||
})}
|
||||
{links
|
||||
.filter((e) => e.tags.some((e) => e.id === Number(router.query.id)))
|
||||
.map((e, i) => {
|
||||
return <LinkCard key={i} link={e} count={i} />;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
|
||||
Reference in New Issue
Block a user