-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/#172 로딩뷰 추가 #173
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: "fix/#172-\uB85C\uB529\uBDF0"
Refactor/#172 로딩뷰 추가 #173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,56 @@ struct CalendarView: View { | |
| @EnvironmentObject private var calendarCoordinator: CalendarCoordinator | ||
| @StateObject var viewModel: CalendarViewModel | ||
| @StateObject var homeCalendarFlowState: HomeCalendarFlowState | ||
| @State var calendarMode: CalendarMode = .none | ||
| @State var selectedProcedureID: Int? = nil | ||
|
|
||
| var body: some View { | ||
| ZStack { | ||
| if viewModel.isLoading { | ||
| CherrishLoadingView() | ||
| } else { | ||
| CalendarContentView( | ||
| viewModel: viewModel, | ||
| homeCalendarFlowState: homeCalendarFlowState, | ||
| calendarMode: $calendarMode, | ||
| selectedProcedureID: $selectedProcedureID | ||
| ) | ||
| } | ||
| } | ||
| .task (id: viewModel.currentMonth){ | ||
| if calendarMode == .none { | ||
| do { | ||
| try await viewModel.fetchProcedureCountsOfMonth() | ||
| try await viewModel.fetchTodayProcedureList() | ||
| } catch { | ||
| CherrishLogger.error(error) | ||
| } | ||
| } | ||
|
Comment on lines
+44
to
+52
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. 순차적 fetch 호출로 인한 로딩 상태 깜빡임(flicker) 가능성이 있습니다.
또한, 첫 번째 호출이 실패하면 두 번째 호출이 실행되지 않아 불완전한 상태가 될 수 있습니다. 🔧 권장 수정안ViewModel에서 로딩 상태를 별도로 관리하거나, 두 호출을 병렬로 실행하고 외부에서 로딩 상태를 제어하는 방식을 고려하세요: .task (id: viewModel.currentMonth){
if calendarMode == .none {
+ viewModel.isLoading = true
do {
- try await viewModel.fetchProcedureCountsOfMonth()
- try await viewModel.fetchTodayProcedureList()
+ async let counts: () = viewModel.fetchProcedureCountsOfMonthWithoutLoading()
+ async let list: () = viewModel.fetchTodayProcedureListWithoutLoading()
+ _ = try await (counts, list)
} catch {
CherrishLogger.error(error)
}
+ viewModel.isLoading = false
}
}또는 ViewModel에 두 작업을 래핑하는 단일 메서드를 추가하세요. 🤖 Prompt for AI Agents |
||
| } | ||
| .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 | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private struct CalendarContentView: View { | ||
| @EnvironmentObject private var calendarCoordinator: CalendarCoordinator | ||
| @ObservedObject var viewModel: CalendarViewModel | ||
| @ObservedObject var homeCalendarFlowState: HomeCalendarFlowState | ||
| @State private var topGlobalY: CGFloat = .zero | ||
| @State private var initialTopGlobalY: CGFloat? = nil | ||
| @State private var bottomOffsetY: CGFloat = .zero | ||
| @State private var calendarMode: CalendarMode = .none | ||
| @State private var selectedProcedureID: Int? = nil | ||
| @Binding var calendarMode: CalendarMode | ||
| @Binding var selectedProcedureID: Int? | ||
| @State private var buttonState: ButtonState = .active | ||
|
|
||
| private let scrollAreaHeight: CGFloat = 184.adjustedH | ||
|
|
@@ -40,6 +85,7 @@ struct CalendarView: View { | |
| let weekdays: [String] = ["일", "월", "화", "수", "목", "금", "토"] | ||
| let columns = Array(repeating: GridItem(.fixed(40.adjustedW), spacing: 8), count: 7) | ||
|
|
||
|
|
||
| var body: some View { | ||
| VStack { | ||
| Spacer() | ||
|
|
@@ -56,33 +102,10 @@ struct CalendarView: View { | |
| } | ||
| Spacer() | ||
| } | ||
| .task (id: viewModel.currentMonth){ | ||
| if calendarMode == .none { | ||
| do { | ||
| try await viewModel.fetchProcedureCountsOfMonth() | ||
| try await viewModel.fetchTodayProcedureList() | ||
| } catch { | ||
| CherrishLogger.error(error) | ||
| } | ||
| } | ||
| } | ||
| .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 | ||
| } | ||
| } | ||
| .background(.gray0) | ||
| } | ||
| } | ||
|
|
||
| extension CalendarView { | ||
| extension CalendarContentView { | ||
| private var calendarHeader: some View { | ||
| VStack { | ||
| HStack { | ||
|
|
@@ -330,7 +353,7 @@ extension CalendarView { | |
|
|
||
| } | ||
|
|
||
| extension CalendarView { | ||
| extension CalendarContentView { | ||
| private var scrollViewTopMarkerView: some View { | ||
| GeometryReader { proxy in | ||
| Color.clear | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ final class CalendarViewModel: ObservableObject { | |||||||||||||||||||||||||||||||||
| @Published private(set) var treatmentDate: String = "" | ||||||||||||||||||||||||||||||||||
| @Published private(set) var downtimeByDay: [String : DowntimeDayState] = [:] | ||||||||||||||||||||||||||||||||||
| @Published private(set) var selectedDowntime: ProcedureDowntimeEntity? | ||||||||||||||||||||||||||||||||||
| @Published private(set) var isLoading: Bool = true | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private let fetchProcedureCountOfMonthUseCase: FetchProcedureCountOfMonth | ||||||||||||||||||||||||||||||||||
| private let fetchTodayProcedureListUseCase: FetchTodayProcedureListUseCase | ||||||||||||||||||||||||||||||||||
|
|
@@ -103,26 +104,46 @@ final class CalendarViewModel: ObservableObject { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||
| func fetchProcedureCountsOfMonth() async throws { | ||||||||||||||||||||||||||||||||||
| isLoading = true | ||||||||||||||||||||||||||||||||||
| let calendar = Calendar.current | ||||||||||||||||||||||||||||||||||
| let targetDate = getCurrentMonth(addingMonth: currentMonth) | ||||||||||||||||||||||||||||||||||
| let year = calendar.component(.year, from: targetDate) | ||||||||||||||||||||||||||||||||||
| let month = calendar.component(.month, from: targetDate) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let response = try await fetchProcedureCountOfMonthUseCase.execute(year: year, month: month) | ||||||||||||||||||||||||||||||||||
| procedureCountOfMonth = response.dailyProcedureCounts | ||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||
| let response = try await fetchProcedureCountOfMonthUseCase.execute(year: year, month: month) | ||||||||||||||||||||||||||||||||||
| isLoading = false | ||||||||||||||||||||||||||||||||||
| procedureCountOfMonth = response.dailyProcedureCounts | ||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||
| CherrishLogger.error(error) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
+119
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. 에러 발생 시
🐛 수정 제안 do {
let response = try await fetchProcedureCountOfMonthUseCase.execute(year: year, month: month)
- isLoading = false
procedureCountOfMonth = response.dailyProcedureCounts
} catch {
CherrishLogger.error(error)
}
+ isLoading = false🤖 Prompt for AI Agents
Contributor
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. 이고 한 번 화긴해주세용! |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||
| func fetchTodayProcedureList() async throws { | ||||||||||||||||||||||||||||||||||
| isLoading = true | ||||||||||||||||||||||||||||||||||
| treatmentDate = selectedDate.toDateString() | ||||||||||||||||||||||||||||||||||
| procedureList = try await fetchTodayProcedureListUseCase.execute(date: treatmentDate) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||
| procedureList = try await fetchTodayProcedureListUseCase.execute(date: treatmentDate) | ||||||||||||||||||||||||||||||||||
| isLoading = false | ||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||
| CherrishLogger.error(error) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+127
to
+132
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. 동일한 이슈: 에러 시 🐛 수정 제안 do {
procedureList = try await fetchTodayProcedureListUseCase.execute(date: treatmentDate)
- isLoading = false
} catch {
CherrishLogger.error(error)
}
+ isLoading = false📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||
| func fetchDowntimeByDay(procedureId: Int) async throws { | ||||||||||||||||||||||||||||||||||
| let downtimeList = try await fetchProcedureDowntimeUseCase.execute(id: procedureId) | ||||||||||||||||||||||||||||||||||
| selectedDowntime = downtimeList | ||||||||||||||||||||||||||||||||||
| mapToDowntimeDays(procedure: downtimeList) | ||||||||||||||||||||||||||||||||||
| isLoading = true | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||
| let downtimeList = try await fetchProcedureDowntimeUseCase.execute(id: procedureId) | ||||||||||||||||||||||||||||||||||
| isLoading = false | ||||||||||||||||||||||||||||||||||
| selectedDowntime = downtimeList | ||||||||||||||||||||||||||||||||||
| mapToDowntimeDays(procedure: downtimeList) | ||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||
| CherrishLogger.error(error) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+139
to
+146
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. 동일한 이슈: 에러 시 🐛 수정 제안 do {
let downtimeList = try await fetchProcedureDowntimeUseCase.execute(id: procedureId)
- isLoading = false
selectedDowntime = downtimeList
mapToDowntimeDays(procedure: downtimeList)
} catch {
CherrishLogger.error(error)
}
+ isLoading = false📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func updateDate(date: Date) { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
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.
🧹 Nitpick | 🔵 Trivial
SwiftUI state 속성에
private접근 제어자를 추가하세요.SwiftLint 경고에 따르면, SwiftUI의
@StateObject와@State속성은private으로 선언해야 합니다. 특히calendarMode와selectedProcedureID는 내부 상태이므로 반드시private이어야 합니다.♻️ 권장 수정안
struct CalendarView: View { `@EnvironmentObject` private var calendarCoordinator: CalendarCoordinator - `@StateObject` var viewModel: CalendarViewModel - `@StateObject` var homeCalendarFlowState: HomeCalendarFlowState - `@State` var calendarMode: CalendarMode = .none - `@State` var selectedProcedureID: Int? = nil + `@StateObject` private var viewModel: CalendarViewModel + `@StateObject` private var homeCalendarFlowState: HomeCalendarFlowState + `@State` private var calendarMode: CalendarMode = .none + `@State` private var selectedProcedureID: Int? = nil📝 Committable suggestion
🧰 Tools
🪛 SwiftLint (0.57.0)
[Warning] 26-26: SwiftUI state properties should be private
(private_swiftui_state)
[Warning] 27-27: SwiftUI state properties should be private
(private_swiftui_state)
[Warning] 28-28: SwiftUI state properties should be private
(private_swiftui_state)
[Warning] 29-29: SwiftUI state properties should be private
(private_swiftui_state)
🤖 Prompt for AI Agents