Skip to content

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

bug fix and small performance improvement

daniel31x1348b738449008
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx b/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
index a2b4118a..bf26a61b 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkActions.tsx
@@ -24,7 +24,6 @@ import ConfirmationModal from "@/components/ConfirmationModal";
type Props = {
link: LinkIncludingShortenedCollectionAndTags;
- collection: CollectionIncludingMembersAndLinkCount;
linkModal: boolean;
className?: string;
setLinkModal: (value: boolean) => void;
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
index e31a30e3..d67cee12 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
@@ -1,6 +1,5 @@
import {
ArchivedFormat,
- CollectionIncludingMembersAndLinkCount,
LinkIncludingShortenedCollectionAndTags,
} from "@linkwarden/types";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -22,7 +21,7 @@ import LinkTypeBadge from "./LinkTypeBadge";
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 { useGetLink } from "@linkwarden/router/links";
import { useRouter } from "next/router";
import useLocalSettingsStore from "@/store/localSettings";
import LinkPin from "./LinkPin";
@@ -79,8 +78,6 @@ export default function LinkCard({ link, columns, editMode }: Props) {
settings: { show },
} = useLocalSettingsStore();
- const { links } = useLinks();
-
const router = useRouter();
const isPublicRoute = router.pathname.startsWith("/public") ? true : false;
@@ -102,20 +99,9 @@ export default function LinkCard({ link, columns, editMode }: Props) {
}
};
- 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 collection = useMemo(() => {
+ return collections.find((c) => c.id === link.collection.id);
+ }, [collections, link.collection.id]);
const ref = useRef<HTMLDivElement>(null);
const isVisible = useOnScreen(ref);
@@ -241,7 +227,7 @@ export default function LinkCard({ link, columns, editMode }: Props) {
<Separator className="mb-1" />
<div className="flex justify-between items-center text-xs text-neutral px-3 pb-1 gap-2">
- {show.collection && !isPublicRoute && (
+ {show.collection && !isPublicRoute && collection && (
<div className="cursor-pointer truncate">
<LinkCollection link={link} collection={collection} />
</div>
@@ -257,7 +243,6 @@ export default function LinkCard({ link, columns, editMode }: Props) {
<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"
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
index 68cfd239..2c51031f 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
@@ -1,8 +1,5 @@
-import {
- CollectionIncludingMembersAndLinkCount,
- LinkIncludingShortenedCollectionAndTags,
-} from "@linkwarden/types";
-import { useEffect, useState } from "react";
+import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";
+import { useEffect, useMemo, useState } from "react";
import useLinkStore from "@/store/links";
import unescapeString from "@/lib/client/unescapeString";
import LinkActions from "@/components/LinkViews/LinkComponents/LinkActions";
@@ -16,7 +13,6 @@ import LinkTypeBadge from "./LinkTypeBadge";
import { useTranslation } from "next-i18next";
import { useCollections } from "@linkwarden/router/collections";
import { useUser } from "@linkwarden/router/user";
-import { useLinks } from "@linkwarden/router/links";
import useLocalSettingsStore from "@/store/localSettings";
import LinkPin from "./LinkPin";
import { useRouter } from "next/router";
@@ -54,8 +50,6 @@ export default function LinkCardCompact({ link, editMode }: Props) {
settings: { show },
} = useLocalSettingsStore();
- const { links } = useLinks();
-
useEffect(() => {
if (!editMode) {
setSelectedLinks([]);
@@ -78,20 +72,9 @@ export default function LinkCardCompact({ link, editMode }: Props) {
}
};
- 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 collection = useMemo(() => {
+ return collections.find((c) => c.id === link.collection.id);
+ }, [collections, link.collection.id]);
const permissions = usePermissions(collection?.id as number);
@@ -163,7 +146,7 @@ export default function LinkCardCompact({ link, editMode }: Props) {
<div className="mt-1 flex flex-col sm:flex-row sm:items-center gap-2 text-xs text-neutral">
<div className="flex items-center gap-x-3 text-neutral flex-wrap">
{show.link && <LinkTypeBadge link={link} />}
- {show.collection && (
+ {show.collection && collection && (
<LinkCollection link={link} collection={collection} />
)}
{show.date && <LinkDate link={link} />}
@@ -174,7 +157,6 @@ export default function LinkCardCompact({ link, editMode }: Props) {
{!isPublic && <LinkPin link={link} />}
<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"
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
index df81b563..dd659d4b 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
@@ -1,6 +1,5 @@
import {
ArchivedFormat,
- CollectionIncludingMembersAndLinkCount,
LinkIncludingShortenedCollectionAndTags,
} from "@linkwarden/types";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -23,7 +22,7 @@ import LinkTypeBadge from "./LinkTypeBadge";
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 { useGetLink } from "@linkwarden/router/links";
import useLocalSettingsStore from "@/store/localSettings";
import clsx from "clsx";
import LinkPin from "./LinkPin";
@@ -80,8 +79,6 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
settings: { show },
} = useLocalSettingsStore();
- const { links } = useLinks();
-
const router = useRouter();
let isPublicRoute = router.pathname.startsWith("/public") ? true : undefined;
@@ -104,20 +101,9 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
}
};
- 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 collection = useMemo(() => {
+ return collections.find((c) => c.id === link.collection.id);
+ }, [collections, link.collection.id]);
const ref = useRef<HTMLDivElement>(null);
const isVisible = useOnScreen(ref);
@@ -259,7 +245,7 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
<Separator className="mb-1" />
<div className="flex flex-wrap justify-between items-center text-xs text-neutral px-3 pb-1 w-full gap-x-2">
- {!isPublicRoute && show.collection && (
+ {!isPublicRoute && show.collection && collection && (
<div className="cursor-pointer truncate">
<LinkCollection link={link} collection={collection} />
</div>
@@ -274,7 +260,6 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
<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"
diff --git a/apps/web/components/LinkViews/Links.tsx b/apps/web/components/LinkViews/Links.tsx
index 2a5db4a1..6dda709e 100644
--- a/apps/web/components/LinkViews/Links.tsx
+++ b/apps/web/components/LinkViews/Links.tsx
@@ -7,24 +7,20 @@ import { useEffect, useState } from "react";
import { useInView } from "react-intersection-observer";
import LinkMasonry from "@/components/LinkViews/LinkComponents/LinkMasonry";
import Masonry from "react-masonry-css";
-import resolveConfig from "tailwindcss/resolveConfig";
-import tailwindConfig from "../../tailwind.config.js";
import { useMemo } from "react";
import LinkList from "@/components/LinkViews/LinkComponents/LinkList";
import useLocalSettingsStore from "@/store/localSettings";
-export function CardView({
+function CardView({
links,
editMode,
isLoading,
- placeholders,
hasNextPage,
placeHolderRef,
}: {
links?: LinkIncludingShortenedCollectionAndTags[];
editMode?: boolean;
isLoading?: boolean;
- placeholders?: number[];
hasNextPage?: boolean;
placeHolderRef?: any;
}) {
@@ -82,10 +78,10 @@ export function CardView({
return (
<div className={`${gridColClass} grid gap-5 pb-5`}>
- {links?.map((e, i) => {
+ {links?.map((e) => {
return (
<LinkCard
- key={i}
+ key={e.id}
link={e}
editMode={editMode}
columns={columnCount}
@@ -93,38 +89,29 @@ export function CardView({
);
})}
- {(hasNextPage || isLoading) &&
- placeholders?.map((e, i) => {
- return (
- <div
- className="flex flex-col gap-4"
- ref={e === 1 ? placeHolderRef : undefined}
- key={i}
- >
- <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>
- );
- })}
+ {(hasNextPage || isLoading) && (
+ <div className="flex flex-col gap-4" ref={placeHolderRef}>
+ <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>
);
}
-export function MasonryView({
+function MasonryView({
links,
editMode,
isLoading,
- placeholders,
hasNextPage,
placeHolderRef,
}: {
links?: LinkIncludingShortenedCollectionAndTags[];
editMode?: boolean;
isLoading?: boolean;
- placeholders?: number[];
hasNextPage?: boolean;
placeHolderRef?: any;
}) {
@@ -180,17 +167,7 @@ export function MasonryView({
};
}, [settings.columns]);
- const fullConfig = resolveConfig(tailwindConfig as any);
-
- const breakpointColumnsObj = useMemo(() => {
- return {
- default: 5,
- 1900: 4,
- 1500: 3,
- 880: 2,
- 550: 1,
- };
- }, []);
+ const breakpointColumnsObj = { default: 5, 1900: 4, 1500: 3, 880: 2, 550: 1 };
return (
<Masonry
@@ -200,10 +177,10 @@ export function MasonryView({
columnClassName="flex flex-col gap-5 !w-full"
className={`${gridColClass} grid gap-5 pb-5`}
>
- {links?.map((e, i) => {
+ {links?.map((e) => {
return (
<LinkMasonry
- key={i}
+ key={e.id}
link={e}
editMode={editMode}
columns={columnCount}
@@ -211,31 +188,23 @@ export function MasonryView({
);
})}
- {(hasNextPage || isLoading) &&
- placeholders?.map((e, i) => {
- return (
- <div
- className="flex flex-col gap-4"
- ref={e === 1 ? placeHolderRef : undefined}
- key={i}
- >
- <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>
- );
- })}
+ {(hasNextPage || isLoading) && (
+ <div className="flex flex-col gap-4" ref={placeHolderRef}>
+ <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>
+ )}
</Masonry>
);
}
-export function ListView({
+function ListView({
links,
editMode,
isLoading,
- placeholders,
hasNextPage,
placeHolderRef,
}: {
@@ -249,26 +218,19 @@ export function ListView({
return (
<div className="flex flex-col">
{links?.map((e, i) => {
- return <LinkList key={i} link={e} count={i} editMode={editMode} />;
+ return <LinkList key={e.id} link={e} count={i} editMode={editMode} />;
})}
- {(hasNextPage || isLoading) &&
- placeholders?.map((e, i) => {
- return (
- <div
- ref={e === 1 ? placeHolderRef : undefined}
- key={i}
- className="flex gap-2 py-2 px-1"
- >
- <div className="skeleton h-12 w-12"></div>
- <div className="flex flex-col gap-3 w-full">
- <div className="skeleton h-2 w-2/3"></div>
- <div className="skeleton h-2 w-full"></div>
- <div className="skeleton h-2 w-1/3"></div>
- </div>
- </div>
- );
- })}
+ {(hasNextPage || isLoading) && (
+ <div ref={placeHolderRef} className="flex gap-2 py-2 px-1">
+ <div className="skeleton h-12 w-12"></div>
+ <div className="flex flex-col gap-3 w-full">
+ <div className="skeleton h-2 w-2/3"></div>
+ <div className="skeleton h-2 w-full"></div>
+ <div className="skeleton h-2 w-1/3"></div>
+ </div>
+ </div>
+ )}
</div>
);
}
@@ -277,13 +239,11 @@ export default function Links({
layout,
links,
editMode,
- placeholderCount,
useData,
}: {
layout: ViewMode;
links?: LinkIncludingShortenedCollectionAndTags[];
editMode?: boolean;
- placeholderCount?: number;
useData?: any;
}) {
const { ref, inView } = useInView();
@@ -292,7 +252,7 @@ export default function Links({
if (inView && useData?.fetchNextPage && useData?.hasNextPage) {
useData.fetchNextPage();
}
- }, [useData, inView]);
+ }, [useData?.fetchNextPage, useData?.hasNextPage, inView]);
if (layout === ViewMode.List) {
return (
@@ -300,7 +260,6 @@ export default function Links({
links={links}
editMode={editMode}
isLoading={useData?.isLoading}
- placeholders={placeholderCountToArray(placeholderCount)}
hasNextPage={useData?.hasNextPage}
placeHolderRef={ref}
/>
@@ -311,7 +270,6 @@ export default function Links({
links={links}
editMode={editMode}
isLoading={useData?.isLoading}
- placeholders={placeholderCountToArray(placeholderCount)}
hasNextPage={useData?.hasNextPage}
placeHolderRef={ref}
/>
@@ -323,13 +281,9 @@ export default function Links({
links={links}
editMode={editMode}
isLoading={useData?.isLoading}
- placeholders={placeholderCountToArray(placeholderCount)}
hasNextPage={useData?.hasNextPage}
placeHolderRef={ref}
/>
);
}
}
-
-const placeholderCountToArray = (num?: number) =>
- num ? Array.from({ length: num }, (_, i) => i + 1) : [];
diff --git a/apps/web/pages/collections/[id].tsx b/apps/web/pages/collections/[id].tsx
index 87bba518..3a7bfa80 100644
--- a/apps/web/pages/collections/[id].tsx
+++ b/apps/web/pages/collections/[id].tsx
@@ -370,7 +370,6 @@ export default function Index() {
editMode={editMode}
links={links}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>
{!data.isLoading && links && !links[0] && <NoLinksFound />}
diff --git a/apps/web/pages/links/index.tsx b/apps/web/pages/links/index.tsx
index 23791286..cacadead 100644
--- a/apps/web/pages/links/index.tsx
+++ b/apps/web/pages/links/index.tsx
@@ -77,7 +77,6 @@ export default function Index() {
editMode={editMode}
links={links}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>
</div>
diff --git a/apps/web/pages/links/pinned.tsx b/apps/web/pages/links/pinned.tsx
index 6f8a8f3d..2ca0ecfe 100644
--- a/apps/web/pages/links/pinned.tsx
+++ b/apps/web/pages/links/pinned.tsx
@@ -82,7 +82,6 @@ export default function PinnedLinks() {
editMode={editMode}
links={links}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>
</div>
diff --git a/apps/web/pages/public/collections/[id]/index.tsx b/apps/web/pages/public/collections/[id]/index.tsx
index 107768d5..f3fdf27c 100644
--- a/apps/web/pages/public/collections/[id]/index.tsx
+++ b/apps/web/pages/public/collections/[id]/index.tsx
@@ -306,7 +306,6 @@ export default function PublicCollections() {
}) as any
}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>
{!data.isLoading && links && !links[0] && (
diff --git a/apps/web/pages/search.tsx b/apps/web/pages/search.tsx
index c6030d5d..fdfea68f 100644
--- a/apps/web/pages/search.tsx
+++ b/apps/web/pages/search.tsx
@@ -66,7 +66,6 @@ export default function Search() {
editMode={editMode}
links={links}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>
</div>
diff --git a/apps/web/pages/tags/[id].tsx b/apps/web/pages/tags/[id].tsx
index 4b6844b8..8e9fae2b 100644
--- a/apps/web/pages/tags/[id].tsx
+++ b/apps/web/pages/tags/[id].tsx
@@ -233,7 +233,6 @@ export default function Index() {
editMode={editMode}
links={links}
layout={viewMode}
- placeholderCount={1}
useData={data}
/>