Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ final class HomeViewCoordinator {
)
}

func loadInitialData() {
viewModel.send(.loadInitialData)
func fetchData() {
viewModel.send(.fetchData)
}

func makeTodoManageViewModel() -> TodoManageViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions Application/DevLogPresentation/Sources/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ final class TodayViewCoordinator {
updateTodayDisplayOptionsUseCase: container.resolve(UpdateTodayDisplayOptionsUseCase.self)
)
}

func fetchData() {
viewModel.send(.fetchData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down