11import React from "react" ;
2- import { Box , Menu , MenuItem } from "@mui/material" ;
2+ import { Menu , MenuItem } from "@mui/material" ;
33import { FormatListBulleted as FormatListBulletedIcon , MenuBook as MenuBookIcon , MusicNote as MusicNoteIcon } from "@mui/icons-material" ;
44import { type PlanItemInterface } from "../../helpers" ;
55import { DraggableWrapper } from "../../components/DraggableWrapper" ;
6- import { DroppableWrapper } from "../../components/DroppableWrapper " ;
6+ import { RowDropZone } from "./RowDropZone " ;
77import { type TimeInterface , type PlanItemTimeInterface } from "@churchapps/helpers" ;
88import { ApiHelper , Locale } from "@churchapps/apphelper" ;
99import { SongDialog } from "./SongDialog" ;
1010import { LessonDialog } from "./LessonDialog" ;
11- import { getNextChildSort } from "./planItemUtils" ;
11+ import { getNextChildSort , estimateSeconds , type ProviderMediaInfo } from "./planItemUtils" ;
1212import { ActionDialog } from "./ActionDialog" ;
1313import { ActionSelector } from "./ActionSelector" ;
1414import { PlanItemHeader , PlanItemRow } from "./planItem/index" ;
@@ -29,6 +29,7 @@ interface Props {
2929 exclusions ?: PlanItemTimeInterface [ ] ;
3030 selectedServiceTimeId ?: string ;
3131 excluded ?: boolean ;
32+ mediaLookup ?: Record < string , ProviderMediaInfo > ;
3233}
3334
3435export const PlanItem = React . memo ( ( props : Props ) => {
@@ -123,63 +124,34 @@ export const PlanItem = React.memo((props: Props) => {
123124 props . planItem . children ?. forEach ( ( c , index ) => {
124125 const childStartTime = cumulativeTime ;
125126 const childExcluded = c . itemType !== "header" && isChildExcluded ( c . id || "" ) ;
127+ const childPlanItem = (
128+ < PlanItem key = { c . id } planItem = { c } setEditPlanItem = { props . setEditPlanItem } readOnly = { props . readOnly } showItemDrop = { props . showItemDrop } onDragChange = { props . onDragChange } onChange = { props . onChange } startTime = { childStartTime } associatedContentPath = { props . associatedContentPath } associatedProviderId = { props . associatedProviderId } ministryId = { props . ministryId } serviceTime = { props . serviceTime } exclusions = { props . exclusions } selectedServiceTimeId = { props . selectedServiceTimeId } excluded = { childExcluded } mediaLookup = { props . mediaLookup } />
129+ ) ;
126130 result . push (
127131 < React . Fragment key = { c . id || `child-${ index } ` } >
128- { props . showItemDrop && (
129- < DroppableWrapper
132+ { props . readOnly ? (
133+ childPlanItem
134+ ) : (
135+ < RowDropZone
130136 accept = "planItem"
131- onDrop = { ( item ) => {
132- handleDrop ( item , index + 0.5 ) ;
137+ onDrop = { ( item , position ) => {
138+ handleDrop ( item , index + ( position === "before" ? 0.5 : 1.5 ) ) ;
133139 } } >
134- < Box
135- sx = { {
136- height : "30px" ,
137- border : "2px dashed" ,
138- borderColor : "primary.main" ,
139- borderRadius : 1 ,
140- backgroundColor : "primary.light" ,
141- opacity : 0.3 ,
142- mb : 0.5
143- } }
144- />
145- </ DroppableWrapper >
140+ < DraggableWrapper
141+ dndType = "planItem"
142+ data = { c }
143+ handleClassName = "dragHandle"
144+ draggingCallback = { ( isDragging ) => {
145+ if ( props . onDragChange ) props . onDragChange ( isDragging ) ;
146+ } } >
147+ { childPlanItem }
148+ </ DraggableWrapper >
149+ </ RowDropZone >
146150 ) }
147-
148- < DraggableWrapper
149- dndType = "planItem"
150- data = { c }
151- draggingCallback = { ( isDragging ) => {
152- if ( props . onDragChange ) props . onDragChange ( isDragging ) ;
153- } } >
154- < PlanItem key = { c . id } planItem = { c } setEditPlanItem = { props . setEditPlanItem } readOnly = { props . readOnly } showItemDrop = { props . showItemDrop } onDragChange = { props . onDragChange } onChange = { props . onChange } startTime = { childStartTime } associatedContentPath = { props . associatedContentPath } associatedProviderId = { props . associatedProviderId } ministryId = { props . ministryId } serviceTime = { props . serviceTime } exclusions = { props . exclusions } selectedServiceTimeId = { props . selectedServiceTimeId } excluded = { childExcluded } />
155- </ DraggableWrapper >
156151 </ React . Fragment >
157152 ) ;
158- if ( ! childExcluded ) cumulativeTime += c . seconds || 0 ;
153+ if ( ! childExcluded ) cumulativeTime += estimateSeconds ( c , props . mediaLookup ) ;
159154 } ) ;
160- if ( props . showItemDrop ) {
161- result . push (
162- < React . Fragment key = "trailing-drop-zone" >
163- < DroppableWrapper
164- accept = "planItem"
165- onDrop = { ( item ) => {
166- handleDrop ( item , getNextChildSort ( props . planItem . children ) ) ;
167- } } >
168- < Box
169- sx = { {
170- height : 30 ,
171- border : "2px dashed" ,
172- borderColor : "primary.main" ,
173- borderRadius : 1 ,
174- backgroundColor : "primary.light" ,
175- opacity : 0.3 ,
176- mb : 0.5
177- } }
178- />
179- </ DroppableWrapper >
180- </ React . Fragment >
181- ) ;
182- }
183155 return result ;
184156 } ;
185157
@@ -191,6 +163,16 @@ export const PlanItem = React.memo((props: Props) => {
191163 readOnly = { props . readOnly }
192164 onAddClick = { ( e ) => setAnchorEl ( e . currentTarget ) }
193165 onEditClick = { ( ) => props . setEditPlanItem ( props . planItem ) }
166+ wrapRow = { props . readOnly ? undefined : ( row ) => (
167+ < RowDropZone
168+ accept = "planItem"
169+ mode = "into"
170+ onDrop = { ( item ) => {
171+ handleDrop ( item , 0.5 ) ;
172+ } } >
173+ { row }
174+ </ RowDropZone >
175+ ) }
194176 >
195177 { getChildren ( ) }
196178 </ PlanItemHeader >
@@ -205,6 +187,7 @@ export const PlanItem = React.memo((props: Props) => {
205187 readOnly = { props . readOnly }
206188 onLabelClick = { onLabelClick }
207189 onEditClick = { ( ) => props . setEditPlanItem ( props . planItem ) }
190+ mediaLookup = { props . mediaLookup }
208191 />
209192 ) ;
210193
0 commit comments