fix(sidebar): restrict folder reorder drag to folder header row
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "react"
|
} from "react"
|
||||||
import { useTranslations } from "next-intl"
|
import { useTranslations } from "next-intl"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { Reorder } from "motion/react"
|
import { Reorder, useDragControls, type DragControls } from "motion/react"
|
||||||
import type { OverlayScrollbarsComponentRef } from "overlayscrollbars-react"
|
import type { OverlayScrollbarsComponentRef } from "overlayscrollbars-react"
|
||||||
import {
|
import {
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
@@ -167,6 +167,7 @@ const FolderHeader = memo(function FolderHeader({
|
|||||||
onManageConversations,
|
onManageConversations,
|
||||||
onChangeColor,
|
onChangeColor,
|
||||||
isDragging,
|
isDragging,
|
||||||
|
dragControls,
|
||||||
t,
|
t,
|
||||||
}: {
|
}: {
|
||||||
folderId: number
|
folderId: number
|
||||||
@@ -182,6 +183,7 @@ const FolderHeader = memo(function FolderHeader({
|
|||||||
onManageConversations: (folderId: number) => void
|
onManageConversations: (folderId: number) => void
|
||||||
onChangeColor: (folderId: number, color: string) => void
|
onChangeColor: (folderId: number, color: string) => void
|
||||||
isDragging?: boolean
|
isDragging?: boolean
|
||||||
|
dragControls: DragControls
|
||||||
t: ReturnType<typeof useTranslations>
|
t: ReturnType<typeof useTranslations>
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
@@ -189,6 +191,10 @@ const FolderHeader = memo(function FolderHeader({
|
|||||||
<ContextMenuTrigger asChild>
|
<ContextMenuTrigger asChild>
|
||||||
<div className={cn("relative h-[2rem]", isDragging && "opacity-60")}>
|
<div className={cn("relative h-[2rem]", isDragging && "opacity-60")}>
|
||||||
<div
|
<div
|
||||||
|
onPointerDown={(e) => {
|
||||||
|
if (e.button !== 0) return
|
||||||
|
dragControls.start(e)
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
"group flex h-[1.9375rem] w-full items-center",
|
"group flex h-[1.9375rem] w-full items-center",
|
||||||
"rounded-full",
|
"rounded-full",
|
||||||
@@ -395,6 +401,7 @@ function FolderGroupItem({
|
|||||||
t,
|
t,
|
||||||
}: FolderGroupItemProps) {
|
}: FolderGroupItemProps) {
|
||||||
const justDraggedRef = useRef(false)
|
const justDraggedRef = useRef(false)
|
||||||
|
const dragControls = useDragControls()
|
||||||
|
|
||||||
const handleToggle = useCallback(
|
const handleToggle = useCallback(
|
||||||
(id: number) => {
|
(id: number) => {
|
||||||
@@ -429,6 +436,8 @@ function FolderGroupItem({
|
|||||||
as="div"
|
as="div"
|
||||||
value={folderId}
|
value={folderId}
|
||||||
drag={reordering ? false : "y"}
|
drag={reordering ? false : "y"}
|
||||||
|
dragListener={false}
|
||||||
|
dragControls={dragControls}
|
||||||
dragMomentum={false}
|
dragMomentum={false}
|
||||||
layout="position"
|
layout="position"
|
||||||
onDragStart={handleDragStart}
|
onDragStart={handleDragStart}
|
||||||
@@ -454,6 +463,7 @@ function FolderGroupItem({
|
|||||||
onManageConversations={onManageConversations}
|
onManageConversations={onManageConversations}
|
||||||
onChangeColor={onChangeColor}
|
onChangeColor={onChangeColor}
|
||||||
isDragging={dragging}
|
isDragging={dragging}
|
||||||
|
dragControls={dragControls}
|
||||||
t={t}
|
t={t}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user