Skip to content

Commit a284707

Browse files
committed
♻️ Refactor: Improve left position calculation for overlapping events
1 parent 43e3bbe commit a284707

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

packages/web/src/common/utils/position.util.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,33 +199,28 @@ export const getPosition = (
199199
};
200200

201201
const getRelativeLeftPosition = (
202-
left: number,
202+
initialLeft: number,
203203
event?: Schema_GridEvent,
204204
isDraft?: boolean
205205
) => {
206206
let adjustment = 0;
207207
const GRID_EVENT_OVERLAPPING_HORIZONTAL_MARGIN = 4;
208208

209-
if (event?.position?.isOverlapping) {
210-
const isFirstEventInRow = event.position.horizontalOrder === 1;
211-
if (!isFirstEventInRow) {
212-
console.log("adding cuz not first in row");
209+
if (!isDraft && event?.position?.isOverlapping) {
210+
const isNotFirstInRow = event.position.horizontalOrder !== 1;
211+
if (isNotFirstInRow) {
213212
adjustment +=
214213
GRID_EVENT_OVERLAPPING_HORIZONTAL_MARGIN *
215214
(event.position.horizontalOrder - 1);
216215
}
217216
}
218217

219-
// if (event?.isAllDay === false) {
220-
// adjustment += GRID_MARGIN_LEFT;
221-
// }
222-
// if (isDraft || event?.isAllDay === false) {
223-
// console.log("adjusting with margin");
224-
// adjustment += GRID_MARGIN_LEFT;
225-
// }
218+
const isTimedEvent = event?.isAllDay === false;
219+
if (isTimedEvent) {
220+
adjustment += GRID_MARGIN_LEFT;
221+
}
226222

227-
const relativeLeft = left + adjustment + GRID_MARGIN_LEFT;
228-
console.log("relativeleft", relativeLeft);
223+
const relativeLeft = initialLeft + adjustment;
229224
return relativeLeft;
230225
};
231226

@@ -262,6 +257,7 @@ export const getLeftPosition = (
262257
eventWidth,
263258
isDraft
264259
);
260+
265261
left = getRelativeLeftPosition(left, event, isDraft);
266262

267263
return left;

0 commit comments

Comments
 (0)