Skip to content

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

bug fixed

daniel31x134712dc9b267d
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
index 17c37e79..c256b050 100644
--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -1,15 +1,8 @@
import { prisma } from "@linkwarden/prisma";
-import { LinkRequestQuery, Order, Sort } from "@linkwarden/types";
+import { Order } from "@linkwarden/types";
-export default async function getDashboardData(
- userId: number
- // query: LinkRequestQuery
-) {
+export default async function getDashboardData(userId: number) {
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" };
- // else if (query.sort === Sort.NameZA) order = { name: "desc" };
const dashboardSections = await prisma.dashboardSection.findMany({
where: {
@@ -128,7 +121,7 @@ export default async function getDashboardData(
});
}
- let collectionLinks: any[] = [];
+ let collectionLinks: any = {};
if (collectionSections.length > 0) {
const collectionIds = collectionSections
@@ -136,43 +129,44 @@ export default async function getDashboardData(
.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 },
+ for (const collectionId of collectionIds) {
+ const links = await prisma.link.findMany({
+ where: {
+ AND: [
+ {
+ collection: {
+ id: collectionId,
+ OR: [
+ { ownerId: userId },
+ {
+ members: {
+ some: { userId },
+ },
},
- },
- ],
+ ],
+ },
},
+ ],
+ },
+ take: 16,
+ include: {
+ tags: true,
+ collection: true,
+ pinnedBy: {
+ where: { id: userId },
+ select: { id: true },
},
- ],
- },
- take: 16,
- include: {
- tags: true,
- collection: true,
- pinnedBy: {
- where: { id: userId },
- select: { id: true },
},
- },
- orderBy: order || { id: "desc" },
- });
+ orderBy: order || { id: "desc" },
+ });
+ collectionLinks[collectionId] = links;
+ }
}
}
- const links = [
- ...recentlyAddedLinks,
- ...pinnedLinks,
- ...collectionLinks,
- ].sort((a, b) => new Date(b.id).getTime() - new Date(a.id).getTime());
+ const links = [...recentlyAddedLinks, ...pinnedLinks].sort(
+ (a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
+ );
const uniqueLinks = links.filter(
(link, index, self) => index === self.findIndex((t) => t.id === link.id)
@@ -181,6 +175,7 @@ export default async function getDashboardData(
return {
data: {
links: uniqueLinks,
+ collectionLinks,
numberOfPinnedLinks,
},
message: "Dashboard data fetched successfully.",
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 288e9aac..e3b0cbac 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -30,7 +30,9 @@ export default function Dashboard() {
const { t } = useTranslation();
const { data: collections = [] } = useCollections();
const {
- data: { links = [], numberOfPinnedLinks } = { links: [] },
+ data: { links = [], numberOfPinnedLinks, collectionLinks = {} } = {
+ links: [],
+ },
...dashboardData
} = useDashboardData();
const { data: tags = [] } = useTags();
@@ -151,6 +153,11 @@ export default function Dashboard() {
collection={collections.find(
(c) => c.id === section.collectionId
)}
+ collectionLinks={
+ section.collectionId
+ ? collectionLinks[section.collectionId]
+ : []
+ }
links={links}
tags={tags}
numberOfLinks={numberOfLinks}
@@ -200,6 +207,7 @@ type SectionProps = {
numberOfLinks: number;
numberOfPinnedLinks: number;
dashboardData: any;
+ collectionLinks: any[];
setNewLinkModal: (value: boolean) => void;
};
@@ -213,6 +221,7 @@ const Section = ({
collectionsLength,
numberOfPinnedLinks,
dashboardData,
+ collectionLinks,
setNewLinkModal,
}: SectionProps) => {
switch (sectionData.type) {
@@ -358,14 +367,9 @@ const Section = ({
<i className="bi-chevron-right text-sm"></i>
</Link>
</div>
-
- {dashboardData.isLoading ||
- links?.filter((link: any) => link.collection.id === collection.id)
- .length > 0 ? (
+ {dashboardData.isLoading || collectionLinks?.length > 0 ? (
<DashboardLinks
- links={links.filter(
- (link: any) => link.collection.id === collection.id
- )}
+ links={collectionLinks}
isLoading={dashboardData.isLoading}
/>
) : (