⚡️⚡️⚡️ 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
refactor custom collision algorithm function
Kha Nguyenc9992591021e
diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.tsindex 9318dac6..a652ca6e 100644--- a/apps/web/lib/utils.ts+++ b/apps/web/lib/utils.ts@@ -1,3 +1,4 @@+import { pointerWithin, rectIntersection } from "@dnd-kit/core";import { clsx, type ClassValue } from "clsx";import { twMerge } from "tailwind-merge";@@ -19,3 +20,21 @@ export function isIphone() {!(window as unknown as { MSStream?: any }).MSStream);}++/**+ *+ * Custom collision detection algorithm for dnd-kit that first checks for pointer collisions+ * and then falls back to rectangle intersections+ */+export function customCollisionDetectionAlgorithm(args: any) {+ // First, let's see if there are any collisions with the pointer+ const pointerCollisions = pointerWithin(args);++ // Collision detection algorithms return an array of collisions+ if (pointerCollisions.length > 0) {+ return pointerCollisions;+ }++ // If there are no collisions with the pointer, return rectangle intersections+ return rectIntersection(args);+}diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsxindex a065478d..b3fbf60b 100644--- a/apps/web/pages/dashboard.tsx+++ b/apps/web/pages/dashboard.tsx@@ -38,15 +38,13 @@ import {MouseSensor,TouchSensor,useSensors,- closestCenter,- pointerWithin,- rectIntersection,} from "@dnd-kit/core";import { restrictToWindowEdges } from "@dnd-kit/modifiers";import Droppable from "@/components/Droppable";import { useUpdateLink } from "@linkwarden/router/links";import usePinLink from "@/lib/client/pinLink";import { useQueryClient } from "@tanstack/react-query";+import { customCollisionDetectionAlgorithm } from "@/lib/utils";export default function Dashboard() {const { t } = useTranslation();@@ -646,18 +644,3 @@ const Section = ({return null;}};--// Custom collision detection algorithm that first checks for pointer collisions-// and then falls back to rectangle intersections-function customCollisionDetectionAlgorithm(args: any) {- // First, let's see if there are any collisions with the pointer- const pointerCollisions = pointerWithin(args);-- // Collision detection algorithms return an array of collisions- if (pointerCollisions.length > 0) {- return pointerCollisions;- }-- // If there are no collisions with the pointer, return rectangle intersections- return rectIntersection(args);-}