⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
fix DnD bug
daniel31x13218fd504bf31
diff --git a/apps/web/components/DashboardLinks.tsx b/apps/web/components/DashboardLinks.tsxindex 18e80290..ac8ad1ef 100644--- a/apps/web/components/DashboardLinks.tsx+++ b/apps/web/components/DashboardLinks.tsx@@ -70,6 +70,7 @@ export function Card({ link, editMode, dashboardType }: Props) {id: `${link.id}-${dashboardType}`,data: {linkId: link.id,+ link,dashboardType,},});diff --git a/apps/web/components/DragNDrop.tsx b/apps/web/components/DragNDrop.tsxindex 89ebea75..9c71a376 100644--- a/apps/web/components/DragNDrop.tsx+++ b/apps/web/components/DragNDrop.tsx@@ -15,9 +15,11 @@ import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import toast from "react-hot-toast";import { useUpdateLink } from "@linkwarden/router/links";import { useTranslation } from "react-i18next";-import { restrictToWindowEdges, snapCenterToCursor } from "@dnd-kit/modifiers";+import { snapCenterToCursor } from "@dnd-kit/modifiers";import { customCollisionDetectionAlgorithm } from "@/lib/utils";-import { useUpdateTag } from "@linkwarden/router/tags";+import usePinLink from "@/lib/client/pinLink";+import { useQueryClient } from "@tanstack/react-query";+import { useUser } from "@linkwarden/router/user";interface DragNDropProps {children: React.ReactNode;@@ -28,7 +30,6 @@ interface DragNDropProps {/*** All links available for drag and drop*/- links: LinkIncludingShortenedCollectionAndTags[];setActiveLink: (link: LinkIncludingShortenedCollectionAndTags | null) => void;/*** Override the default sensors used for drag and drop.@@ -47,14 +48,15 @@ interface DragNDropProps {export default function DragNDrop({children,activeLink,- links,setActiveLink,sensors: sensorProp,onDragEnd: onDragEndProp,}: DragNDropProps) {const { t } = useTranslation();- const updateTag = useUpdateTag();const updateLink = useUpdateLink();+ const pinLink = usePinLink();+ const { data: user } = useUser();+ const queryClient = useQueryClient();const mouseSensor = useSensor(MouseSensor, {// Require the mouse to move by 10 pixels before activatingactivationConstraint: {@@ -72,10 +74,10 @@ export default function DragNDrop({const sensors = useSensors(mouseSensor, touchSensor);const handleDragStart = (event: DragStartEvent) => {- const draggedLink = links.find(- (link: any) => link.id === event.active.data.current?.linkId+ setActiveLink(+ (event.active.data.current+ ?.link as LinkIncludingShortenedCollectionAndTags) ?? null);- setActiveLink(draggedLink || null);};const handleDragOverCancel = () => {@@ -83,70 +85,169 @@ export default function DragNDrop({};const handleDragEnd = async (event: DragEndEvent) => {- // If an onDragEnd prop is provided, use it instead of the default behaviorif (onDragEndProp) {onDragEndProp(event);return;}- const { over } = event;++ const { over, active } = event;if (!over || !activeLink) return;- let updatedLink: LinkIncludingShortenedCollectionAndTags | null = null;+ const overData = over.data.current;+ const targetId = String(over.id);++ const isFromRecentSection = active.data.current?.dashboardType === "recent";- // if the link is dropped over a tag- if (over.data.current?.type === "tag") {- const isTagAlreadyExists = activeLink.tags.some(- (tag) => tag.name === over.data.current?.name+ setActiveLink(null);++ const mutateWithToast = async (+ updatedLink: LinkIncludingShortenedCollectionAndTags,+ opts?: { invalidateDashboardOnError?: boolean }+ ) => {+ const load = toast.loading(t("updating"));+ await updateLink.mutateAsync(updatedLink, {+ onSettled: async (_, error) => {+ toast.dismiss(load);+ if (error) {+ if (+ opts?.invalidateDashboardOnError &&+ typeof queryClient !== "undefined"+ ) {+ await queryClient.invalidateQueries({+ queryKey: ["dashboardData"],+ });+ }+ toast.error(error.message);+ } else {+ toast.success(t("updated"));+ }+ },+ });+ };++ // DROP ON TAG+ if (overData?.type === "tag") {+ const tagName = overData?.name as string | undefined;+ if (!tagName) return;++ const isTagAlreadyExists = activeLink.tags?.some(+ (tag) => tag.name === tagName);if (isTagAlreadyExists) {toast.error(t("tag_already_added"));return;}- // to match the tags structure required to update the link- const allTags: { name: string }[] = activeLink.tags.map((tag) => ({- name: tag.name,- }));- const newTags = [...allTags, { name: over.data.current?.name as string }];- updatedLink = {++ const allTags: { name: string }[] = (activeLink.tags ?? []).map(+ (tag) => ({+ name: tag.name,+ })+ );++ const updatedLink: LinkIncludingShortenedCollectionAndTags = {...activeLink,- tags: newTags as any,+ tags: [...allTags, { name: tagName }] as any,};- } else {- const collectionId = over.data.current?.id as number;- const collectionName = over.data.current?.name as string;- const ownerId = over.data.current?.ownerId as number;- // Immediately hide the drag overlay- setActiveLink(null);+ await mutateWithToast(updatedLink, {+ invalidateDashboardOnError: typeof queryClient !== "undefined",+ });+ return;+ }- // if the link dropped over the same collection, toast- if (activeLink.collection.id === collectionId) {- toast.error(t("link_already_in_collection"));- return;+ // DROP ON DASHBOARD "PINNED" SECTION+ const isPinnedSection = targetId === "pinned-links-section";++ const canPin =+ typeof pinLink === "function" &&+ typeof user !== "undefined" &&+ typeof user?.id !== "undefined";++ if (isPinnedSection && canPin) {+ if (Array.isArray(activeLink.pinnedBy) && !activeLink.pinnedBy.length) {+ if (typeof queryClient !== "undefined") {+ const optimisticallyPinned = {+ ...activeLink,+ pinnedBy: [user!.id],+ };++ queryClient.setQueryData(["dashboardData"], (oldData: any) => {+ if (!oldData?.links) return oldData;+ return {+ ...oldData,+ links: oldData.links.map((l: any) =>+ l.id === optimisticallyPinned.id ? optimisticallyPinned : l+ ),+ };+ });+ }++ pinLink(activeLink);}+ return;+ }- updatedLink = {- ...activeLink,- collection: {- id: collectionId,- name: collectionName,- ownerId,- },- };+ // DROP ON COLLECTION (dashboard + sidebar)+ const collectionId = overData?.id as number | undefined;+ const collectionName = overData?.name as string | undefined;+ const ownerId = overData?.ownerId as number | undefined;++ if (!collectionId || !collectionName || typeof ownerId === "undefined")+ return;++ const isSameCollection = activeLink.collection?.id === collectionId;+ if (isSameCollection) {+ if (isFromRecentSection) toast.error(t("link_already_in_collection"));+ return;}- const load = toast.loading(t("updating"));- await updateLink.mutateAsync(updatedLink, {- onSettled: (_, error) => {- toast.dismiss(load);- if (error) {- toast.error(error.message);- } else {- toast.success(t("updated"));- }+ const updatedLink: LinkIncludingShortenedCollectionAndTags = {+ ...activeLink,+ collection: {+ id: collectionId,+ name: collectionName,+ ownerId,},+ };++ if (typeof queryClient !== "undefined") {+ queryClient.setQueryData(["dashboardData"], (oldData: any) => {+ if (!oldData?.links) return oldData;+ return {+ ...oldData,+ links: oldData.links.map((l: any) =>+ l.id === updatedLink.id ? updatedLink : l+ ),+ };+ });++ queryClient.setQueryData(["dashboardData"], (oldData: any) => {+ if (!oldData?.collectionLinks) return oldData;++ const oldCollectionId = activeLink.collection?.id;+ if (!oldCollectionId) return oldData;++ return {+ ...oldData,+ collectionLinks: {+ ...oldData.collectionLinks,+ [oldCollectionId]: (+ oldData.collectionLinks[oldCollectionId] || []+ ).filter((l: any) => l.id !== updatedLink.id),+ [collectionId]: [+ ...(oldData.collectionLinks[collectionId] || []),+ updatedLink,+ ],+ },+ };+ });+ }++ await mutateWithToast(updatedLink, {+ invalidateDashboardOnError: typeof queryClient !== "undefined",});};+return (<DndContextonDragStart={handleDragStart}diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsxindex ea5a4747..7990d83a 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx@@ -54,6 +54,7 @@ function LinkCard({id: link.id?.toString() ?? "",data: {linkId: link.id,+ link,},disabled: disableDraggable,});diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsxindex bb35b5dc..e76ea8fc 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx@@ -48,6 +48,7 @@ function LinkList({id: link.id?.toString() ?? "",data: {linkId: link.id,+ link,},disabled: disableDraggable,});diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsxindex affa4d97..071c6e2c 100644--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx@@ -57,6 +57,7 @@ function LinkMasonry({id: link.id?.toString() ?? "",data: {linkId: link.id,+ link,},disabled: disableDraggable,});diff --git a/apps/web/components/TagListing.tsx b/apps/web/components/TagListing.tsxindex 368f1bdb..ad3ba79c 100644--- a/apps/web/components/TagListing.tsx+++ b/apps/web/components/TagListing.tsx@@ -14,6 +14,9 @@ export default function TagListing({ tags, active }: TagListingProps) {const { active: droppableActive } = useDndContext();const { t } = useTranslation();+ const ctx = useDndContext();+ console.log("DndContext active?", ctx.active);+if (!tags[0]) {return (<divdiff --git a/apps/web/layouts/MainLayout.tsx b/apps/web/layouts/MainLayout.tsxindex 8e423ea0..cda3e13c 100644--- a/apps/web/layouts/MainLayout.tsx+++ b/apps/web/layouts/MainLayout.tsx@@ -3,6 +3,10 @@ import Announcement from "@/components/Announcement";import Sidebar from "@/components/Sidebar";import { ReactNode, useEffect, useState } from "react";import getLatestVersion from "@/lib/client/getLatestVersion";+import { DndContext } from "@dnd-kit/core";+import DragNDrop from "@/components/DragNDrop";+import { useLinks } from "@linkwarden/router/links";+import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";interface Props {children: ReactNode;@@ -40,29 +44,34 @@ export default function MainLayout({ children }: Props) {const toggleAnnouncementBar = () => setShowAnnouncement(!showAnnouncement);const toggleSidebar = () => setSidebarIsCollapsed(!sidebarIsCollapsed);+ const [activeLink, setActiveLink] =+ useState<LinkIncludingShortenedCollectionAndTags | null>(null);+return (- <div className="flex" data-testid="dashboard-wrapper">- {showAnnouncement && (- <Announcement toggleAnnouncementBar={toggleAnnouncementBar} />- )}- <div className="hidden lg:block">- <Sidebar- className={`${sidebarIsCollapsed ? "w-14" : "w-80"}`}- toggleSidebar={toggleSidebar}- sidebarIsCollapsed={sidebarIsCollapsed}- />- </div>+ <DragNDrop activeLink={activeLink} setActiveLink={setActiveLink}>+ <div className="flex" data-testid="dashboard-wrapper">+ {showAnnouncement && (+ <Announcement toggleAnnouncementBar={toggleAnnouncementBar} />+ )}+ <div className="hidden lg:block">+ <Sidebar+ className={`${sidebarIsCollapsed ? "w-14" : "w-80"}`}+ toggleSidebar={toggleSidebar}+ sidebarIsCollapsed={sidebarIsCollapsed}+ />+ </div>- <div- className={`${- sidebarIsCollapsed- ? "lg:w-[calc(100%-56px)]"- : "lg:w-[calc(100%-320px)]"- } w-full sm:pb-0 pb-20 flex flex-col h-screen overflow-y-auto`}- >- <Navbar />- {children}+ <div+ className={`${+ sidebarIsCollapsed+ ? "lg:w-[calc(100%-56px)]"+ : "lg:w-[calc(100%-320px)]"+ } w-full sm:pb-0 pb-20 flex flex-col h-screen overflow-y-auto`}+ >+ <Navbar />+ {children}+ </div></div>- </div>+ </DragNDrop>);}diff --git a/apps/web/pages/collections/[id].tsx b/apps/web/pages/collections/[id].tsxindex bd2d0174..d70c8cc2 100644--- a/apps/web/pages/collections/[id].tsx+++ b/apps/web/pages/collections/[id].tsx@@ -36,7 +36,6 @@ import {} from "@/components/ui/dropdown-menu";import { Button } from "@/components/ui/button";import { Separator } from "@/components/ui/separator";-import DragNDrop from "@/components/DragNDrop";import { NextPageWithLayout } from "../_app";const Page: NextPageWithLayout = () => {@@ -113,263 +112,255 @@ const Page: NextPageWithLayout = () => {);return (- <DragNDrop- links={links}- activeLink={activeLink}- setActiveLink={setActiveLink}+ <div+ className="p-5 flex gap-3 flex-col"+ style={{+ backgroundImage: `linear-gradient(${activeCollection?.color}20 0%, ${+ user?.theme === "dark" ? "#262626" : "#f3f4f6"+ } 13rem, ${user?.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,+ }}>- <div- className="p-5 flex gap-3 flex-col"- style={{- backgroundImage: `linear-gradient(${activeCollection?.color}20 0%, ${- user?.theme === "dark" ? "#262626" : "#f3f4f6"- } 13rem, ${user?.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,- }}- >- {activeCollection && (- <div className="flex gap-3 items-start justify-between">- <div className="flex items-center gap-2">- {activeCollection.icon ? (- <Icon- icon={activeCollection.icon}- size={45}- weight={- (activeCollection.iconWeight || "regular") as IconWeight- }- color={activeCollection.color}- />- ) : (- <i- className="bi-folder-fill text-3xl"- style={{ color: activeCollection.color }}- />- )}-- <p className="sm:text-3xl text-2xl w-full py-1 break-words hyphens-auto font-thin">- {activeCollection?.name}- </p>- </div>+ {activeCollection && (+ <div className="flex gap-3 items-start justify-between">+ <div className="flex items-center gap-2">+ {activeCollection.icon ? (+ <Icon+ icon={activeCollection.icon}+ size={45}+ weight={+ (activeCollection.iconWeight || "regular") as IconWeight+ }+ color={activeCollection.color}+ />+ ) : (+ <i+ className="bi-folder-fill text-3xl"+ style={{ color: activeCollection.color }}+ />+ )}++ <p className="sm:text-3xl text-2xl w-full py-1 break-words hyphens-auto font-thin">+ {activeCollection?.name}+ </p>+ </div>- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button- asChild- variant="ghost"- size="icon"- className="mt-2 text-neutral"- onMouseDown={(e) => e.preventDefault()}- title={t("more")}- >- <i className="bi-three-dots text-xl" />- </Button>- </DropdownMenuTrigger>-- <DropdownMenuContent- sideOffset={4}- align="end"- className="bg-base-200 border border-neutral-content rounded-box p-1"+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ asChild+ variant="ghost"+ size="icon"+ className="mt-2 text-neutral"+ onMouseDown={(e) => e.preventDefault()}+ title={t("more")}>- <DropdownMenuItem- onClick={() => {- for (const link of links) {- if (link.url) window.open(link.url, "_blank");- }- }}- >- <i className="bi-box-arrow-up-right" />- {t("open_all_links")}+ <i className="bi-three-dots text-xl" />+ </Button>+ </DropdownMenuTrigger>++ <DropdownMenuContent+ sideOffset={4}+ align="end"+ className="bg-base-200 border border-neutral-content rounded-box p-1"+ >+ <DropdownMenuItem+ onClick={() => {+ for (const link of links) {+ if (link.url) window.open(link.url, "_blank");+ }+ }}+ >+ <i className="bi-box-arrow-up-right" />+ {t("open_all_links")}+ </DropdownMenuItem>++ {permissions === true && (+ <DropdownMenuItem onClick={() => setEditCollectionModal(true)}>+ <i className="bi-pencil-square" />+ {t("edit_collection_info")}</DropdownMenuItem>+ )}- {permissions === true && (- <DropdownMenuItem- onClick={() => setEditCollectionModal(true)}- >- <i className="bi-pencil-square" />- {t("edit_collection_info")}- </DropdownMenuItem>- )}-- <DropdownMenuItem- onClick={() => setEditCollectionSharingModal(true)}- >- <i className="bi-globe" />- {permissions === true- ? t("share_and_collaborate")- : t("view_team")}+ <DropdownMenuItem+ onClick={() => setEditCollectionSharingModal(true)}+ >+ <i className="bi-globe" />+ {permissions === true+ ? t("share_and_collaborate")+ : t("view_team")}+ </DropdownMenuItem>++ {permissions === true && (+ <DropdownMenuItem onClick={() => setNewCollectionModal(true)}>+ <i className="bi-folder-plus" />+ {t("create_subcollection")}</DropdownMenuItem>+ )}- {permissions === true && (- <DropdownMenuItem onClick={() => setNewCollectionModal(true)}>- <i className="bi-folder-plus" />- {t("create_subcollection")}- </DropdownMenuItem>- )}-- <DropdownMenuSeparator />-- <DropdownMenuItem- onClick={() => setDeleteCollectionModal(true)}- className="text-error"- >- {permissions === true ? (- <>- <i className="bi-trash" />- {t("delete_collection")}- </>- ) : (- <>- <i className="bi-box-arrow-left" />- {t("leave_collection")}- </>- )}- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- </div>- )}+ <DropdownMenuSeparator />- {activeCollection && (- <div className="min-w-[15rem]">- <div className="flex gap-1 justify-center sm:justify-end items-center w-fit">- <div- className="flex items-center px-1 py-1 rounded-full cursor-pointer hover:bg-base-content/20 transition-colors duration-200"- onClick={() => setEditCollectionSharingModal(true)}+ <DropdownMenuItem+ onClick={() => setDeleteCollectionModal(true)}+ className="text-error">- {collectionOwner.id && (- <ProfilePhoto- src={collectionOwner.image || undefined}- name={collectionOwner.name}- />- )}- {activeCollection.members- .sort((a, b) => (a.userId as number) - (b.userId as number))- .map((e, i) => {- return (- <ProfilePhoto- key={i}- src={e.user.image ? e.user.image : undefined}- name={e.user.name}- className="-ml-3"- />- );- })- .slice(0, 3)}- {activeCollection.members.length - 3 > 0 && (- <div className={`avatar drop-shadow-md placeholder -ml-3`}>- <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">- <span>+{activeCollection.members.length - 3}</span>- </div>- </div>+ {permissions === true ? (+ <>+ <i className="bi-trash" />+ {t("delete_collection")}+ </>+ ) : (+ <>+ <i className="bi-box-arrow-left" />+ {t("leave_collection")}+ </>)}- </div>-- <p className="text-neutral text-sm ml-2">- {activeCollection.members.length > 0- ? activeCollection.members.length === 1- ? t("by_author_and_other", {- author: collectionOwner.name,- count: activeCollection.members.length,- })- : t("by_author_and_others", {- author: collectionOwner.name,- count: activeCollection.members.length,- })- : t("by_author", { author: collectionOwner.name })}- </p>- </div>- </div>- )}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ )}- {activeCollection?.description && <p>{activeCollection.description}</p>}-- <Separator />-- {collections.some((e) => e.parentId === activeCollection?.id) && (- <>- <PageHeader- icon="bi-folder"- title={t("collections")}- description={t(- collections.filter((e) => e.parentId === activeCollection?.id)- .length === 1- ? "showing_count_result"- : "showing_count_results",- {- count: collections.filter(- (e) => e.parentId === activeCollection?.id- ).length,- }+ {activeCollection && (+ <div className="min-w-[15rem]">+ <div className="flex gap-1 justify-center sm:justify-end items-center w-fit">+ <div+ className="flex items-center px-1 py-1 rounded-full cursor-pointer hover:bg-base-content/20 transition-colors duration-200"+ onClick={() => setEditCollectionSharingModal(true)}+ >+ {collectionOwner.id && (+ <ProfilePhoto+ src={collectionOwner.image || undefined}+ name={collectionOwner.name}+ />+ )}+ {activeCollection.members+ .sort((a, b) => (a.userId as number) - (b.userId as number))+ .map((e, i) => {+ return (+ <ProfilePhoto+ key={i}+ src={e.user.image ? e.user.image : undefined}+ name={e.user.name}+ className="-ml-3"+ />+ );+ })+ .slice(0, 3)}+ {activeCollection.members.length - 3 > 0 && (+ <div className={`avatar drop-shadow-md placeholder -ml-3`}>+ <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">+ <span>+{activeCollection.members.length - 3}</span>+ </div>+ </div>)}- className="scale-90 w-fit"- />- <div className="grid 2xl:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">- {collections- .filter((e) => e.parentId === activeCollection?.id)- .map((e) => (- <CollectionCard key={e.id} collection={e} />- ))}</div>- </>- )}- <LinkListOptions- t={t}- viewMode={viewMode}- setViewMode={setViewMode}- sortBy={sortBy}- setSortBy={setSortBy}- editMode={- permissions === true ||- permissions?.canUpdate ||- permissions?.canDelete- ? editMode- : undefined- }- setEditMode={- permissions === true ||- permissions?.canUpdate ||- permissions?.canDelete- ? setEditMode- : undefined- }- links={links}- >- {collections.some((e) => e.parentId === activeCollection?.id) ? (- <PageHeader- icon={"bi-link-45deg"}- title={t("links")}- description={- activeCollection?._count?.links === 1- ? t("showing_count_result", {- count: activeCollection?._count?.links,+ <p className="text-neutral text-sm ml-2">+ {activeCollection.members.length > 0+ ? activeCollection.members.length === 1+ ? t("by_author_and_other", {+ author: collectionOwner.name,+ count: activeCollection.members.length,})- : t("showing_count_results", {- count: activeCollection?._count?.links,+ : t("by_author_and_others", {+ author: collectionOwner.name,+ count: activeCollection.members.length,})+ : t("by_author", { author: collectionOwner.name })}+ </p>+ </div>+ </div>+ )}++ {activeCollection?.description && <p>{activeCollection.description}</p>}++ <Separator />++ {collections.some((e) => e.parentId === activeCollection?.id) && (+ <>+ <PageHeader+ icon="bi-folder"+ title={t("collections")}+ description={t(+ collections.filter((e) => e.parentId === activeCollection?.id)+ .length === 1+ ? "showing_count_result"+ : "showing_count_results",+ {+ count: collections.filter(+ (e) => e.parentId === activeCollection?.id+ ).length,}- className="scale-90 w-fit"- />- ) : (- <p>- {activeCollection?._count?.links === 1+ )}+ className="scale-90 w-fit"+ />+ <div className="grid 2xl:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">+ {collections+ .filter((e) => e.parentId === activeCollection?.id)+ .map((e) => (+ <CollectionCard key={e.id} collection={e} />+ ))}+ </div>+ </>+ )}++ <LinkListOptions+ t={t}+ viewMode={viewMode}+ setViewMode={setViewMode}+ sortBy={sortBy}+ setSortBy={setSortBy}+ editMode={+ permissions === true ||+ permissions?.canUpdate ||+ permissions?.canDelete+ ? editMode+ : undefined+ }+ setEditMode={+ permissions === true ||+ permissions?.canUpdate ||+ permissions?.canDelete+ ? setEditMode+ : undefined+ }+ links={links}+ >+ {collections.some((e) => e.parentId === activeCollection?.id) ? (+ <PageHeader+ icon={"bi-link-45deg"}+ title={t("links")}+ description={+ activeCollection?._count?.links === 1? t("showing_count_result", {count: activeCollection?._count?.links,}): t("showing_count_results", {count: activeCollection?._count?.links,- })}- </p>- )}- </LinkListOptions>-- <Links- editMode={editMode}- links={links}- layout={viewMode}- useData={data}- />- {!data.isLoading && links && !links[0] && <NoLinksFound />}- </div>+ })+ }+ className="scale-90 w-fit"+ />+ ) : (+ <p>+ {activeCollection?._count?.links === 1+ ? t("showing_count_result", {+ count: activeCollection?._count?.links,+ })+ : t("showing_count_results", {+ count: activeCollection?._count?.links,+ })}+ </p>+ )}+ </LinkListOptions>++ <Links+ editMode={editMode}+ links={links}+ layout={viewMode}+ useData={data}+ />+ {!data.isLoading && links && !links[0] && <NoLinksFound />}{activeCollection && (<>{editCollectionModal && (@@ -398,7 +389,7 @@ const Page: NextPageWithLayout = () => {)}</>)}- </DragNDrop>+ </div>);};diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsxindex 3cb49c2b..9d4dc741 100644--- a/apps/web/pages/dashboard.tsx+++ b/apps/web/pages/dashboard.tsx@@ -46,19 +46,8 @@ const Page: NextPageWithLayout = () => {...dashboardData} = useDashboardData();- /**- * Get a combined list of all links, including those from collections.- * Dupplications are fine since this is used for finding dragged link- */- const allLinks = useMemo(() => {- const _collectionLinks = Object.values(collectionLinks).flat();- return [...links, ..._collectionLinks];- }, [collectionLinks, links]);-const { data: tags = [] } = useTags();const { data: user } = useUser();- const pinLink = usePinLink();- const queryClient = useQueryClient();const [numberOfLinks, setNumberOfLinks] = useState(0);const [activeLink, setActiveLink] =@@ -149,145 +138,8 @@ const Page: NextPageWithLayout = () => {);};- const handleDragEnd = async (event: DragEndEvent) => {- const { over, active } = event;- if (!over || !activeLink) return;-- const targetSectionId = over.id as string;- const collectionId = over.data.current?.id as number;- const collectionName = over.data.current?.name as string;- const ownerId = over.data.current?.ownerId as number;-- const isFromRecentSection = active.data.current?.dashboardType === "recent";-- // Immediately hide the drag overlay- setActiveLink(null);- if (over.data.current?.type === "tag") {- const isTagAlreadyExists = activeLink.tags.some(- (tag) => tag.name === over.data.current?.name- );- if (isTagAlreadyExists) {- toast.error(t("tag_already_added"));- return;- }- // to match the tags structure required to update the link- const allTags: { name: string }[] = activeLink.tags.map((tag) => ({- name: tag.name,- }));- const newTags = [...allTags, { name: over.data.current?.name as string }];- const updatedLink = {- ...activeLink,- tags: newTags as any,- };- const load = toast.loading(t("updating"));- await updateLink.mutateAsync(updatedLink, {- onSettled: (_, error) => {- toast.dismiss(load);- if (error) {- // If there's an error, invalidate queries to restore the original state- queryClient.invalidateQueries({ queryKey: ["dashboardData"] });- toast.error(error.message);- } else {- toast.success(t("updated"));- }- },- });- return;- }-- // Handle pinning the link- if (targetSectionId === "pinned-links-section") {- if (Array.isArray(activeLink.pinnedBy) && !activeLink.pinnedBy.length) {- // optimistically update the link's pinned state- const updatedLink = {- ...activeLink,- pinnedBy: [user?.id],- };- queryClient.setQueryData(["dashboardData"], (oldData: any) => {- if (!oldData?.links) return oldData;- return {- ...oldData,- links: oldData.links.map((link: any) =>- link.id === updatedLink.id ? updatedLink : link- ),- };- });- pinLink(activeLink);- }- // Handle moving the link to a different collection- } else if (activeLink.collection.id !== collectionId) {- // Optimistically update the link's collection immediately- const updatedLink: LinkIncludingShortenedCollectionAndTags = {- ...activeLink,- collection: {- id: collectionId,- name: collectionName,- ownerId,- },- };-- // Optimistically update the dashboard data cache- queryClient.setQueryData(["dashboardData"], (oldData: any) => {- if (!oldData?.links) return oldData;- return {- ...oldData,- links: oldData.links.map((link: any) =>- link.id === updatedLink.id ? updatedLink : link- ),- };- });-- // Optimistically update the collection links cache- if (collectionId) {- queryClient.setQueryData(["dashboardData"], (oldData: any) => {- if (!oldData?.collectionLinks) return oldData;-- const oldCollectionId = activeLink.collection.id!;-- return {- ...oldData,- collectionLinks: {- ...oldData.collectionLinks,- // Remove from old collection- [oldCollectionId]: (- oldData.collectionLinks[oldCollectionId] || []- ).filter((link: any) => link.id !== updatedLink.id),- // Add to new collection- [collectionId]: [- ...(oldData.collectionLinks[collectionId] || []),- updatedLink,- ],- },- };- });- }-- const load = toast.loading(t("updating"));- await updateLink.mutateAsync(updatedLink, {- onSettled: (_, error) => {- toast.dismiss(load);- if (error) {- // If there's an error, invalidate queries to restore the original state- queryClient.invalidateQueries({ queryKey: ["dashboardData"] });- toast.error(error.message);- } else {- toast.success(t("updated"));- }- },- });- } else if (isFromRecentSection) {- // show error if link is dragged from recent section to the target collection which it already belongs to- toast.error(t("link_already_in_collection"));- }- };-return (- <DragNDrop- onDragEnd={handleDragEnd}- links={allLinks}- activeLink={activeLink}- setActiveLink={setActiveLink}- >+ <><div className="p-5 flex flex-col gap-4"><div className="flex items-center justify-between"><div className="flex items-center gap-2">@@ -350,7 +202,7 @@ const Page: NextPageWithLayout = () => {/>)}{newLinkModal && <NewLinkModal onClose={() => setNewLinkModal(false)} />}- </DragNDrop>+ </>);};diff --git a/apps/web/pages/links/index.tsx b/apps/web/pages/links/index.tsxindex 8f79b178..802f3e0c 100644--- a/apps/web/pages/links/index.tsx+++ b/apps/web/pages/links/index.tsx@@ -2,23 +2,16 @@ import NoLinksFound from "@/components/NoLinksFound";import { useLinks } from "@linkwarden/router/links";import MainLayout from "@/layouts/MainLayout";import React, { ReactElement, useEffect, useState } from "react";-import {- LinkIncludingShortenedCollectionAndTags,- Sort,- ViewMode,-} from "@linkwarden/types";+import { Sort, ViewMode } from "@linkwarden/types";import { useRouter } from "next/router";import LinkListOptions from "@/components/LinkListOptions";import getServerSideProps from "@/lib/client/getServerSideProps";import { useTranslation } from "next-i18next";import Links from "@/components/LinkViews/Links";import clsx from "clsx";-import DragNDrop from "@/components/DragNDrop";import { NextPageWithLayout } from "../_app";const Page: NextPageWithLayout = () => {- const [activeLink, setActiveLink] =- useState<LinkIncludingShortenedCollectionAndTags | null>(null);const { t } = useTranslation();const [viewMode, setViewMode] = useState<ViewMode>(@@ -41,44 +34,36 @@ const Page: NextPageWithLayout = () => {}, [router]);return (- <DragNDrop- links={links}- activeLink={activeLink}- setActiveLink={setActiveLink}- >- <div className="p-5 flex flex-col gap-5 w-full h-full">- <LinkListOptions- t={t}- viewMode={viewMode}- setViewMode={setViewMode}- sortBy={sortBy}- setSortBy={setSortBy}- editMode={editMode}- setEditMode={setEditMode}- links={links}- >- <div className={clsx("flex items-center gap-3")}>- <i- className={`bi-link-45deg text-primary text-3xl drop-shadow`}- ></i>- <div>- <p className="text-2xl capitalize font-thin">{t("all_links")}</p>- <p className="text-xs sm:text-sm">{t("all_links_desc")}</p>- </div>+ <div className="p-5 flex flex-col gap-5 w-full h-full">+ <LinkListOptions+ t={t}+ viewMode={viewMode}+ setViewMode={setViewMode}+ sortBy={sortBy}+ setSortBy={setSortBy}+ editMode={editMode}+ setEditMode={setEditMode}+ links={links}+ >+ <div className={clsx("flex items-center gap-3")}>+ <i className={`bi-link-45deg text-primary text-3xl drop-shadow`}></i>+ <div>+ <p className="text-2xl capitalize font-thin">{t("all_links")}</p>+ <p className="text-xs sm:text-sm">{t("all_links_desc")}</p></div>- </LinkListOptions>+ </div>+ </LinkListOptions>- {!data.isLoading && links && !links[0] && (- <NoLinksFound text={t("you_have_not_added_any_links")} />- )}- <Links- editMode={editMode}- links={links}- layout={viewMode}- useData={data}- />- </div>- </DragNDrop>+ {!data.isLoading && links && !links[0] && (+ <NoLinksFound text={t("you_have_not_added_any_links")} />+ )}+ <Links+ editMode={editMode}+ links={links}+ layout={viewMode}+ useData={data}+ />+ </div>);};diff --git a/apps/web/pages/links/pinned.tsx b/apps/web/pages/links/pinned.tsxindex 0cfb4d10..18eecdbb 100644--- a/apps/web/pages/links/pinned.tsx+++ b/apps/web/pages/links/pinned.tsx@@ -1,17 +1,12 @@import MainLayout from "@/layouts/MainLayout";import React, { ReactElement, useState } from "react";import PageHeader from "@/components/PageHeader";-import {- LinkIncludingShortenedCollectionAndTags,- Sort,- ViewMode,-} from "@linkwarden/types";+import { Sort, ViewMode } from "@linkwarden/types";import { useTranslation } from "next-i18next";import getServerSideProps from "@/lib/client/getServerSideProps";import LinkListOptions from "@/components/LinkListOptions";import { useLinks } from "@linkwarden/router/links";import Links from "@/components/LinkViews/Links";-import DragNDrop from "@/components/DragNDrop";import { NextPageWithLayout } from "../_app";const Page: NextPageWithLayout = () => {@@ -29,63 +24,53 @@ const Page: NextPageWithLayout = () => {pinnedOnly: true,});- const [activeLink, setActiveLink] =- useState<LinkIncludingShortenedCollectionAndTags | null>(null);const [editMode, setEditMode] = useState(false);return (- <DragNDrop- links={links}- activeLink={activeLink}- setActiveLink={setActiveLink}- >- <div className="p-5 flex flex-col gap-5 w-full h-full">- <LinkListOptions- t={t}- viewMode={viewMode}- setViewMode={setViewMode}- sortBy={sortBy}- setSortBy={setSortBy}- editMode={editMode}- setEditMode={setEditMode}- links={links}- >- <PageHeader- icon={"bi-pin-angle"}- title={t("pinned")}- description={t("pinned_links_desc")}- />- </LinkListOptions>+ <div className="p-5 flex flex-col gap-5 w-full h-full">+ <LinkListOptions+ t={t}+ viewMode={viewMode}+ setViewMode={setViewMode}+ sortBy={sortBy}+ setSortBy={setSortBy}+ editMode={editMode}+ setEditMode={setEditMode}+ links={links}+ >+ <PageHeader+ icon={"bi-pin-angle"}+ title={t("pinned")}+ description={t("pinned_links_desc")}+ />+ </LinkListOptions>- {!data.isLoading && links && !links[0] && (- <div- style={{ flex: "1 1 auto" }}- className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"+ {!data.isLoading && links && !links[0] && (+ <div+ style={{ flex: "1 1 auto" }}+ className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"+ >+ <svg+ xmlns="http://www.w3.org/2000/svg"+ className="w-1/4 min-w-[7rem] max-w-[15rem] h-auto mx-auto mb-5 text-primary drop-shadow"+ fill="currentColor"+ viewBox="0 0 16 16">- <svg- xmlns="http://www.w3.org/2000/svg"- className="w-1/4 min-w-[7rem] max-w-[15rem] h-auto mx-auto mb-5 text-primary drop-shadow"- fill="currentColor"- viewBox="0 0 16 16"- >- <path d="M4.146.146A.5.5 0 0 1 4.5 0h7a.5.5 0 0 1 .5.5c0 .68-.342 1.174-.646 1.479-.126.125-.25.224-.354.298v4.431l.078.048c.203.127.476.314.751.555C12.36 7.775 13 8.527 13 9.5a.5.5 0 0 1-.5.5h-4v4.5c0 .276-.224 1.5-.5 1.5s-.5-1.224-.5-1.5V10h-4a.5.5 0 0 1-.5-.5c0-.973.64-1.725 1.17-2.189A6 6 0 0 1 5 6.708V2.277a3 3 0 0 1-.354-.298C4.342 1.674 4 1.179 4 .5a.5.5 0 0 1 .146-.354m1.58 1.408-.002-.001zm-.002-.001.002.001A.5.5 0 0 1 6 2v5a.5.5 0 0 1-.276.447h-.002l-.012.007-.054.03a5 5 0 0 0-.827.58c-.318.278-.585.596-.725.936h7.792c-.14-.34-.407-.658-.725-.936a5 5 0 0 0-.881-.61l-.012-.006h-.002A.5.5 0 0 1 10 7V2a.5.5 0 0 1 .295-.458 1.8 1.8 0 0 0 .351-.271c.08-.08.155-.17.214-.271H5.14q.091.15.214.271a1.8 1.8 0 0 0 .37.282" />- </svg>- <p className="text-center text-xl">- {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>- )}- <Links- editMode={editMode}- links={links}- layout={viewMode}- useData={data}- />- </div>- </DragNDrop>+ <path d="M4.146.146A.5.5 0 0 1 4.5 0h7a.5.5 0 0 1 .5.5c0 .68-.342 1.174-.646 1.479-.126.125-.25.224-.354.298v4.431l.078.048c.203.127.476.314.751.555C12.36 7.775 13 8.527 13 9.5a.5.5 0 0 1-.5.5h-4v4.5c0 .276-.224 1.5-.5 1.5s-.5-1.224-.5-1.5V10h-4a.5.5 0 0 1-.5-.5c0-.973.64-1.725 1.17-2.189A6 6 0 0 1 5 6.708V2.277a3 3 0 0 1-.354-.298C4.342 1.674 4 1.179 4 .5a.5.5 0 0 1 .146-.354m1.58 1.408-.002-.001zm-.002-.001.002.001A.5.5 0 0 1 6 2v5a.5.5 0 0 1-.276.447h-.002l-.012.007-.054.03a5 5 0 0 0-.827.58c-.318.278-.585.596-.725.936h7.792c-.14-.34-.407-.658-.725-.936a5 5 0 0 0-.881-.61l-.012-.006h-.002A.5.5 0 0 1 10 7V2a.5.5 0 0 1 .295-.458 1.8 1.8 0 0 0 .351-.271c.08-.08.155-.17.214-.271H5.14q.091.15.214.271a1.8 1.8 0 0 0 .37.282" />+ </svg>+ <p className="text-center text-xl">{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>+ )}+ <Links+ editMode={editMode}+ links={links}+ layout={viewMode}+ useData={data}+ />+ </div>);};diff --git a/apps/web/pages/search.tsx b/apps/web/pages/search.tsxindex 0757fc6e..9ba00d4d 100644--- a/apps/web/pages/search.tsx+++ b/apps/web/pages/search.tsx@@ -12,7 +12,6 @@ import LinkListOptions from "@/components/LinkListOptions";import getServerSideProps from "@/lib/client/getServerSideProps";import { useTranslation } from "next-i18next";import Links from "@/components/LinkViews/Links";-import DragNDrop from "@/components/DragNDrop";import { NextPageWithLayout } from "./_app";const Page: NextPageWithLayout = () => {@@ -42,34 +41,28 @@ const Page: NextPageWithLayout = () => {});return (- <DragNDrop- links={links}- activeLink={activeLink}- setActiveLink={setActiveLink}- >- <div className="p-5 flex flex-col gap-5 w-full h-full">- <LinkListOptions- t={t}- viewMode={viewMode}- setViewMode={setViewMode}- sortBy={sortBy}- setSortBy={setSortBy}- editMode={editMode}- setEditMode={setEditMode}- links={links}- >- <PageHeader icon={"bi-search"} title={t("search_results")} />- </LinkListOptions>+ <div className="p-5 flex flex-col gap-5 w-full h-full">+ <LinkListOptions+ t={t}+ viewMode={viewMode}+ setViewMode={setViewMode}+ sortBy={sortBy}+ setSortBy={setSortBy}+ editMode={editMode}+ setEditMode={setEditMode}+ links={links}+ >+ <PageHeader icon={"bi-search"} title={t("search_results")} />+ </LinkListOptions>- {!data.isLoading && links && !links[0] && <p>{t("nothing_found")}</p>}- <Links- editMode={editMode}- links={links}- layout={viewMode}- useData={data}- />- </div>- </DragNDrop>+ {!data.isLoading && links && !links[0] && <p>{t("nothing_found")}</p>}+ <Links+ editMode={editMode}+ links={links}+ layout={viewMode}+ useData={data}+ />+ </div>);};diff --git a/apps/web/pages/tags/[id].tsx b/apps/web/pages/tags/[id].tsxindex 6abdcbd4..87b46a5b 100644--- a/apps/web/pages/tags/[id].tsx+++ b/apps/web/pages/tags/[id].tsx@@ -24,7 +24,6 @@ import {DropdownMenuItem,DropdownMenuSeparator,} from "@/components/ui/dropdown-menu";-import DragNDrop from "@/components/DragNDrop";import { NextPageWithLayout } from "../_app";const Page: NextPageWithLayout = () => {@@ -146,111 +145,102 @@ const Page: NextPageWithLayout = () => {);return (- <DragNDrop- links={links}- activeLink={activeLink}- setActiveLink={setActiveLink}- >- <div className="p-5 flex flex-col gap-5 w-full h-full">- <LinkListOptions- t={t}- viewMode={viewMode}- setViewMode={setViewMode}- sortBy={sortBy}- setSortBy={setSortBy}- editMode={editMode}- setEditMode={setEditMode}- links={links}- >- <div className="flex gap-3 items-center">- <div className="flex gap-2 items-center font-thin">- <i className="bi-hash text-primary text-3xl" />-- {renameTag ? (- <form onSubmit={submit} className="flex items-center gap-2">- <input- type="text"- autoFocus- className="sm:text-3xl text-xl bg-transparent h-10 w-3/4 outline-none border-b border-b-neutral-content"- value={newTagName}- onChange={(e) => setNewTagName(e.target.value)}- />- <Button variant="ghost" size="icon" onClick={submit}>- <i className="bi-check2 text-neutral text-xl" />- </Button>- <Button variant="ghost" size="icon" onClick={cancelUpdateTag}>- <i className="bi-x text-neutral text-xl" />- </Button>- </form>- ) : (- <>- <p className="sm:text-3xl text-xl">{activeTag?.name}</p>- <div className="relative">- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button variant="ghost" size="icon" title={t("more")}>- <i className="bi-three-dots text-xl text-neutral" />- </Button>- </DropdownMenuTrigger>-- <DropdownMenuContent- sideOffset={4}- align={- activeTag?.name.length && activeTag?.name.length > 8- ? "end"- : "start"- }- className="bg-base-200 border border-neutral-content rounded-box p-1"- >- <DropdownMenuItem onClick={() => setRenameTag(true)}>- <i className="bi-pencil-square" />- {t("rename_tag")}- </DropdownMenuItem>-- <DropdownMenuSeparator />-- <DropdownMenuItem- onClick={remove}- className="text-error"- >- <i className="bi-trash" />- {t("delete_tag")}- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- </div>- </>- )}- </div>- </div>- </LinkListOptions>-- <Links- editMode={editMode}- links={links}- layout={viewMode}- useData={data}- />-- {!data.isLoading && links && !links[0] && (- <div- style={{ flex: "1 1 auto" }}- className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"- >- <p className="text-center text-xl">{t("this_tag_has_no_links")}</p>- <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">- {t("this_tag_has_no_links_desc")}- </p>+ <div className="p-5 flex flex-col gap-5 w-full h-full">+ <LinkListOptions+ t={t}+ viewMode={viewMode}+ setViewMode={setViewMode}+ sortBy={sortBy}+ setSortBy={setSortBy}+ editMode={editMode}+ setEditMode={setEditMode}+ links={links}+ >+ <div className="flex gap-3 items-center">+ <div className="flex gap-2 items-center font-thin">+ <i className="bi-hash text-primary text-3xl" />++ {renameTag ? (+ <form onSubmit={submit} className="flex items-center gap-2">+ <input+ type="text"+ autoFocus+ className="sm:text-3xl text-xl bg-transparent h-10 w-3/4 outline-none border-b border-b-neutral-content"+ value={newTagName}+ onChange={(e) => setNewTagName(e.target.value)}+ />+ <Button variant="ghost" size="icon" onClick={submit}>+ <i className="bi-check2 text-neutral text-xl" />+ </Button>+ <Button variant="ghost" size="icon" onClick={cancelUpdateTag}>+ <i className="bi-x text-neutral text-xl" />+ </Button>+ </form>+ ) : (+ <>+ <p className="sm:text-3xl text-xl">{activeTag?.name}</p>+ <div className="relative">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon" title={t("more")}>+ <i className="bi-three-dots text-xl text-neutral" />+ </Button>+ </DropdownMenuTrigger>++ <DropdownMenuContent+ sideOffset={4}+ align={+ activeTag?.name.length && activeTag?.name.length > 8+ ? "end"+ : "start"+ }+ className="bg-base-200 border border-neutral-content rounded-box p-1"+ >+ <DropdownMenuItem onClick={() => setRenameTag(true)}>+ <i className="bi-pencil-square" />+ {t("rename_tag")}+ </DropdownMenuItem>++ <DropdownMenuSeparator />++ <DropdownMenuItem onClick={remove} className="text-error">+ <i className="bi-trash" />+ {t("delete_tag")}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ </>+ )}</div>- )}- </div>+ </div>+ </LinkListOptions>++ <Links+ editMode={editMode}+ links={links}+ layout={viewMode}+ useData={data}+ />++ {!data.isLoading && links && !links[0] && (+ <div+ style={{ flex: "1 1 auto" }}+ className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"+ >+ <p className="text-center text-xl">{t("this_tag_has_no_links")}</p>+ <p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">+ {t("this_tag_has_no_links_desc")}+ </p>+ </div>+ )}{bulkDeleteLinksModal && (<BulkDeleteLinksModal onClose={() => setBulkDeleteLinksModal(false)} />)}{bulkEditLinksModal && (<BulkEditLinksModal onClose={() => setBulkEditLinksModal(false)} />)}- </DragNDrop>+ </div>);};