-
Notifications
You must be signed in to change notification settings - Fork 0
Style/#139 캘린더 선택날짜 #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "style/#139-\uCE98\uB9B0\uB354-\uC120\uD0DD\uB0A0\uC9DC"
Style/#139 캘린더 선택날짜 #142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ enum CalendarMode { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct CalendarView: View { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @EnvironmentObject private var calendarCoordinator: CalendarCoordinator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @StateObject var viewModel: CalendarViewModel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @StateObject var homeCalendarFlowState: HomeCalendarFlowState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @State private var topGlobalY: CGFloat = .zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @State private var initialTopGlobalY: CGFloat? = nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @State private var bottomOffsetY: CGFloat = .zero | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -65,6 +66,18 @@ struct CalendarView: View { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .onChange(of: homeCalendarFlowState.treatmentDate) { date in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let date = date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewModel.updateDate(date: date) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| homeCalendarFlowState.treatmentDate = nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .onAppear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let date = homeCalendarFlowState.treatmentDate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewModel.updateDate(date: date) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| homeCalendarFlowState.treatmentDate = nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 중복 로직을 헬퍼 함수로 추출하는 것을 고려해보세요.
♻️ 제안하는 리팩토링+ private func handleTreatmentDate(_ date: Date?) {
+ guard let date = date else { return }
+ viewModel.updateDate(date: date)
+ homeCalendarFlowState.treatmentDate = nil
+ }
+
// In body:
.onChange(of: homeCalendarFlowState.treatmentDate) { date in
- if let date = date {
- viewModel.updateDate(date: date)
- homeCalendarFlowState.treatmentDate = nil
- }
+ handleTreatmentDate(date)
}
.onAppear {
- if let date = homeCalendarFlowState.treatmentDate {
- viewModel.updateDate(date: date)
- homeCalendarFlowState.treatmentDate = nil
- }
+ handleTreatmentDate(homeCalendarFlowState.treatmentDate)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .background(.gray0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,29 @@ final class CalendarViewModel: ObservableObject { | |
| selectedDowntime = downtimeList | ||
| mapToDowntimeDays(procedure: downtimeList) | ||
| } | ||
|
|
||
| func updateDate(date: Date) { | ||
| selectedDate = date | ||
|
|
||
| let calendar = Calendar.current | ||
| let currentYear = calendar.component(.year, from: currentDate) | ||
| let currentMonthVal = calendar.component(.month, from: currentDate) | ||
|
|
||
| let targetYear = calendar.component(.year, from: date) | ||
| let targetMonthVal = calendar.component(.month, from: date) | ||
|
|
||
| let monthDiff = (targetYear - currentYear) * 12 + (targetMonthVal - currentMonthVal) | ||
| currentMonth = monthDiff | ||
|
|
||
| Task { | ||
| do { | ||
| try await fetchProcedureCountsOfMonth() | ||
| try await fetchTodayProcedureList() | ||
| } catch { | ||
| CherrishLogger.error(error) | ||
| } | ||
| } | ||
|
Comment on lines
+141
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 비동기 작업의 취소 처리가 누락되었습니다.
♻️ Task 관리 개선 제안ViewModel에 Task 참조를 저장하고 새 호출 시 이전 Task를 취소하는 방식을 고려해보세요: + private var updateTask: Task<Void, Never>?
+
func updateDate(date: Date) {
selectedDate = date
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: currentDate)
let currentMonthVal = calendar.component(.month, from: currentDate)
let targetYear = calendar.component(.year, from: date)
let targetMonthVal = calendar.component(.month, from: date)
let monthDiff = (targetYear - currentYear) * 12 + (targetMonthVal - currentMonthVal)
currentMonth = monthDiff
- Task {
+ updateTask?.cancel()
+ updateTask = Task {
do {
try await fetchProcedureCountsOfMonth()
try await fetchTodayProcedureList()
} catch {
CherrishLogger.error(error)
}
}
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| extension CalendarViewModel { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,11 @@ final class TreatmentViewModel: ObservableObject{ | |
| } | ||
|
|
||
| do { | ||
| try await createUserProcedureUseCase.execute(scheduledDate: scheduledDate.toScheduledAtFormat, recoveryDate: recoverDate.toRecoveryDateFormat, treatments: selectedTreatments) | ||
| try await createUserProcedureUseCase.execute( | ||
| scheduledDate: scheduledDate.toScheduledAtFormat, | ||
| recoveryDate: recoverDate.toRecoveryDateFormat, | ||
| treatments: selectedTreatments | ||
| ) | ||
|
Comment on lines
+81
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 코드 포맷팅 개선 확인 함수 호출을 여러 줄로 분리하여 가독성을 향상시켰습니다. 파라미터 순서와 값은 변경되지 않았으며, 로직에 영향을 주지 않는 포맷팅 변경입니다. 다만, 이 변경사항은 PR의 주요 목적(캘린더 선택 날짜 네비게이션)과 직접적인 관련이 없는 것으로 보입니다. 포맷팅 개선은 좋지만, 별도의 커밋이나 PR로 분리하는 것이 변경 이력 관리에 더 명확할 수 있습니다. 🤖 Prompt for AI Agents |
||
| } catch { | ||
| CherrishLogger.network(error) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // | ||
| // HomeCalendarFlowState.swift | ||
| // Cherrish-iOS | ||
| // | ||
| // Created by 이나연 on 1/21/26. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| final class HomeCalendarFlowState: ObservableObject { | ||
| @Published var treatmentDate: Date? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,14 @@ final class HomeViewModel: ObservableObject { | |
| @Published var errorMessage: String? | ||
|
|
||
| private let fetchDashboardDataUseCase: FetchDashboardData | ||
| private let homeCalendarFlowState: HomeCalendarFlowState | ||
|
|
||
| init(fetchDashboardDataUseCase: FetchDashboardData) { | ||
| init( | ||
| fetchDashboardDataUseCase: FetchDashboardData, | ||
| homeCalendarFlowState: HomeCalendarFlowState | ||
| ) { | ||
| self.fetchDashboardDataUseCase = fetchDashboardDataUseCase | ||
| self.homeCalendarFlowState = homeCalendarFlowState | ||
| } | ||
|
|
||
| @MainActor | ||
|
|
@@ -33,6 +38,14 @@ final class HomeViewModel: ObservableObject { | |
| isLoading = false | ||
| } | ||
|
|
||
| func selectUpcomingDate(_ dateString: String) { | ||
| let formatter = DateFormatter() | ||
| formatter.dateFormat = "yyyy-MM-dd" | ||
| if let date = formatter.date(from: dateString) { | ||
| homeCalendarFlowState.treatmentDate = date | ||
| } | ||
|
Comment on lines
+41
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Short best-practice checklist for fixed-format parsing with DateFormatter (Swift / Foundation)
Minimal example (Swift): let f = DateFormatter() (Or use ISO8601DateFormatter for RFC 3339/ISO 8601 inputs.) (sarunw.com) References (Apple):
Citations:
고정 포맷 파싱 시 Locale/Calendar 명시 필요. 현재 코드에서 명시적인 로케일과 캘린더가 없으므로 "yyyy-MM-dd" 파싱이 사용자의 기기 설정에 따라 실패할 수 있습니다. Apple의 공식 가이드에 따르면 고정 포맷 파싱에는 🔧 제안 수정- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd"
+ let formatter = DateFormatter()
+ formatter.locale = Locale(identifier: "en_US_POSIX")
+ formatter.calendar = Calendar(identifier: .gregorian)
+ formatter.dateFormat = "yyyy-MM-dd"🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| var formattedDate: String { | ||
| guard let date = dashboardData?.date else { return "" } | ||
| let formatter = DateFormatter() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StateObject대신@ObservedObject를 사용해야 합니다.homeCalendarFlowState는 DIContainer에서 외부 생성되어 주입되는 객체입니다.@StateObject는 View가 객체의 생명주기를 소유할 때 사용하고, 외부에서 생성된 객체를 전달받을 때는@ObservedObject를 사용해야 합니다.현재 구현에서는 싱글톤으로 등록되어 있어 실질적으로 문제가 발생하지 않을 수 있지만, 의미론적으로 올바른 property wrapper를 사용하는 것이 좋습니다.
🔧 수정 제안
📝 Committable suggestion
🤖 Prompt for AI Agents