mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-10-30 17:38:40 +00:00 
			
		
		
		
	chore: dnd reordering
This commit is contained in:
		
							parent
							
								
									745ee264c8
								
							
						
					
					
						commit
						d60c39d483
					
				| @ -4,7 +4,7 @@ import { BoardBlock } from './BoardBlock'; | |||||||
| import { NewBoardBlock } from './NewBoardBlock'; | import { NewBoardBlock } from './NewBoardBlock'; | ||||||
| import { useDatabase } from '../_shared/database-hooks/useDatabase'; | import { useDatabase } from '../_shared/database-hooks/useDatabase'; | ||||||
| import { ViewLayoutTypePB } from '@/services/backend'; | import { ViewLayoutTypePB } from '@/services/backend'; | ||||||
| import { DragDropContext, Droppable } from 'react-beautiful-dnd'; | import { DragDropContext } from 'react-beautiful-dnd'; | ||||||
| 
 | 
 | ||||||
| export const Board = ({ viewId }: { viewId: string }) => { | export const Board = ({ viewId }: { viewId: string }) => { | ||||||
|   const { controller, rows, groups, onNewRowClick, onDragEnd } = useDatabase(viewId, ViewLayoutTypePB.Board); |   const { controller, rows, groups, onNewRowClick, onDragEnd } = useDatabase(viewId, ViewLayoutTypePB.Board); | ||||||
| @ -29,10 +29,8 @@ export const Board = ({ viewId }: { viewId: string }) => { | |||||||
|             {controller && |             {controller && | ||||||
|               groups && |               groups && | ||||||
|               groups.map((group, index) => ( |               groups.map((group, index) => ( | ||||||
|                 <Droppable droppableId={group.groupId} key={index}> |  | ||||||
|                   {(provided, snapshot) => ( |  | ||||||
|                     <div className={'h-full'} {...provided.droppableProps} ref={provided.innerRef}> |  | ||||||
|                 <BoardBlock |                 <BoardBlock | ||||||
|  |                   groupId={group.groupId} | ||||||
|                   key={index} |                   key={index} | ||||||
|                   viewId={viewId} |                   viewId={viewId} | ||||||
|                   controller={controller} |                   controller={controller} | ||||||
| @ -41,9 +39,6 @@ export const Board = ({ viewId }: { viewId: string }) => { | |||||||
|                   allRows={rows} |                   allRows={rows} | ||||||
|                   onNewRowClick={() => onNewRowClick(index)} |                   onNewRowClick={() => onNewRowClick(index)} | ||||||
|                 /> |                 /> | ||||||
|                     </div> |  | ||||||
|                   )} |  | ||||||
|                 </Droppable> |  | ||||||
|               ))} |               ))} | ||||||
|             <NewBoardBlock onClick={() => console.log('new block')}></NewBoardBlock> |             <NewBoardBlock onClick={() => console.log('new block')}></NewBoardBlock> | ||||||
|           </div> |           </div> | ||||||
|  | |||||||
| @ -4,9 +4,10 @@ import { BoardCard } from './BoardCard'; | |||||||
| import { RowInfo } from '../../stores/effects/database/row/row_cache'; | import { RowInfo } from '../../stores/effects/database/row/row_cache'; | ||||||
| import { DatabaseController } from '../../stores/effects/database/database_controller'; | import { DatabaseController } from '../../stores/effects/database/database_controller'; | ||||||
| import { RowPB } from '@/services/backend'; | import { RowPB } from '@/services/backend'; | ||||||
| import { Draggable } from 'react-beautiful-dnd'; | import { Droppable } from 'react-beautiful-dnd'; | ||||||
| 
 | 
 | ||||||
| export const BoardBlock = ({ | export const BoardBlock = ({ | ||||||
|  |   groupId, | ||||||
|   viewId, |   viewId, | ||||||
|   controller, |   controller, | ||||||
|   title, |   title, | ||||||
| @ -14,6 +15,7 @@ export const BoardBlock = ({ | |||||||
|   allRows, |   allRows, | ||||||
|   onNewRowClick, |   onNewRowClick, | ||||||
| }: { | }: { | ||||||
|  |   groupId: string; | ||||||
|   viewId: string; |   viewId: string; | ||||||
|   controller: DatabaseController; |   controller: DatabaseController; | ||||||
|   title: string; |   title: string; | ||||||
| @ -37,22 +39,24 @@ export const BoardBlock = ({ | |||||||
|           </button> |           </button> | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </div> | ||||||
|       <div className={'flex flex-1 flex-col gap-1 overflow-auto px-2'}> |       <Droppable droppableId={groupId}> | ||||||
|  |         {(provided) => ( | ||||||
|  |           <div | ||||||
|  |             className={'flex flex-1 flex-col gap-1 overflow-auto px-2'} | ||||||
|  |             {...provided.droppableProps} | ||||||
|  |             ref={provided.innerRef} | ||||||
|  |           > | ||||||
|             {rows.map((row_pb, index) => { |             {rows.map((row_pb, index) => { | ||||||
|               const row = allRows.find((r) => r.row.id === row_pb.id); |               const row = allRows.find((r) => r.row.id === row_pb.id); | ||||||
|               return row ? ( |               return row ? ( | ||||||
|             <Draggable draggableId={row_pb.id} index={index} key={index}> |                 <BoardCard viewId={viewId} controller={controller} index={index} key={index} rowInfo={row}></BoardCard> | ||||||
|               {(provided, snapshot) => ( |  | ||||||
|                 <div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}> |  | ||||||
|                   <BoardCard viewId={viewId} controller={controller} key={index} rowInfo={row}></BoardCard> |  | ||||||
|                 </div> |  | ||||||
|               )} |  | ||||||
|             </Draggable> |  | ||||||
|               ) : ( |               ) : ( | ||||||
|                 <span key={index}></span> |                 <span key={index}></span> | ||||||
|               ); |               ); | ||||||
|             })} |             })} | ||||||
|           </div> |           </div> | ||||||
|  |         )} | ||||||
|  |       </Droppable> | ||||||
|       <div className={'p-2'}> |       <div className={'p-2'}> | ||||||
|         <button |         <button | ||||||
|           onClick={onNewRowClick} |           onClick={onNewRowClick} | ||||||
|  | |||||||
| @ -3,12 +3,15 @@ import { RowInfo } from '../../stores/effects/database/row/row_cache'; | |||||||
| import { useRow } from '../_shared/database-hooks/useRow'; | import { useRow } from '../_shared/database-hooks/useRow'; | ||||||
| import { DatabaseController } from '../../stores/effects/database/database_controller'; | import { DatabaseController } from '../../stores/effects/database/database_controller'; | ||||||
| import { BoardCell } from './BoardCell'; | import { BoardCell } from './BoardCell'; | ||||||
|  | import { Draggable } from 'react-beautiful-dnd'; | ||||||
| 
 | 
 | ||||||
| export const BoardCard = ({ | export const BoardCard = ({ | ||||||
|  |   index, | ||||||
|   viewId, |   viewId, | ||||||
|   controller, |   controller, | ||||||
|   rowInfo, |   rowInfo, | ||||||
| }: { | }: { | ||||||
|  |   index: number; | ||||||
|   viewId: string; |   viewId: string; | ||||||
|   controller: DatabaseController; |   controller: DatabaseController; | ||||||
|   rowInfo: RowInfo; |   rowInfo: RowInfo; | ||||||
| @ -16,7 +19,12 @@ export const BoardCard = ({ | |||||||
|   const { cells } = useRow(viewId, controller, rowInfo); |   const { cells } = useRow(viewId, controller, rowInfo); | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|  |     <Draggable draggableId={rowInfo.row.id} index={index}> | ||||||
|  |       {(provided) => ( | ||||||
|         <div |         <div | ||||||
|  |           ref={provided.innerRef} | ||||||
|  |           {...provided.draggableProps} | ||||||
|  |           {...provided.dragHandleProps} | ||||||
|           onClick={() => console.log('on click')} |           onClick={() => console.log('on click')} | ||||||
|           className={`relative cursor-pointer select-none rounded-lg border border-shade-6 bg-white px-3 py-2 transition-transform duration-100 hover:bg-main-selector `} |           className={`relative cursor-pointer select-none rounded-lg border border-shade-6 bg-white px-3 py-2 transition-transform duration-100 hover:bg-main-selector `} | ||||||
|         > |         > | ||||||
| @ -24,9 +32,9 @@ export const BoardCard = ({ | |||||||
|             <Details2Svg></Details2Svg> |             <Details2Svg></Details2Svg> | ||||||
|           </button> |           </button> | ||||||
|           <div className={'flex flex-col gap-3'}> |           <div className={'flex flex-col gap-3'}> | ||||||
|         {cells.map((cell, index) => ( |             {cells.map((cell, cellIndex) => ( | ||||||
|               <BoardCell |               <BoardCell | ||||||
|             key={index} |                 key={cellIndex} | ||||||
|                 cellIdentifier={cell.cellIdentifier} |                 cellIdentifier={cell.cellIdentifier} | ||||||
|                 cellCache={controller.databaseViewCache.getRowCache().getCellCache()} |                 cellCache={controller.databaseViewCache.getRowCache().getCellCache()} | ||||||
|                 fieldController={controller.fieldController} |                 fieldController={controller.fieldController} | ||||||
| @ -34,5 +42,7 @@ export const BoardCard = ({ | |||||||
|             ))} |             ))} | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|  |       )} | ||||||
|  |     </Draggable> | ||||||
|   ); |   ); | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 ascarbek
						ascarbek