feat: 요일 헤더에 자동 날짜 표시 추가 - #116
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary by CodeRabbit
Walkthrough
Changes요일 날짜 표기 및 파일 검증 수정
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
핵심 지적 사항: 1.
// 위험: 매 렌더마다 다른 값
function formatDayWithDate(dayCode: string): string {
const today = new Date(); // ← 렌더 시점 종속
...
}
const [referenceDate, setReferenceDate] = useState<Date | null>(null);
useEffect(() => { setReferenceDate(new Date()); }, []);
// formatDayWithDate에 referenceDate를 인자로 주입
function formatDayWithDate(dayCode: string, from: Date | null): string {
if (!from) return DAY_LABELS[dayCode] ?? dayCode; // SSR safe fallback
...
}2. // 변경 전
if (!isImage && file.size > 100 * 1024)
// 변경 후
if (!isIcs && file.size > 100 * 1024)
const MAX_ICS_SIZE = 100 * 1024;
const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 의도에 맞게 조정
if (isIcs && file.size > MAX_ICS_SIZE) { ... }
if (isImage && file.size > MAX_IMAGE_SIZE) { ... }3.
const jsDay = DAY_CODE_TO_JS_DAY[dayCode];
if (jsDay === undefined) return DAY_LABELS[dayCode] ?? dayCode;🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/schedule/`[id]/ScheduleRoomClient.tsx:
- Around line 64-82: The formatDayWithDate function does not validate whether
the dayCode parameter exists in the DAY_CODE_TO_JS_DAY mapping, which can cause
diff to become NaN when an invalid dayCode is passed, resulting in incorrect
dates. Add defensive code to the formatDayWithDate function to check if the
dayCode exists in the DAY_CODE_TO_JS_DAY record before using it, and either
throw an error for invalid inputs or provide a fallback behavior to prevent NaN
calculations.
- Around line 428-431: The condition checking file size validation in the
ScheduleRoomClient.tsx file is inverted. The current condition `!isIcs` applies
the size limit and ICS-specific error message to image files instead of ICS
files. Change the condition from `!isIcs` to `isIcs` so that the 100KB file size
limit with the message "ICS 파일 크기는 100KB 이하여야 합니다." only applies to actual ICS
files, preventing incorrect error messages from appearing for image files.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 10b64849-3659-42c2-bb94-39268c91ea54
📒 Files selected for processing (1)
src/app/schedule/[id]/ScheduleRoomClient.tsx
| const DAY_CODE_TO_JS_DAY: Record<string, number> = { | ||
| SUN: 0, | ||
| MON: 1, | ||
| TUE: 2, | ||
| WED: 3, | ||
| THU: 4, | ||
| FRI: 5, | ||
| SAT: 6, | ||
| }; | ||
|
|
||
| function formatDayWithDate(dayCode: string): string { | ||
| const now = new Date(); | ||
| const diff = (DAY_CODE_TO_JS_DAY[dayCode] - now.getDay() + 7) % 7; | ||
| const target = new Date(now); | ||
| target.setDate(now.getDate() + diff); | ||
| const m = target.getMonth() + 1; | ||
| const d = target.getDate(); | ||
| return `${DAY_LABELS[dayCode] ?? dayCode} ${m}/${d}`; | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
formatDayWithDate에서 잘못된 dayCode 입력 시 NaN 날짜 생성 가능
DAY_CODE_TO_JS_DAY[dayCode]가 undefined를 반환하면 diff가 NaN이 되어 잘못된 날짜가 표시된다. 현재 호출부가 모두 DayCode[]를 사용하므로 런타임 위험은 낮으나, 타입이 string으로 완화된 만큼 방어 코드가 필요하다.
♻️ 방어 코드 추가 제안
function formatDayWithDate(dayCode: string): string {
+ const jsDay = DAY_CODE_TO_JS_DAY[dayCode];
+ if (jsDay === undefined) {
+ return DAY_LABELS[dayCode] ?? dayCode;
+ }
const now = new Date();
- const diff = (DAY_CODE_TO_JS_DAY[dayCode] - now.getDay() + 7) % 7;
+ const diff = (jsDay - now.getDay() + 7) % 7;
const target = new Date(now);
target.setDate(now.getDate() + diff);
const m = target.getMonth() + 1;
const d = target.getDate();
return `${DAY_LABELS[dayCode] ?? dayCode} ${m}/${d}`;
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/app/schedule/`[id]/ScheduleRoomClient.tsx around lines 64 - 82, The
formatDayWithDate function does not validate whether the dayCode parameter
exists in the DAY_CODE_TO_JS_DAY mapping, which can cause diff to become NaN
when an invalid dayCode is passed, resulting in incorrect dates. Add defensive
code to the formatDayWithDate function to check if the dayCode exists in the
DAY_CODE_TO_JS_DAY record before using it, and either throw an error for invalid
inputs or provide a fallback behavior to prevent NaN calculations.
| if (!isIcs && file.size > 100 * 1024) { | ||
| setImportMessage("ICS 파일 크기는 100KB 이하여야 합니다."); | ||
| return; | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 다른 파일의 ICS 검증 로직과 일관성 확인
rg -n "100.*1024|100KB" --type ts -C 3 | head -80Repository: Siul49/moim
Length of output: 2152
🏁 Script executed:
sed -n '420,435p' src/app/schedule/[id]/ScheduleRoomClient.tsxRepository: Siul49/moim
Length of output: 487
조건 반전 버그 — 이미지 파일에 ICS 크기 제한 메시지 표시
라인 428의 !isIcs 조건은 "이미지 파일"을 필터링하는데, 에러 메시지는 "ICS 파일 크기" 제한을 안내한다. 라인 422-427 검증을 통과한 파일은 isIcs || isImage이므로, !isIcs는 곧 isImage를 의미한다. 따라서 현재 코드는 이미지 파일 > 100KB 시 "ICS 파일 크기는..." 메시지를 표시하게 되어 사용자를 혼동시킨다.
calendar/connect/page.tsx와 api/everytime/timetable/route.ts는 모두 ICS 파일에만 100KB 제한을 적용한다. 조건을 isIcs로 수정해야 한다.
🐛 조건 수정
- if (!isIcs && file.size > 100 * 1024) {
+ if (isIcs && file.size > 100 * 1024) {
setImportMessage("ICS 파일 크기는 100KB 이하여야 합니다.");
return;
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/app/schedule/`[id]/ScheduleRoomClient.tsx around lines 428 - 431, The
condition checking file size validation in the ScheduleRoomClient.tsx file is
inverted. The current condition `!isIcs` applies the size limit and ICS-specific
error message to image files instead of ICS files. Change the condition from
`!isIcs` to `isIcs` so that the 100KB file size limit with the message "ICS 파일
크기는 100KB 이하여야 합니다." only applies to actual ICS files, preventing incorrect
error messages from appearing for image files.
종료 사유: 최신 dev 기준 재작업으로 대체이 PR 브랜치(ix/day-headers-dates)는 dev 대비 오래되어 conflict/리뷰 지적 상태였습니다.
이 PR은 머지하지 않고 닫습니다. 후속 PR 번호를 코멘트로 연결합니다. |
|
대체 PR: #124 |
🚀 작업 내용 (What)
📣 핵심 변경 이유 (Why)
📸 스크린샷 (Visuals, 선택)
🔗 관련 이슈 (Issue)
Close #