@@ -14,7 +14,10 @@ import {
1414} from "@lib/hooks/useMouseAndTouch" ;
1515import useResizeEvent from "@lib/hooks/useResizeEvent" ;
1616import useUrlEventId from "@lib/hooks/useUrlEventId" ;
17- import { generateSelectedArea , getTableIndex } from "@lib/tableHelper" ;
17+ import {
18+ generateSelectedArea ,
19+ getColumnIndexAtTimetable ,
20+ } from "@lib/tableHelper" ;
1821import updateCurrentAttendee from "@lib/updateCurrentAttendee" ;
1922import { FC , useCallback , useRef , useState } from "react" ;
2023
@@ -43,7 +46,7 @@ interface TimeProps {
4346 h : number ;
4447}
4548
46- const initialSelectedArea = { x : 0 , y : 0 , w : 0 , h : 0 } ;
49+ const initialArea = { x : 0 , y : 0 , w : 0 , h : 0 } ;
4750
4851const END_TIME = 24 ;
4952const START_TIME = 8 ;
@@ -68,52 +71,51 @@ const Timetable: FC<ComponentProps> = ({
6871 const isUserReady = useDelay ( 500 , currentAttendee ) ;
6972 const id = useUrlEventId ( ) ;
7073 const containerRef = useRef < HTMLDivElement > ( null ) ;
71- const currentSelectedAreaRef = useRef < TimeProps > ( initialSelectedArea ) ;
72- const initialTableAreaRef = useRef < TimeProps > ( initialSelectedArea ) ;
73- const { startClientX, startClientY, setInit } = useMouseAndTouchStartLocation (
74- {
74+ const currentSelectedAreaRef = useRef < TimeProps > ( initialArea ) ;
75+ const timetableAreaRef = useRef < TimeProps > ( initialArea ) ;
76+ const { startClientX, startClientY, initializeMouseAndTouchStart } =
77+ useMouseAndTouchStartLocation ( {
7578 ref : containerRef ,
7679 skipEvent : ! isUserReady ,
77- }
78- ) ;
80+ } ) ;
7981 const hasNotStartMove = startClientX === 0 && startClientY === 0 ;
80- const currentTableIndex = useRef ( 0 ) ;
81- const { moveClientY, setInitMove } = useMouseAndTouchMoveLocation ( {
82- skipEvent : hasNotStartMove ,
83- } ) ;
82+ const columnIndexOfSelectedAreaRef = useRef ( 0 ) ;
83+ const { moveClientY, initializeMouseAndTouchMove } =
84+ useMouseAndTouchMoveLocation ( {
85+ skipEvent : hasNotStartMove ,
86+ } ) ;
8487
85- const [ initialTableArea , setInitialTableArea ] = useState ( initialSelectedArea ) ;
86- const currentWidth = ( initialTableArea . w - 1 * 6 ) / 7 ;
88+ const [ timetableArea , setTimetableArea ] = useState ( initialArea ) ;
8789
88- currentTableIndex . current = getTableIndex (
89- initialTableArea . w / 7 ,
90+ columnIndexOfSelectedAreaRef . current = getColumnIndexAtTimetable (
91+ timetableArea . w / 7 ,
9092 startClientX
9193 ) ;
9294
9395 currentSelectedAreaRef . current = generateSelectedArea (
9496 hasNotStartMove ,
9597 moveClientY ,
9698 startClientY ,
97- initialTableArea ,
98- startClientX ,
99- currentWidth
99+ timetableArea ,
100+ startClientX
100101 ) ;
102+
101103 const resizeTimeTableHandler = ( ) => {
102104 if ( containerRef . current ) {
103105 const { x, y, width, height } =
104106 containerRef . current . getBoundingClientRect ( ) ;
105- setInitialTableArea ( { x, y, w : width , h : height } ) ;
106- initialTableAreaRef . current = { x, y, w : width , h : height } ;
107+ setTimetableArea ( { x, y, w : width , h : height } ) ;
108+ timetableAreaRef . current = { x, y, w : width , h : height } ;
107109 }
108110 } ;
109111
110112 useResizeEvent ( resizeTimeTableHandler ) ;
111113
112114 const updateAttendeesAndResetSelectedArea = useCallback ( ( ) => {
113115 const resetSelectedArea = ( ) => {
114- setInit ( { clientX : 0 , clientY : 0 } ) ;
115- currentSelectedAreaRef . current = initialSelectedArea ;
116- setInitMove ( { clientX : 0 , clientY : 0 } ) ;
116+ initializeMouseAndTouchStart ( ) ;
117+ initializeMouseAndTouchMove ( ) ;
118+ currentSelectedAreaRef . current = initialArea ;
117119 } ;
118120
119121 const currentSelectedArea = currentSelectedAreaRef . current ;
@@ -124,9 +126,9 @@ const Timetable: FC<ComponentProps> = ({
124126
125127 const selectedDates = getSelectedDatesWithSelectedArea (
126128 currentSelectedArea ,
127- initialTableAreaRef . current ,
129+ timetableAreaRef . current ,
128130 startDate ,
129- currentTableIndex . current ,
131+ columnIndexOfSelectedAreaRef . current ,
130132 currentPageIndex
131133 ) ;
132134
@@ -150,10 +152,10 @@ const Timetable: FC<ComponentProps> = ({
150152 attendees ,
151153 currentAttendee ,
152154 isEraseMode ,
153- setInit ,
154155 startDate ,
155156 currentPageIndex ,
156- setInitMove ,
157+ initializeMouseAndTouchMove ,
158+ initializeMouseAndTouchStart ,
157159 id ,
158160 ] ) ;
159161
@@ -215,7 +217,7 @@ const Timetable: FC<ComponentProps> = ({
215217 />
216218 ) ;
217219 } ) }
218- < TimesWrapper height = { initialTableArea . h } >
220+ < TimesWrapper height = { timetableArea . h } >
219221 { DAY_TIME_ARRAY [ 0 ] . map ( ( hour ) => (
220222 < TimeUnit key = { hour } > { hour } :00</ TimeUnit >
221223 ) ) }
0 commit comments