Skip to content

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

show toast when drop a link to collection it already belongs to

Kha Nguyen360eadb08d6c
diff --git a/apps/web/components/DashboardLinks.tsx b/apps/web/components/DashboardLinks.tsx
index aa83106e..a3d50538 100644
--- a/apps/web/components/DashboardLinks.tsx
+++ b/apps/web/components/DashboardLinks.tsx
@@ -27,7 +27,6 @@ import LinkPin from "./LinkViews/LinkComponents/LinkPin";
import { Separator } from "./ui/separator";
import { useDraggable } from "@dnd-kit/core";
import { cn } from "@linkwarden/lib";
-import { GripIcon } from "lucide-react";
export function DashboardLinks({
links,
@@ -69,6 +68,7 @@ export function Card({ link, editMode, dashboardType }: Props) {
id: `${link.id}-${dashboardType}`,
data: {
linkId: link.id,
+ dashboardType,
},
});
const { data: collections = [] } = useCollections();
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index ab469c5a..bf4abd50 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -181,7 +181,7 @@ export default function Dashboard() {
};
const handleDragEnd = async (event: DragEndEvent) => {
- const { over } = event;
+ const { over, active } = event;
if (!over || !activeLink) return;
const targetSectionId = over.id as string;
@@ -189,6 +189,8 @@ export default function Dashboard() {
const ownerId = over.data.current?.ownerId as string;
const collectionName = over.data.current?.collectionName as string;
+ const isFromRecentSection = active.data.current?.dashboardType === "recent";
+
// Find the link in the current data
const linkToMove = links.find((link: any) => link.id === activeLink.id);
@@ -259,6 +261,9 @@ export default function Dashboard() {
}
},
});
+ } 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"));
}
};
@@ -379,7 +384,6 @@ const Section = ({
collectionLinks,
setNewLinkModal,
}: SectionProps) => {
- console.log("links", links);
switch (sectionData.type) {
case DashboardSectionType.STATS:
return (
@@ -506,9 +510,9 @@ const Section = ({
<Droppable
id={collection.id}
data={{
- collectionId: collection?.id,
- collectionName: collection?.name,
- ownerId: collection?.ownerId,
+ collectionId: collection.id,
+ collectionName: collection.name,
+ ownerId: collection.ownerId,
}}
>
<div>
diff --git a/apps/web/public/locales/en/common.json b/apps/web/public/locales/en/common.json
index 8e47e4f1..13b67050 100644
--- a/apps/web/public/locales/en/common.json
+++ b/apps/web/public/locales/en/common.json
@@ -208,6 +208,7 @@
"password_successfully_updated": "Your password has been successfully updated.",
"user_already_member": "User already exists.",
"you_are_already_collection_owner": "You are already the collection owner.",
+ "link_already_in_collection": "Link is already in this collection.",
"date_newest_first": "Date (Newest First)",
"date_oldest_first": "Date (Oldest First)",
"name_az": "Name (A-Z)",