diff --git a/Application/DevLogPresentation/Sources/Home/Home/HomeViewCoordinator.swift b/Application/DevLogPresentation/Sources/Home/Home/HomeViewCoordinator.swift index 477d4d44..0eafabc7 100644 --- a/Application/DevLogPresentation/Sources/Home/Home/HomeViewCoordinator.swift +++ b/Application/DevLogPresentation/Sources/Home/Home/HomeViewCoordinator.swift @@ -45,8 +45,8 @@ final class HomeViewCoordinator { ) } - func loadInitialData() { - viewModel.send(.loadInitialData) + func fetchData() { + viewModel.send(.fetchData) } func makeTodoManageViewModel() -> TodoManageViewModel { diff --git a/Application/DevLogPresentation/Sources/Home/Home/HomeViewModel.swift b/Application/DevLogPresentation/Sources/Home/Home/HomeViewModel.swift index 11cb785b..dbda9812 100644 --- a/Application/DevLogPresentation/Sources/Home/Home/HomeViewModel.swift +++ b/Application/DevLogPresentation/Sources/Home/Home/HomeViewModel.swift @@ -38,7 +38,7 @@ final class HomeViewModel: Store { } enum Action { - case loadInitialData + case fetchData case networkStatusChanged(Bool) case setPresentation(Presentation, Bool) case setAlert(isPresented: Bool, type: AlertType? = nil) @@ -145,7 +145,7 @@ final class HomeViewModel: Store { switch action { case .networkStatusChanged(let isConnected): state.isNetworkConnected = isConnected - case .loadInitialData, .setPresentation, .setAlert, .setToast, .refreshWebPages, + case .fetchData, .setPresentation, .setAlert, .setToast, .refreshWebPages, .tapTodoCategory, .orderTodoCategory, .addTodo, .updateWebPageURLInput, .addWebPage, .deleteWebPage, .undoDeleteWebPage: effects = reduceByView(action, state: &state) @@ -274,7 +274,7 @@ private extension HomeViewModel { // swiftlint:disable cyclomatic_complexity func reduceByView(_ action: Action, state: inout State) -> [SideEffect] { switch action { - case .loadInitialData: + case .fetchData: return [.fetchTodoCategoryPreferences, .fetchRecentTodos, .fetchWebPages] case .refreshWebPages: return [.fetchWebPages] diff --git a/Application/DevLogPresentation/Sources/Main/MainView.swift b/Application/DevLogPresentation/Sources/Main/MainView.swift index b9dc7471..ecc6d36b 100644 --- a/Application/DevLogPresentation/Sources/Main/MainView.swift +++ b/Application/DevLogPresentation/Sources/Main/MainView.swift @@ -41,9 +41,11 @@ struct MainView: View { .onAppear { coordinator.mainViewModel.send(.onAppear) } - .onChange(of: selectedTab) { _, newValue in + .onChange(of: selectedTab, initial: true) { _, newValue in if newValue == .home { - homeViewCoordinator.loadInitialData() + homeViewCoordinator.fetchData() + } else if newValue == .today { + todayViewCoordinator.fetchData() } } .alert( diff --git a/Application/DevLogPresentation/Sources/Today/TodayView.swift b/Application/DevLogPresentation/Sources/Today/TodayView.swift index 7fded289..7db59ef9 100644 --- a/Application/DevLogPresentation/Sources/Today/TodayView.swift +++ b/Application/DevLogPresentation/Sources/Today/TodayView.swift @@ -29,7 +29,6 @@ struct TodayView: View { .toolbar { toolbarContent } .background(NavigationBarConfigurator()) .refreshable { coordinator.viewModel.send(.refresh) } - .onAppear { coordinator.viewModel.send(.onAppear) } .alert( coordinator.viewModel.state.alertTitle, isPresented: Binding( diff --git a/Application/DevLogPresentation/Sources/Today/TodayViewCoordinator.swift b/Application/DevLogPresentation/Sources/Today/TodayViewCoordinator.swift index 46bc2578..290bb0d3 100644 --- a/Application/DevLogPresentation/Sources/Today/TodayViewCoordinator.swift +++ b/Application/DevLogPresentation/Sources/Today/TodayViewCoordinator.swift @@ -24,4 +24,8 @@ final class TodayViewCoordinator { updateTodayDisplayOptionsUseCase: container.resolve(UpdateTodayDisplayOptionsUseCase.self) ) } + + func fetchData() { + viewModel.send(.fetchData) + } } diff --git a/Application/DevLogPresentation/Sources/Today/TodayViewModel.swift b/Application/DevLogPresentation/Sources/Today/TodayViewModel.swift index 0002fdcc..0281bfbb 100644 --- a/Application/DevLogPresentation/Sources/Today/TodayViewModel.swift +++ b/Application/DevLogPresentation/Sources/Today/TodayViewModel.swift @@ -62,7 +62,7 @@ final class TodayViewModel: Store { case resetDisplayOptions case completeTodo(TodayTodoItem) case togglePinned(TodayTodoItem) - case onAppear + case fetchData case fetchTodos([TodayTodoItem]) case setLoading(Bool) case updateTodo(TodayTodoItem) @@ -178,7 +178,7 @@ final class TodayViewModel: Store { case .refresh, .setAlert, .setSectionScope, .setDueDateVisibility, .setFocusVisibility, .resetDisplayOptions, .completeTodo, .togglePinned: effects = reduceByUser(action, state: &state) - case .onAppear: + case .fetchData: effects = reduceByView(action, state: &state) case .fetchTodos, .setLoading, .updateTodo, .removeTodo: effects = reduceByRun(action, state: &state) @@ -305,7 +305,7 @@ private extension TodayViewModel { func reduceByView(_ action: Action, state: inout State) -> [SideEffect] { switch action { - case .onAppear: + case .fetchData: return [.fetchTodos] default: break