@@ -3,7 +3,7 @@ import { getEventCoordinates } from '@dnd-kit/utilities';
33import { useModal } from '@gouvfr-lasuite/cunningham-react' ;
44import { TreeViewMoveModeEnum } from '@gouvfr-lasuite/ui-kit' ;
55import { useQueryClient } from '@tanstack/react-query' ;
6- import { useMemo , useRef } from 'react' ;
6+ import { useEffect , useMemo , useRef , useState } from 'react' ;
77import { Trans , useTranslation } from 'react-i18next' ;
88
99import { AlertModal , Card , Text } from '@/components' ;
@@ -15,6 +15,7 @@ import {
1515 useDeleteDocInvitation ,
1616} from '@/docs/doc-share' ;
1717import { useMoveDoc } from '@/docs/doc-tree' ;
18+ import { useResponsiveStore } from '@/stores/useResponsiveStore' ;
1819
1920import { DocDragEndData , useDragAndDrop } from '../hooks/useDragAndDrop' ;
2021
@@ -151,9 +152,24 @@ export const DraggableDocGridContentList = ({
151152 const cannotMoveDoc =
152153 ! canDrag || ( canDrop !== undefined && ! canDrop ) || isError ;
153154
154- if ( docs . length === 0 ) {
155- return null ;
156- }
155+ const [ isDraggableDisabled , setIsDraggableDisabled ] = useState ( false ) ;
156+
157+ useEffect ( ( ) => {
158+ const checkModal = ( ) => {
159+ const modalOpen = document . querySelector ( '[role="dialog"]' ) ;
160+ setIsDraggableDisabled ( ! ! modalOpen ) ;
161+ } ;
162+
163+ checkModal ( ) ;
164+
165+ const observer = new MutationObserver ( checkModal ) ;
166+ observer . observe ( document . body , {
167+ childList : true ,
168+ subtree : true ,
169+ } ) ;
170+
171+ return ( ) => observer . disconnect ( ) ;
172+ } , [ ] ) ;
157173
158174 return (
159175 < >
@@ -170,6 +186,7 @@ export const DraggableDocGridContentList = ({
170186 dragMode = { ! ! selectedDoc }
171187 canDrag = { ! ! canDrag }
172188 updateCanDrop = { updateCanDrop }
189+ disabled = { isDraggableDisabled }
173190 />
174191 ) ) }
175192 < DragOverlay dropAnimation = { null } >
@@ -216,13 +233,15 @@ export const DraggableDocGridContentList = ({
216233} ;
217234
218235interface DraggableDocGridItemProps {
236+ disabled : boolean ;
219237 doc : Doc ;
220238 dragMode : boolean ;
221239 canDrag : boolean ;
222240 updateCanDrop : ( canDrop : boolean , isOver : boolean ) => void ;
223241}
224242
225243export const DraggableDocGridItem = ( {
244+ disabled,
226245 doc,
227246 dragMode,
228247 canDrag,
@@ -238,18 +257,24 @@ export const DraggableDocGridItem = ({
238257 id = { doc . id }
239258 data = { doc }
240259 >
241- < Draggable id = { doc . id } data = { doc } >
260+ < Draggable id = { doc . id } data = { doc } disabled = { disabled } >
242261 < DocsGridItem dragMode = { dragMode } doc = { doc } />
243262 </ Draggable >
244263 </ Droppable >
245264 ) ;
246265} ;
247266
248267export const DocGridContentList = ( { docs } : DocGridContentListProps ) => {
268+ const { isDesktop } = useResponsiveStore ( ) ;
269+
249270 if ( docs . length === 0 ) {
250271 return null ;
251272 }
252273
274+ if ( isDesktop ) {
275+ return < DraggableDocGridContentList docs = { docs } /> ;
276+ }
277+
253278 return docs . map ( ( doc ) => (
254279 < DocsGridItem dragMode = { false } doc = { doc } key = { doc . id } />
255280 ) ) ;
0 commit comments