Skip to content

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

improvements

daniel31x139f376a633cdf
diff --git a/apps/web/components/DashboardLinks.tsx b/apps/web/components/DashboardLinks.tsx
new file mode 100644
index 00000000..6dbd06ad
--- /dev/null
+++ b/apps/web/components/DashboardLinks.tsx
@@ -0,0 +1,260 @@
+import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";
+import useLocalSettingsStore from "@/store/localSettings";
+import {
+ ArchivedFormat,
+ CollectionIncludingMembersAndLinkCount,
+} from "@linkwarden/types";
+import { useEffect, useRef, useState } from "react";
+import useLinkStore from "@/store/links";
+import unescapeString from "@/lib/client/unescapeString";
+import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";
+import LinkDate from "@/components/LinkViews/LinkComponents/LinkDate";
+import LinkCollection from "@/components/LinkViews/LinkComponents/LinkCollection";
+import Image from "next/image";
+import {
+ atLeastOneFormatAvailable,
+ formatAvailable,
+} from "@linkwarden/lib/formatStats";
+import useOnScreen from "@/hooks/useOnScreen";
+import usePermissions from "@/hooks/usePermissions";
+import toast from "react-hot-toast";
+import { useTranslation } from "next-i18next";
+import { useCollections } from "@linkwarden/router/collections";
+import { useUser } from "@linkwarden/router/user";
+import { useGetLink, useLinks } from "@linkwarden/router/links";
+import { useRouter } from "next/router";
+import openLink from "@/lib/client/openLink";
+import LinkIcon from "./LinkViews/LinkComponents/LinkIcon";
+import LinkFormats from "./LinkViews/LinkComponents/LinkFormats";
+import LinkTypeBadge from "./LinkViews/LinkComponents/LinkTypeBadge";
+import LinkPin from "./LinkViews/LinkComponents/LinkPin";
+
+export function DashboardLinks({
+ links,
+ isLoading,
+}: {
+ links?: LinkIncludingShortenedCollectionAndTags[];
+ isLoading?: boolean;
+}) {
+ return (
+ <div className={`flex gap-5 pb-5 overflow-x-auto hide-scrollbar w-full`}>
+ {links?.map((e, i) => {
+ return <Card key={i} link={e} />;
+ })}
+
+ {isLoading && (
+ <div className="flex flex-col gap-4">
+ <div className="skeleton h-40 w-full"></div>
+ <div className="skeleton h-3 w-2/3"></div>
+ <div className="skeleton h-3 w-full"></div>
+ <div className="skeleton h-3 w-full"></div>
+ <div className="skeleton h-3 w-1/3"></div>
+ </div>
+ )}
+ </div>
+ );
+}
+
+type Props = {
+ link: LinkIncludingShortenedCollectionAndTags;
+ editMode?: boolean;
+};
+
+export function Card({ link, editMode }: Props) {
+ const { t } = useTranslation();
+
+ const { data: collections = [] } = useCollections();
+
+ const { data: user } = useUser();
+
+ const { setSelectedLinks, selectedLinks } = useLinkStore();
+
+ const {
+ settings: { show },
+ } = useLocalSettingsStore();
+
+ const { links } = useLinks();
+
+ const router = useRouter();
+ const isPublicRoute = router.pathname.startsWith("/public") ? true : false;
+
+ const { refetch } = useGetLink({ id: link.id as number, isPublicRoute });
+
+ useEffect(() => {
+ if (!editMode) {
+ setSelectedLinks([]);
+ }
+ }, [editMode]);
+
+ const handleCheckboxClick = (
+ link: LinkIncludingShortenedCollectionAndTags
+ ) => {
+ if (selectedLinks.includes(link)) {
+ setSelectedLinks(selectedLinks.filter((e) => e !== link));
+ } else {
+ setSelectedLinks([...selectedLinks, link]);
+ }
+ };
+
+ let shortendURL;
+
+ try {
+ if (link.url) {
+ shortendURL = new URL(link.url).host.toLowerCase();
+ }
+ } catch (error) {
+ console.log(error);
+ }
+
+ const [collection, setCollection] =
+ useState<CollectionIncludingMembersAndLinkCount>(
+ collections.find(
+ (e) => e.id === link.collection.id
+ ) as CollectionIncludingMembersAndLinkCount
+ );
+
+ useEffect(() => {
+ setCollection(
+ collections.find(
+ (e) => e.id === link.collection.id
+ ) as CollectionIncludingMembersAndLinkCount
+ );
+ }, [collections, links]);
+
+ const ref = useRef<HTMLDivElement>(null);
+ const isVisible = useOnScreen(ref);
+ const permissions = usePermissions(collection?.id as number);
+
+ const [linkModal, setLinkModal] = useState(false);
+
+ useEffect(() => {
+ let interval: NodeJS.Timeout | null = null;
+
+ if (
+ isVisible &&
+ !link.preview?.startsWith("archives") &&
+ link.preview !== "unavailable"
+ ) {
+ interval = setInterval(async () => {
+ refetch().catch((error) => {
+ console.error("Error refetching link:", error);
+ });
+ }, 5000);
+ }
+
+ return () => {
+ if (interval) {
+ clearInterval(interval);
+ }
+ };
+ }, [isVisible, link.preview]);
+
+ const selectedStyle = selectedLinks.some(
+ (selectedLink) => selectedLink.id === link.id
+ )
+ ? "border-primary bg-base-300"
+ : "border-neutral-content";
+
+ const selectable =
+ editMode &&
+ (permissions === true || permissions?.canCreate || permissions?.canDelete);
+
+ return (
+ <div
+ ref={ref}
+ className={`${selectedStyle} w-52 border border-solid border-neutral-content bg-base-200 shadow-md hover:shadow-none duration-100 rounded-xl relative group`}
+ onClick={() =>
+ selectable
+ ? handleCheckboxClick(link)
+ : editMode
+ ? toast.error(t("link_selection_error"))
+ : undefined
+ }
+ >
+ <div
+ className="rounded-xl cursor-pointer h-full w-52 flex flex-col justify-between"
+ onClick={() =>
+ !editMode && openLink(link, user, () => setLinkModal(true))
+ }
+ >
+ {show.image && (
+ <div>
+ <div className={`relative rounded-t-xl h-40 overflow-hidden`}>
+ {formatAvailable(link, "preview") ? (
+ <Image
+ src={`/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true&updatedAt=${link.updatedAt}`}
+ width={1280}
+ height={720}
+ alt=""
+ className={`rounded-t-xl select-none object-cover z-10 h-40 w-full shadow opacity-80 scale-105`}
+ style={show.icon ? { filter: "blur(1px)" } : undefined}
+ draggable="false"
+ onError={(e) => {
+ const target = e.target as HTMLElement;
+ target.style.display = "none";
+ }}
+ />
+ ) : link.preview === "unavailable" ? (
+ <div className={`bg-gray-50 h-40 bg-opacity-80`}></div>
+ ) : (
+ <div
+ className={`h-40 bg-opacity-80 skeleton rounded-none`}
+ ></div>
+ )}
+ {show.icon && (
+ <div className="absolute top-0 left-0 right-0 bottom-0 rounded-t-xl flex items-center justify-center rounded-md">
+ <LinkIcon link={link} />
+ </div>
+ )}
+ {show.preserved_formats &&
+ link.type === "url" &&
+ atLeastOneFormatAvailable(link) && (
+ <div className="absolute bottom-0 right-0 m-2 bg-base-200 bg-opacity-60 px-1 rounded-md">
+ <LinkFormats link={link} />
+ </div>
+ )}
+ </div>
+ <hr className="divider my-0 border-t border-neutral-content h-[1px]" />
+ </div>
+ )}
+
+ <div className="flex flex-col justify-between h-full min-h-24">
+ <div className="p-3 flex flex-col justify-between h-full gap-2">
+ {show.name && (
+ <p className="line-clamp-2 w-full text-primary text-sm">
+ {unescapeString(link.name)}
+ </p>
+ )}
+
+ {show.link && <LinkTypeBadge link={link} />}
+ </div>
+
+ {(show.collection || show.date) && (
+ <div>
+ <hr className="divider mt-0 mb-1 last:hidden border-t border-neutral-content h-[1px]" />
+
+ <div className="flex justify-between items-center text-xs text-neutral px-3 pb-1 gap-2">
+ {show.collection && !isPublicRoute && (
+ <div className="cursor-pointer truncate">
+ <LinkCollection link={link} collection={collection} />
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+
+ {/* Overlay on hover */}
+ <div className="absolute pointer-events-none top-0 left-0 right-0 bottom-0 bg-base-100 bg-opacity-0 group-hover:bg-opacity-20 group-focus-within:opacity-20 rounded-xl duration-100"></div>
+ <LinkActions
+ link={link}
+ collection={collection}
+ linkModal={linkModal}
+ setLinkModal={(e) => setLinkModal(e)}
+ className="absolute top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100 text-neutral z-20"
+ />
+ {!isPublicRoute && <LinkPin link={link} />}
+ </div>
+ );
+}
diff --git a/apps/web/components/NoLinksFound.tsx b/apps/web/components/NoLinksFound.tsx
index 5d440430..3888b6b0 100644
--- a/apps/web/components/NoLinksFound.tsx
+++ b/apps/web/components/NoLinksFound.tsx
@@ -24,7 +24,7 @@ export default function NoLinksFound({ text }: Props) {
<path d="M7.009 12.139a7.632 7.632 0 0 1-1.804-1.352A7.568 7.568 0 0 1 3.794 8.86c-1.102.992-1.965 5.054-1.839 5.18.125.126 3.936-.896 5.054-1.902Z" />
</svg>
<p className="text-center text-xl sm:text-xl">
- {text || "You haven't created any Links Here"}
+ {text || t("no_links_in_collection")}
</p>
<p className="text-center text-sm sm:text-base">{t("start_journey")}</p>
<div className="text-center w-full mt-4">
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
index b9646948..17c37e79 100644
--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts
@@ -67,7 +67,7 @@ export default async function getDashboardData(
if (viewPinned) {
pinnedLinks = await prisma.link.findMany({
- take: 10,
+ take: 16,
where: {
AND: [
{
@@ -103,7 +103,7 @@ export default async function getDashboardData(
if (viewRecent) {
recentlyAddedLinks = await prisma.link.findMany({
- take: 10,
+ take: 16,
where: {
collection: {
OR: [
@@ -154,7 +154,7 @@ export default async function getDashboardData(
},
],
},
- take: 10,
+ take: 16,
include: {
tags: true,
collection: true,
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 505b9a75..b66b1546 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -3,17 +3,14 @@ import { useEffect, useMemo, useState } from "react";
import Link from "next/link";
import React from "react";
import { toast } from "react-hot-toast";
-import { ViewMode } from "@linkwarden/types";
import DashboardItem from "@/components/DashboardItem";
import NewLinkModal from "@/components/ModalContent/NewLinkModal";
import PageHeader from "@/components/PageHeader";
-import ViewDropdown from "@/components/ViewDropdown";
import getServerSideProps from "@/lib/client/getServerSideProps";
import { useTranslation } from "next-i18next";
import { useCollections } from "@linkwarden/router/collections";
import { useTags } from "@linkwarden/router/tags";
import { useDashboardData } from "@linkwarden/router/dashboardData";
-import Links from "@/components/LinkViews/Links";
import useLocalSettingsStore from "@/store/localSettings";
import { useUpdateUser, useUser } from "@linkwarden/router/user";
import SurveyModal from "@/components/ModalContent/SurveyModal";
@@ -24,6 +21,7 @@ import {
DashboardSection,
DashboardSectionType,
} from "@linkwarden/prisma/client";
+import { DashboardLinks } from "@/components/DashboardLinks";
export default function Dashboard() {
const { t } = useTranslation();
@@ -99,30 +97,8 @@ export default function Dashboard() {
setShowPinnedLinks(pinnedLinks || false);
}, [dashboardSections]);
- const numberOfLinksToShow = useMemo(() => {
- if (showRecentLinks && showPinnedLinks) {
- 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 100;
- }
- }, [showRecentLinks, showPinnedLinks]);
-
const [newLinkModal, setNewLinkModal] = useState(false);
- const [viewMode, setViewMode] = useState<ViewMode>(
- (localStorage.getItem("viewMode") as ViewMode) || ViewMode.Card
- );
-
const [showSurveyModal, setShowsSurveyModal] = useState(false);
const updateUser = useUpdateUser();
@@ -211,26 +187,9 @@ export default function Dashboard() {
}}
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 && showRecentLinks && showPinnedLinks
- ? settings.columns * 2
- : numberOfLinksToShow
- )}
- layout={viewMode}
- />
- </div>
+ {dashboardData.isLoading ||
+ (links && links[0] && !dashboardData.isLoading) ? (
+ <DashboardLinks links={links} isLoading={dashboardData.isLoading} />
) : (
<div className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
<p className="text-center text-xl">{t("view_added_links_here")}</p>
@@ -280,28 +239,12 @@ export default function Dashboard() {
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}
- />
- </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 && showRecentLinks && showPinnedLinks
- ? settings.columns * 2
- : numberOfLinksToShow
- )}
- layout={viewMode}
- />
- </div>
+ {dashboardData.isLoading ||
+ links?.some((e: any) => e.pinnedBy && e.pinnedBy[0]) ? (
+ <DashboardLinks
+ links={links.filter((e: any) => e.pinnedBy && e.pinnedBy[0])}
+ isLoading={dashboardData.isLoading}
+ />
) : (
<div
style={{ flex: "1 1 auto" }}
@@ -344,24 +287,15 @@ export default function Dashboard() {
</div>
<div 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?.filter((link: any) => link.collection.id === collection.id)
- .length > 0 ? (
- <div className="w-full">
- <Links
- links={links
- .filter((link: any) => link.collection.id === collection.id)
- .slice(0, numberOfLinksToShow)}
- layout={viewMode}
- />
- </div>
+ {dashboardData.isLoading ||
+ links?.filter((link: any) => link.collection.id === collection.id)
+ .length > 0 ? (
+ <DashboardLinks
+ links={links.filter(
+ (link: any) => link.collection.id === collection.id
+ )}
+ isLoading={dashboardData.isLoading}
+ />
) : (
<div className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
<i className="bi-folder mx-auto text-6xl text-primary"></i>
@@ -401,7 +335,6 @@ export default function Dashboard() {
/>
<div className="flex items-center gap-3">
<DashboardLayoutDropdown />
- <ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
</div>
</div>