Skip to content

Commit 7f186d7

Browse files
committed
refactor: optimize block position calculation in TimeTableClient for better display handling
1 parent f43e2c7 commit 7f186d7

1 file changed

Lines changed: 12 additions & 38 deletions

File tree

  • apps/ticket/src/app/(pages)/event/[eventId]/time-table/_clientBoundary/TimeTableClient

apps/ticket/src/app/(pages)/event/[eventId]/time-table/_clientBoundary/TimeTableClient/index.tsx

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -294,59 +294,33 @@ function calcBlockPosition(
294294
const start = parseCustomDate(block.blockStartDate);
295295
const end = parseCustomDate(block.blockEndDate);
296296

297-
const durationInHours = (end.getTime() - start.getTime()) / (1000 * 60 * 60);
298-
299-
// 타임테이블 시작 시간을 기준으로 계산
300297
if (timeSlots.length === 0) {
301-
const DISABLE_DISPLAY_HEIGHT = -200;
302-
303-
return { top: DISABLE_DISPLAY_HEIGHT, height: durationInHours * hourHeight, left: 0 };
298+
return { top: -9999, height: 0, left: 0 };
304299
}
305300

306301
const tableStartTime = timeSlots[0].datetime.getTime();
307302
const tableEndTime = timeSlots[timeSlots.length - 1].datetime.getTime();
308303
const blockStartTime = start.getTime();
304+
const blockEndTime = end.getTime();
309305

310-
// 블록이 타임테이블 범위 내에 있는지 확인
311-
if (blockStartTime < tableStartTime) {
312-
const DISABLE_DISPLAY_HEIGHT = 0;
313-
const stage = stages.find((a) => a.stageNotionId === block.blockStageNotionId);
314-
const stageSequence = stage ? stage.sequence : 0;
315-
316-
return {
317-
top: DISABLE_DISPLAY_HEIGHT,
318-
height: durationInHours * hourHeight,
319-
left: stageSequence * columnWidth,
320-
};
321-
}
322-
323-
if (tableEndTime < blockStartTime) {
324-
return {
325-
top: -200,
326-
height: 0,
327-
left: 0,
328-
};
306+
// 완전히 범위 밖이면 숨김 처리
307+
if (blockEndTime <= tableStartTime || blockStartTime >= tableEndTime) {
308+
return { top: -9999, height: 0, left: 0 };
329309
}
330310

331-
// 타임테이블 시작 시간부터 블록 시작/종료 시간까지의 차이를 시간 단위로 계산
332-
const blockEndTime = end.getTime();
311+
// 일부만 겹치는 경우는 클리핑
312+
const displayStart = Math.max(blockStartTime, tableStartTime);
313+
const displayEnd = Math.min(blockEndTime, tableEndTime);
333314

334-
const timeDiffStartMs = blockStartTime - tableStartTime;
335-
const timeDiffEndMs = blockEndTime - tableStartTime;
336-
const timeDiffStartInHours = timeDiffStartMs / (1000 * 60 * 60);
337-
const timeDiffEndInHours = timeDiffEndMs / (1000 * 60 * 60);
338-
const startMinutes = start.getMinutes();
339-
const endMinutes = end.getMinutes();
315+
const timeDiffStartInHours = (displayStart - tableStartTime) / (1000 * 60 * 60);
316+
const timeDiffEndInHours = (displayEnd - tableStartTime) / (1000 * 60 * 60);
340317

341318
// 해당 stage의 sequence 찾기
342319
const stage = stages.find((a) => a.stageNotionId === block.blockStageNotionId);
343320
const stageSequence = stage ? stage.sequence : 0;
344321

345-
// top 위치 = 시작 시간 차이(시간) * hourHeight + 시작 분 오프셋
346-
const top = timeDiffStartInHours * hourHeight + (startMinutes / 60) * hourHeight;
347-
// height = 종료 시간 위치 - 시작 시간 위치
348-
const endTop = timeDiffEndInHours * hourHeight + (endMinutes / 60) * hourHeight;
349-
const height = endTop - top;
322+
const top = timeDiffStartInHours * hourHeight;
323+
const height = Math.max((timeDiffEndInHours - timeDiffStartInHours) * hourHeight, 2); // 최소 높이 보장
350324
const left = stageSequence * columnWidth;
351325

352326
return { top, height, left };

0 commit comments

Comments
 (0)