Skip to content

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

fix returned links

Isaace012c8953c05
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
index 2a917ab8..b6fefc0e 100644
--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -1,11 +1,13 @@
import { prisma } from "@linkwarden/prisma";
+import { DashboardSection } from "@linkwarden/prisma/client";
import { LinkRequestQuery, Order, Sort } from "@linkwarden/types";
export default async function getDashboardData(
userId: number,
query: LinkRequestQuery,
viewRecent: boolean,
- viewPinned: boolean
+ viewPinned: boolean,
+ collectionSections: DashboardSection[]
) {
let pinnedTake = 0;
let recentTake = 0;
@@ -47,7 +49,7 @@ export default async function getDashboardData(
},
});
- if (!viewRecent && !viewPinned) {
+ if (!viewRecent && !viewPinned && collectionSections.length === 0) {
return {
data: {
links: [],
@@ -124,9 +126,50 @@ export default async function getDashboardData(
});
}
- const links = [...recentlyAddedLinks, ...pinnedLinks].sort(
- (a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
- );
+ let collectionLinks: any[] = [];
+
+ if (collectionSections.length > 0) {
+ const collectionIds = collectionSections
+ .filter((section) => section.collectionId !== null)
+ .map((section) => section.collectionId!);
+
+ if (collectionIds.length > 0) {
+ collectionLinks = await prisma.link.findMany({
+ where: {
+ AND: [
+ {
+ collection: {
+ id: { in: collectionIds },
+ OR: [
+ { ownerId: userId },
+ {
+ members: {
+ some: { userId },
+ },
+ },
+ ],
+ },
+ },
+ ],
+ },
+ include: {
+ tags: true,
+ collection: true,
+ pinnedBy: {
+ where: { id: userId },
+ select: { id: true },
+ },
+ },
+ orderBy: order || { id: "desc" },
+ });
+ }
+ }
+
+ const links = [
+ ...recentlyAddedLinks,
+ ...pinnedLinks,
+ ...collectionLinks,
+ ].sort((a, b) => new Date(b.id).getTime() - new Date(a.id).getTime());
// Make sure links are unique
const uniqueLinks = links.filter(
diff --git a/apps/web/pages/api/v2/dashboard/index.ts b/apps/web/pages/api/v2/dashboard/index.ts
index 5aaff7dd..9f5d2318 100644
--- a/apps/web/pages/api/v2/dashboard/index.ts
+++ b/apps/web/pages/api/v2/dashboard/index.ts
@@ -21,15 +21,21 @@ export default async function dashboard(
const showRecentLinks = user.dashboardSections.some(
(section) => section.type === "RECENT_LINKS"
);
+
const showPinnedLinks = user.dashboardSections.some(
(section) => section.type === "PINNED_LINKS"
);
+ const collectionSections = user.dashboardSections.filter(
+ (section) => section.type === "COLLECTION"
+ );
+
const { statusCode, ...data } = await getDashboardDataV2(
user.id,
convertedData,
showRecentLinks,
- showPinnedLinks
+ showPinnedLinks,
+ collectionSections
);
return res.status(statusCode).json(data);