Skip to content

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

disable drag and drop on small screen on links page

Kha Nguyen92a1c4a5f064
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
index 77ff4dba..64793367 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
@@ -31,6 +31,7 @@ import openLink from "@/lib/client/openLink";
import { Separator } from "@/components/ui/separator";
import { useDraggable } from "@dnd-kit/core";
import { cn } from "@/lib/utils";
+import useMediaQuery from "@/hooks/useMediaQuery";
type Props = {
link: LinkIncludingShortenedCollectionAndTags;
@@ -41,11 +42,15 @@ type Props = {
export default function LinkCard({ link, columns, editMode }: Props) {
const { t } = useTranslation();
+
+ // we don't want to use the draggable feature for screen under 1023px since the sidebar is hidden
+ const isSmallScreen = useMediaQuery("(max-width: 1023px)");
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
id: link.id?.toString() ?? "",
data: {
linkId: link.id,
},
+ disabled: isSmallScreen,
});
const heightMap = {
diff --git a/apps/web/hooks/useMediaQuery.tsx b/apps/web/hooks/useMediaQuery.tsx
new file mode 100644
index 00000000..8c24102e
--- /dev/null
+++ b/apps/web/hooks/useMediaQuery.tsx
@@ -0,0 +1,20 @@
+import { useEffect, useState } from "react";
+
+export default function useMediaQuery(query: string): boolean {
+ const [matches, setMatches] = useState<boolean>(false);
+ useEffect(() => {
+ const mediaQueryList = window.matchMedia(query);
+ const handleChange = (event: MediaQueryListEvent) => {
+ setMatches(event.matches);
+ };
+ // Set initial state
+ setMatches(mediaQueryList.matches);
+ // Add listener for changes
+ mediaQueryList.addEventListener("change", handleChange);
+ // Cleanup listener on unmount
+ return () => {
+ mediaQueryList.removeEventListener("change", handleChange);
+ };
+ }, [query]);
+ return matches;
+}