Skip to content

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

feat: choose what to show in dashboard

daniel31x139d8b602839ed
diff --git a/lib/api/controllers/dashboard/getDashboardDataV2.ts b/lib/api/controllers/dashboard/getDashboardDataV2.ts
index b7647376..791e43bc 100644
--- a/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -15,8 +15,22 @@ type Response<D> =
export default async function getDashboardData(
userId: number,
- query: LinkRequestQuery
+ query: LinkRequestQuery,
+ viewRecent: boolean,
+ viewPinned: boolean
): Promise<Response<any>> {
+ let pinnedTake = 0;
+ let recentTake = 0;
+
+ if (viewPinned && viewRecent) {
+ pinnedTake = 16;
+ recentTake = 16;
+ } else if (viewPinned && !viewRecent) {
+ pinnedTake = 32;
+ } else if (!viewPinned && viewRecent) {
+ recentTake = 32;
+ }
+
let order: Order = { id: "desc" };
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
@@ -47,62 +61,81 @@ export default async function getDashboardData(
},
});
- const pinnedLinks = await prisma.link.findMany({
- take: 16,
- where: {
- AND: [
- {
- collection: {
- OR: [
- { ownerId: userId },
- {
- members: {
- some: { userId },
- },
- },
- ],
- },
- },
- {
- pinnedBy: { some: { id: userId } },
- },
- ],
- },
- include: {
- tags: true,
- collection: true,
- pinnedBy: {
- where: { id: userId },
- select: { id: true },
+ if (!viewRecent && !viewPinned) {
+ return {
+ data: {
+ links: [],
+ numberOfPinnedLinks,
},
- },
- orderBy: order || { id: "desc" },
- });
+ message: "Dashboard data fetched successfully.",
+ status: 200,
+ };
+ }
- const recentlyAddedLinks = await prisma.link.findMany({
- take: 16,
- where: {
- collection: {
- OR: [
- { ownerId: userId },
+ let pinnedLinks: any[] = [];
+
+ if (viewPinned) {
+ pinnedLinks = await prisma.link.findMany({
+ take: pinnedTake,
+ where: {
+ AND: [
{
- members: {
- some: { userId },
+ collection: {
+ OR: [
+ { ownerId: userId },
+ {
+ members: {
+ some: { userId },
+ },
+ },
+ ],
},
},
+ {
+ pinnedBy: { some: { id: userId } },
+ },
],
},
- },
- include: {
- tags: true,
- collection: true,
- pinnedBy: {
- where: { id: userId },
- select: { id: true },
+ include: {
+ tags: true,
+ collection: true,
+ pinnedBy: {
+ where: { id: userId },
+ select: { id: true },
+ },
},
- },
- orderBy: order || { id: "desc" },
- });
+ orderBy: order || { id: "desc" },
+ });
+ }
+
+ let recentlyAddedLinks: any[] = [];
+
+ if (viewRecent) {
+ recentlyAddedLinks = await prisma.link.findMany({
+ take: recentTake,
+ where: {
+ collection: {
+ 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].sort(
(a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
diff --git a/lib/api/controllers/users/userId/updateUserById.ts b/lib/api/controllers/users/userId/updateUserById.ts
index 6cebe31b..7f1e0892 100644
--- a/lib/api/controllers/users/userId/updateUserById.ts
+++ b/lib/api/controllers/users/userId/updateUserById.ts
@@ -209,6 +209,8 @@ export default async function updateUserById(
archiveAsPDF: data.archiveAsPDF,
archiveAsWaybackMachine: data.archiveAsWaybackMachine,
linksRouteTo: data.linksRouteTo,
+ dashboardPinnedLinks: data.dashboardPinnedLinks,
+ dashboardRecentLinks: data.dashboardRecentLinks,
preventDuplicateLinks: data.preventDuplicateLinks,
referredBy:
!user?.referredBy && data.referredBy ? data.referredBy : undefined,
diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.ts
index 76219633..5b0b1501 100644
--- a/lib/shared/schemaValidation.ts
+++ b/lib/shared/schemaValidation.ts
@@ -75,6 +75,8 @@ export const UpdateUserSchema = () => {
archiveAsPDF: z.boolean().optional(),
archiveAsMonolith: z.boolean().optional(),
archiveAsWaybackMachine: z.boolean().optional(),
+ dashboardPinnedLinks: z.boolean().optional(),
+ dashboardRecentLinks: z.boolean().optional(),
aiTaggingMethod: z.nativeEnum(AiTaggingMethod).optional(),
aiPredefinedTags: z.array(z.string().max(20).trim()).max(20).optional(),
locale: z.string().max(20).optional(),
diff --git a/pages/api/v2/dashboard/index.ts b/pages/api/v2/dashboard/index.ts
index 2cb6c9e3..0cd5cd29 100644
--- a/pages/api/v2/dashboard/index.ts
+++ b/pages/api/v2/dashboard/index.ts
@@ -16,7 +16,12 @@ export default async function dashboard(
cursor: req.query.cursor ? Number(req.query.cursor as string) : undefined,
};
- const data = await getDashboardDataV2(user.id, convertedData);
+ const data = await getDashboardDataV2(
+ user.id,
+ convertedData,
+ user.dashboardRecentLinks,
+ user.dashboardPinnedLinks
+ );
return res.status(data.status).json({
data: {
links: data.data.links,
diff --git a/pages/dashboard.tsx b/pages/dashboard.tsx
index d96f83fe..6d88e984 100644
--- a/pages/dashboard.tsx
+++ b/pages/dashboard.tsx
@@ -60,16 +60,20 @@ export default function Dashboard() {
}, [account]);
const numberOfLinksToShow = useMemo(() => {
- if (window.innerWidth > 1900) {
- return 10;
- } else if (window.innerWidth > 1500) {
- return 8;
- } else if (window.innerWidth > 880) {
- return 6;
- } else if (window.innerWidth > 550) {
- return 4;
+ if (account.dashboardRecentLinks && account.dashboardPinnedLinks) {
+ if (window.innerWidth > 1900) {
+ return 10;
+ } else if (window.innerWidth > 1500) {
+ return 8;
+ } else if (window.innerWidth > 880) {
+ return 6;
+ } else if (window.innerWidth > 550) {
+ return 4;
+ } else {
+ return 2;
+ }
} else {
- return 2;
+ return 100;
}
}, []);
@@ -153,133 +157,148 @@ export default function Dashboard() {
/>
</div>
- <div className="flex justify-between items-center">
- <div className="flex gap-2 items-center">
- <PageHeader
- icon={"bi-clock-history"}
- title={t("recent")}
- description={t("recent_links_desc")}
- />
- </div>
- <Link
- href="/links"
- className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
- >
- {t("view_all")}
- <i className="bi-chevron-right text-sm"></i>
- </Link>
- </div>
-
- <div
- style={{
- flex: links || dashboardData.isLoading ? "0 1 auto" : "1 1 auto",
- }}
- className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
- >
- {dashboardData.isLoading ? (
- <div className="w-full">
- <Links
- layout={viewMode}
- placeholderCount={settings.columns || 1}
- useData={dashboardData}
- />
- </div>
- ) : links && links[0] && !dashboardData.isLoading ? (
- <div className="w-full">
- <Links
- links={links.slice(
- 0,
- settings.columns ? settings.columns * 2 : numberOfLinksToShow
- )}
- layout={viewMode}
- />
+ {account.dashboardRecentLinks && (
+ <>
+ <div className="flex justify-between items-center">
+ <div className="flex gap-2 items-center">
+ <PageHeader
+ icon={"bi-clock-history"}
+ title={t("recent")}
+ description={t("recent_links_desc")}
+ />
+ </div>
+ <Link
+ href="/links"
+ className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
+ >
+ {t("view_all")}
+ <i className="bi-chevron-right text-sm"></i>
+ </Link>
</div>
- ) : (
- <div className="flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
- <p className="text-center text-2xl">
- {t("view_added_links_here")}
- </p>
- <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm mt-2">
- {t("view_added_links_here_desc")}
- </p>
- <div className="text-center w-full mt-4 flex flex-wrap gap-4 justify-center">
- <div
- onClick={() => {
- setNewLinkModal(true);
- }}
- className="inline-flex items-center gap-2 text-sm btn btn-accent dark:border-violet-400 text-white"
- >
- <i className="bi-plus-lg text-xl"></i>
- <span className="group-hover:opacity-0 text-right">
- {t("add_link")}
- </span>
+ <div
+ style={{
+ flex:
+ links || dashboardData.isLoading ? "0 1 auto" : "1 1 auto",
+ }}
+ className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
+ >
+ {dashboardData.isLoading ? (
+ <div className="w-full">
+ <Links
+ layout={viewMode}
+ placeholderCount={settings.columns || 1}
+ useData={dashboardData}
+ />
</div>
+ ) : links && links[0] && !dashboardData.isLoading ? (
+ <div className="w-full">
+ <Links
+ links={links.slice(
+ 0,
+ settings.columns &&
+ account.dashboardRecentLinks &&
+ account.dashboardPinnedLinks
+ ? settings.columns * 2
+ : numberOfLinksToShow
+ )}
+ layout={viewMode}
+ />
+ </div>
+ ) : (
+ <div className="flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
+ <p className="text-center text-2xl">
+ {t("view_added_links_here")}
+ </p>
+ <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm mt-2">
+ {t("view_added_links_here_desc")}
+ </p>
- <ImportDropdown />
- </div>
- </div>
- )}
- </div>
-
- <div className="flex justify-between items-center">
- <div className="flex gap-2 items-center">
- <PageHeader
- icon={"bi-pin-angle"}
- title={t("pinned")}
- description={t("pinned_links_desc")}
- />
- </div>
- <Link
- href="/links/pinned"
- className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
- >
- {t("view_all")}
- <i className="bi-chevron-right text-sm "></i>
- </Link>
- </div>
+ <div className="text-center w-full mt-4 flex flex-wrap gap-4 justify-center">
+ <div
+ onClick={() => {
+ setNewLinkModal(true);
+ }}
+ className="inline-flex items-center gap-2 text-sm btn btn-accent dark:border-violet-400 text-white"
+ >
+ <i className="bi-plus-lg text-xl"></i>
+ <span className="group-hover:opacity-0 text-right">
+ {t("add_link")}
+ </span>
+ </div>
- <div
- style={{ flex: "1 1 auto" }}
- className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
- >
- {dashboardData.isLoading ? (
- <div className="w-full">
- <Links
- layout={viewMode}
- placeholderCount={settings.columns || 1}
- useData={dashboardData}
- />
+ <ImportDropdown />
+ </div>
+ </div>
+ )}
</div>
- ) : links?.some((e: any) => e.pinnedBy && e.pinnedBy[0]) ? (
- <div className="w-full">
- <Links
- links={links
- .filter((e: any) => e.pinnedBy && e.pinnedBy[0])
- .slice(
- 0,
- settings.columns
- ? settings.columns * 2
- : numberOfLinksToShow
- )}
- layout={viewMode}
- />
+ </>
+ )}
+
+ {account.dashboardPinnedLinks && (
+ <>
+ <div className="flex justify-between items-center">
+ <div className="flex gap-2 items-center">
+ <PageHeader
+ icon={"bi-pin-angle"}
+ title={t("pinned")}
+ description={t("pinned_links_desc")}
+ />
+ </div>
+ <Link
+ href="/links/pinned"
+ className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
+ >
+ {t("view_all")}
+ <i className="bi-chevron-right text-sm "></i>
+ </Link>
</div>
- ) : (
+
<div
style={{ flex: "1 1 auto" }}
- className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200"
+ className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
>
- <i className="bi-pin mx-auto text-6xl text-primary"></i>
- <p className="text-center text-2xl">
- {t("pin_favorite_links_here")}
- </p>
- <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">
- {t("pin_favorite_links_here_desc")}
- </p>
+ {dashboardData.isLoading ? (
+ <div className="w-full">
+ <Links
+ layout={viewMode}
+ placeholderCount={settings.columns || 1}
+ useData={dashboardData}
+ />
+ </div>
+ ) : links?.some((e: any) => e.pinnedBy && e.pinnedBy[0]) ? (
+ <div className="w-full">
+ <Links
+ links={links
+ .filter((e: any) => e.pinnedBy && e.pinnedBy[0])
+ .slice(
+ 0,
+ settings.columns &&
+ account.dashboardRecentLinks &&
+ account.dashboardPinnedLinks
+ ? settings.columns * 2
+ : numberOfLinksToShow
+ )}
+ layout={viewMode}
+ />
+ </div>
+ ) : (
+ <div
+ style={{ flex: "1 1 auto" }}
+ className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200"
+ >
+ <i className="bi-pin mx-auto text-6xl text-primary"></i>
+ <p className="text-center text-2xl">
+ {t("pin_favorite_links_here")}
+ </p>
+ <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">
+ {t("pin_favorite_links_here_desc")}
+ </p>
+ </div>
+ )}
</div>
- )}
- </div>
+ </>
+ )}
</div>
{showSurveyModal && (
<SurveyModal
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index 80e65b1d..10abc7c1 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -30,6 +30,12 @@ export default function Appearance() {
const [archiveAsMonolith, setArchiveAsMonolith] = useState<boolean>(
account.archiveAsMonolith || false
);
+ const [dashboardPinnedLinks, setDashboardPinnedLinks] = useState<boolean>(
+ account.dashboardPinnedLinks || false
+ );
+ const [dashboardRecentLinks, setDashboardRecentLinks] = useState<boolean>(
+ account.dashboardRecentLinks || false
+ );
const [archiveAsWaybackMachine, setArchiveAsWaybackMachine] =
useState<boolean>(account.archiveAsWaybackMachine || false);
const [linksRouteTo, setLinksRouteTo] = useState(account.linksRouteTo);
@@ -49,6 +55,8 @@ export default function Appearance() {
preventDuplicateLinks,
aiTaggingMethod,
aiPredefinedTags,
+ dashboardRecentLinks,
+ dashboardPinnedLinks,
});
}, [
account,
@@ -60,6 +68,8 @@ export default function Appearance() {
preventDuplicateLinks,
aiTaggingMethod,
aiPredefinedTags,
+ dashboardRecentLinks,
+ dashboardPinnedLinks,
]);
function objectIsEmpty(obj: object) {
@@ -76,6 +86,8 @@ export default function Appearance() {
setPreventDuplicateLinks(account.preventDuplicateLinks);
setAiTaggingMethod(account.aiTaggingMethod);
setAiPredefinedTags(account.aiPredefinedTags);
+ setDashboardRecentLinks(account.dashboardRecentLinks);
+ setDashboardPinnedLinks(account.dashboardPinnedLinks);
}
}, [account]);
@@ -223,6 +235,27 @@ export default function Appearance() {
</div>
)}
+ <div>
+ <p className="capitalize text-3xl font-thin inline">
+ {t("dashboard_settings")}
+ </p>
+ <div className="divider my-3"></div>
+ <p>{t("choose_whats_displayed_dashboard")}</p>
+ <div className="p-3">
+ <Checkbox
+ label={t("pinned_links")}
+ state={dashboardPinnedLinks}
+ onClick={() => setDashboardPinnedLinks(!dashboardPinnedLinks)}
+ />
+
+ <Checkbox
+ label={t("recent_links")}
+ state={dashboardRecentLinks}
+ onClick={() => setDashboardRecentLinks(!dashboardRecentLinks)}
+ />
+ </div>
+ </div>
+
<div>
<p className="capitalize text-3xl font-thin inline">
{t("archive_settings")}
diff --git a/prisma/migrations/20241231230724_add_fields/migration.sql b/prisma/migrations/20241231230724_add_fields/migration.sql
new file mode 100644
index 00000000..74c78859
--- /dev/null
+++ b/prisma/migrations/20241231230724_add_fields/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "User" ADD COLUMN "dashboardPinnedLinks" BOOLEAN NOT NULL DEFAULT true,
+ADD COLUMN "dashboardRecentLinks" BOOLEAN NOT NULL DEFAULT true;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index c4cb390c..d8969ac0 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -51,6 +51,8 @@ model User {
linksRouteTo LinksRouteTo @default(ORIGINAL)
aiTaggingMethod AiTaggingMethod @default(DISABLED)
aiPredefinedTags String[] @default([])
+ dashboardRecentLinks Boolean @default(true)
+ dashboardPinnedLinks Boolean @default(true)
preventDuplicateLinks Boolean @default(false)
archiveAsScreenshot Boolean @default(true)
archiveAsMonolith Boolean @default(true)
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index d9ec978b..e8cfa4fa 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -446,5 +446,9 @@
"new_rss_subscription": "New RSS Subscription",
"rss_subscription_deleted": "RSS Subscription deleted!",
"create_rss_subscription": "Create RSS Subscription",
- "rss_feed": "RSS Feed"
+ "rss_feed": "RSS Feed",
+ "dashboard_settings": "Dashboard Settings",
+ "choose_whats_displayed_dashboard": "Choose what's displayed on your Dashboard.",
+ "pinned_links": "Pinned Links",
+ "recent_links": "Recent Links"
}
\ No newline at end of file