Skip to content

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

bug fixed

daniel31x13352389958c94
diff --git a/apps/web/components/DashboardLayoutDropdown.tsx b/apps/web/components/DashboardLayoutDropdown.tsx
index f1f4088b..94b8fd96 100644
--- a/apps/web/components/DashboardLayoutDropdown.tsx
+++ b/apps/web/components/DashboardLayoutDropdown.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useMemo, DragEvent } from "react";
+import React, { useState, useMemo, DragEvent, useEffect } from "react";
import {
DropdownMenu,
DropdownMenuTrigger,
@@ -35,7 +35,13 @@ export default function DashboardLayoutDropdown() {
"above" | "below" | null
>(null);
- const dashboardSections: DashboardSection[] = user?.dashboardSections || [];
+ const [dashboardSections, setDashboardSections] = useState<
+ DashboardSection[]
+ >(user?.dashboardSections || []);
+
+ useEffect(() => {
+ setDashboardSections(user?.dashboardSections || []);
+ }, [user?.dashboardSections]);
const getSectionOrder = (
type: DashboardSectionType,
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
index 604206ec..b9646948 100644
--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -2,14 +2,14 @@ import { prisma } from "@linkwarden/prisma";
import { LinkRequestQuery, Order, Sort } from "@linkwarden/types";
export default async function getDashboardData(
- userId: number,
- query: LinkRequestQuery
+ userId: number
+ // query: LinkRequestQuery
) {
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" };
+ // 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: {
@@ -67,7 +67,7 @@ export default async function getDashboardData(
if (viewPinned) {
pinnedLinks = await prisma.link.findMany({
- take: 16,
+ take: 10,
where: {
AND: [
{
@@ -103,7 +103,7 @@ export default async function getDashboardData(
if (viewRecent) {
recentlyAddedLinks = await prisma.link.findMany({
- take: 16,
+ take: 10,
where: {
collection: {
OR: [
@@ -154,6 +154,7 @@ export default async function getDashboardData(
},
],
},
+ take: 10,
include: {
tags: true,
collection: true,
diff --git a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
index 6bdec0dc..0da40307 100644
--- a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
+++ b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts
@@ -4,6 +4,7 @@ import {
} from "@linkwarden/lib/schemaValidation";
import { prisma } from "@linkwarden/prisma";
import { DashboardSection } from "@linkwarden/prisma/client";
+import getDashboardData from "./getDashboardDataV2";
export default async function updateDashboardLayout(
userId: number,
@@ -178,8 +179,10 @@ export default async function updateDashboardLayout(
}
});
+ const getData = await getDashboardData(userId);
+
return {
status: 200,
- response: parsedData,
+ response: getData,
};
}
diff --git a/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts b/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts
index f6e7141e..97a3454c 100644
--- a/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts
+++ b/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts
@@ -35,6 +35,7 @@ export default async function updateUserPreference(
include: {
whitelistedUsers: true,
subscriptions: true,
+ dashboardSections: true,
parentSubscription: {
include: {
user: true,
diff --git a/apps/web/pages/api/v2/dashboard/index.ts b/apps/web/pages/api/v2/dashboard/index.ts
index 9dac0f3f..9efc116a 100644
--- a/apps/web/pages/api/v2/dashboard/index.ts
+++ b/apps/web/pages/api/v2/dashboard/index.ts
@@ -1,8 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next";
-import { LinkRequestQuery } from "@linkwarden/types";
+// import { LinkRequestQuery } from "@linkwarden/types";
import getDashboardDataV2 from "@/lib/api/controllers/dashboard/getDashboardDataV2";
import verifyUser from "@/lib/api/verifyUser";
-import { UpdateDashboardLayoutSchema } from "@linkwarden/lib/schemaValidation";
import updateDashboardLayout from "@/lib/api/controllers/dashboard/updateDashboardLayout";
export default async function dashboard(
@@ -13,14 +12,14 @@ export default async function dashboard(
if (!user) return;
if (req.method === "GET") {
- const convertedData: LinkRequestQuery = {
- sort: Number(req.query.sort as string),
- cursor: req.query.cursor ? Number(req.query.cursor as string) : undefined,
- };
+ // const convertedData: LinkRequestQuery = {
+ // sort: Number(req.query.sort as string),
+ // cursor: req.query.cursor ? Number(req.query.cursor as string) : undefined,
+ // };
const { statusCode, ...data } = await getDashboardDataV2(
- user.id,
- convertedData
+ user.id
+ // convertedData
);
return res.status(statusCode).json(data);
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 5f1b8907..505b9a75 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -36,6 +36,16 @@ export default function Dashboard() {
const { data: user } = useUser();
const [numberOfLinks, setNumberOfLinks] = useState(0);
+ const [showRecentLinks, setShowRecentLinks] = useState(false);
+ const [showPinnedLinks, setShowPinnedLinks] = useState(false);
+
+ const [dashboardSections, setDashboardSections] = useState<
+ DashboardSection[]
+ >(user?.dashboardSections || []);
+
+ useEffect(() => {
+ setDashboardSections(user?.dashboardSections || []);
+ }, [user?.dashboardSections]);
const { settings } = useLocalSettingsStore();
@@ -65,8 +75,6 @@ export default function Dashboard() {
}
}, [user]);
- const dashboardSections: DashboardSection[] = user?.dashboardSections || [];
-
// Sort sections by order and filter enabled ones
const orderedSections = useMemo(() => {
return dashboardSections.sort((a, b) => {
@@ -79,12 +87,17 @@ export default function Dashboard() {
});
}, [dashboardSections]);
- const showRecentLinks = dashboardSections.some(
- (section) => section.type === "RECENT_LINKS"
- );
- const showPinnedLinks = dashboardSections.some(
- (section) => section.type === "PINNED_LINKS"
- );
+ useEffect(() => {
+ const recentLinks = dashboardSections.some(
+ (section) => section.type === "RECENT_LINKS"
+ );
+ const pinnedLinks = dashboardSections.some(
+ (section) => section.type === "PINNED_LINKS"
+ );
+
+ setShowRecentLinks(recentLinks || false);
+ setShowPinnedLinks(pinnedLinks || false);
+ }, [dashboardSections]);
const numberOfLinksToShow = useMemo(() => {
if (showRecentLinks && showPinnedLinks) {
@@ -392,7 +405,7 @@ export default function Dashboard() {
</div>
</div>
- {orderedSections.map((section) => (
+ {orderedSections?.map((section) => (
<div key={`${section.type}-${section.collectionId || "default"}`}>
{renderSection(section)}
</div>
diff --git a/packages/router/dashboardData.tsx b/packages/router/dashboardData.tsx
index f174a5d1..96e03eb1 100644
--- a/packages/router/dashboardData.tsx
+++ b/packages/router/dashboardData.tsx
@@ -55,6 +55,7 @@ const useUpdateDashboardLayout = () => {
},
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ["user"] });
+ await queryClient.invalidateQueries({ queryKey: ["dashboardData"] });
},
});
};