@@ -16,7 +16,7 @@ import { ArcherElement } from 'react-archer';
1616import { v4 as uuidv4 } from 'uuid' ;
1717
1818const CELL_SIZE_PX = 38 + 2 ; // 38px cell + 2px for borders (1px each side)
19- const GAP_SIZE_PX = 10 ; // empirically determined, see note above
19+ const GAP_SIZE_PX = 10 ; // empirically determined, see note above
2020const WIDTH_PER_DAY = 7.2 ; //width per day to use for resizing calculations, kind of arbitrary,
2121
2222interface GanttTaskBarEditProps < T > {
@@ -72,14 +72,11 @@ export const GanttTaskBarEditView = <T,>({
7272 right : '-10'
7373 } ;
7474
75- const getCorrectWidth = useCallback (
76- ( rawWidth : number ) => {
77- const newEventLengthInDays = floorToMultipleOf7 ( rawWidth / WIDTH_PER_DAY ) ;
78- const displayWeeks = newEventLengthInDays / 7 + 1 ;
79- return displayWeeks * CELL_SIZE_PX + ( displayWeeks - 1 ) * GAP_SIZE_PX ;
80- } ,
81- [ ]
82- ) ;
75+ const getCorrectWidth = useCallback ( ( rawWidth : number ) => {
76+ const newEventLengthInDays = floorToMultipleOf7 ( rawWidth / WIDTH_PER_DAY ) ;
77+ const displayWeeks = newEventLengthInDays / 7 + 1 ;
78+ return displayWeeks * CELL_SIZE_PX + ( displayWeeks - 1 ) * GAP_SIZE_PX ;
79+ } , [ ] ) ;
8380
8481 useEffect ( ( ) => {
8582 if ( ! hasMeasuredRef . current && bounds . width > 0 ) {
@@ -101,7 +98,7 @@ export const GanttTaskBarEditView = <T,>({
10198 } ;
10299
103100 const handleMouseDown = ( e : MouseEvent < HTMLElement > ) => {
104- const bar = ( e . currentTarget as HTMLElement ) . closest ( '[data-gantt-bar]' )
101+ const bar = ( e . currentTarget as HTMLElement ) . closest ( '[data-gantt-bar]' ) ;
105102 if ( ! bar ) return ;
106103
107104 boxRef . current = ( e . currentTarget as HTMLElement ) . closest ( '[data-gantt-bar]' ) as HTMLDivElement ;
@@ -118,21 +115,21 @@ export const GanttTaskBarEditView = <T,>({
118115 } ;
119116
120117 const handleMouseUp = ( ) => {
121- if ( isResizing ) {
122- setIsResizing ( false ) ;
123- const newEventLengthInDays = floorToMultipleOf7 ( width / WIDTH_PER_DAY ) ;
124- const displayWeeks = newEventLengthInDays / 7 + 1 ;
125- const correctWidth = displayWeeks * 40 + ( displayWeeks - 1 ) * 10 ;
126- setWidth ( correctWidth ) ;
127- createChange ( {
128- id : uuidv4 ( ) ,
129- element : task . element ,
130- type : 'change-end-date' ,
131- originalEnd : task . end ,
132- newEnd : addDaysToDate ( task . start , newEventLengthInDays )
133- } ) ;
134- }
135- } ;
118+ if ( isResizing ) {
119+ setIsResizing ( false ) ;
120+ const newEventLengthInDays = floorToMultipleOf7 ( width / WIDTH_PER_DAY ) ;
121+ const displayWeeks = newEventLengthInDays / 7 + 1 ;
122+ const correctWidth = displayWeeks * 40 + ( displayWeeks - 1 ) * 10 ;
123+ setWidth ( correctWidth ) ;
124+ createChange ( {
125+ id : uuidv4 ( ) ,
126+ element : task . element ,
127+ type : 'change-end-date' ,
128+ originalEnd : task . end ,
129+ newEnd : addDaysToDate ( task . start , newEventLengthInDays )
130+ } ) ;
131+ }
132+ } ;
136133
137134 const onDragStart = ( ) => {
138135 setShowDropPoints ( true ) ;
0 commit comments