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
9 changes: 5 additions & 4 deletions DevLog/Presentation/ViewModel/AccountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ final class AccountViewModel: Store {

func reduce(with action: Action) -> [SideEffect] {
var state = self.state
var effects: [SideEffect] = []

switch action {
case .onAppear:
return [.fetch]
effects = [.fetch]
case .linkWithProvider(let value):
return [.link(value)]
effects = [.link(value)]
case .unlinkFromProvider(let value):
return [.unlink(value)]
effects = [.unlink(value)]
case .setAlert(let isPresented, let type):
setAlert(&state, isPresented: isPresented, type: type)
case .setToast(let isPresented, let type):
Expand All @@ -86,7 +87,7 @@ final class AccountViewModel: Store {
}

self.state = state
return []
return effects
}

func run(_ effect: SideEffect) {
Expand Down
9 changes: 4 additions & 5 deletions DevLog/Presentation/ViewModel/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,23 @@ final class LoginViewModel: Store {

func reduce(with action: Action) -> [SideEffect] {
var state = self.state
var effects: [SideEffect] = []

switch action {
case .setAlert(let isPresented):
setAlert(&state, isPresented: isPresented)
case .tapSignInButton(let authProvider):
self.state = state
return [.signIn(authProvider)]
effects = [.signIn(authProvider)]
case .tapSignOutButton, .signOutAuto:
self.state = state
return [.signOut]
effects = [.signOut]
case .setLoading(let value):
state.isLoading = value
case .setLogined(let result):
state.signIn = result
}

self.state = state
return []
return effects
}

func run(_ effect: SideEffect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ final class PushNotificationSettingsViewModel: Store {
func reduce(with action: Action) -> [SideEffect] {
var state = self.state
var effects: [SideEffect] = []

switch action {
case .fetchSettings:
effects = [.fetchPushNotificationSettings]
Expand Down
5 changes: 3 additions & 2 deletions DevLog/Presentation/ViewModel/RootViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class RootViewModel: Store {

func reduce(with action: Action) -> [SideEffect] {
var state = self.state
var effects: [SideEffect] = []

switch action {
case .setAlert(let isPresented):
Expand All @@ -82,13 +83,13 @@ final class RootViewModel: Store {
case .setTheme(let theme):
state.theme = theme
case .signOutAuto:
return [.signOut]
effects = [.signOut]
case .didLogined(let result):
state.signIn = result
}

self.state = state
return []
return effects
}

func run(_ effect: SideEffect) {
Expand Down
11 changes: 8 additions & 3 deletions DevLog/Presentation/ViewModel/SettingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ final class SettingViewModel: Store {
}

func reduce(with action: Action) -> [SideEffect] {
var state = self.state
var effects: [SideEffect] = []

switch action {
case .setAlert(let isPresented, let type):
setAlert(&state, isPresented: isPresented, type: type)
Expand All @@ -76,9 +79,9 @@ final class SettingViewModel: Store {
case .updateDirSize:
state.dirSize = dirSizeInBytes()
case .tapDeleteAuthButton:
return [.deleteAuth]
effects = [.deleteAuth]
case .tapSignOutButton:
return [.signOut]
effects = [.signOut]
case .tapRemoveCacheButton:
setAlert(&state, isPresented: true, type: .removeCache)
case .confirmRemoveCache:
Expand All @@ -90,7 +93,9 @@ final class SettingViewModel: Store {
setAlert(&state, isPresented: true, type: .error)
}
}
return []

self.state = state
return effects
}

func run(_ effect: SideEffect) {
Expand Down
2 changes: 1 addition & 1 deletion DevLog/Presentation/ViewModel/TodoDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class TodoDetailViewModel: Store {
case .setLoading(let value):
state.isLoading = value
case .upsertTodo(let todo):
return [.upsertTodo(todo)]
effects = [.upsertTodo(todo)]
}

self.state = state
Expand Down
16 changes: 13 additions & 3 deletions DevLog/Presentation/ViewModel/TodoEditorViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,19 @@ final class TodoEditorViewModel: Store {
}

func reduce(with action: Action) -> [SideEffect] {
var state = self.state

switch action {
case .addTag(let tag):
if !tag.isEmpty { state.tags.append(tag) }
if !tag.isEmpty {
state.tags.append(tag)
}
case .removeTag(let tagText):
state.tags.removeAll { $0 == tagText }
case .setContent(let stringValue),
.setTagText(let stringValue),
.setTitle(let stringValue):
handleStringAction(action, stringValue: stringValue)
handleStringAction(action, stringValue: stringValue, state: &state)
case .setDueDate(let dueDate):
if let tomorrowDate = calendar.date(byAdding: .day, value: 1, to: Date()), let dueDate {
state.dueDate = max(dueDate, tomorrowDate)
Expand All @@ -102,12 +106,18 @@ final class TodoEditorViewModel: Store {
state.dueDate = calendar.date(byAdding: .day, value: 1, to: Date())
}
}

self.state = state
return []
}
}

extension TodoEditorViewModel {
private func handleStringAction(_ action: Action, stringValue: String) {
private func handleStringAction(
_ action: Action,
stringValue: String,
state: inout State
) {
switch action {
case .setContent:
state.content = stringValue
Expand Down
4 changes: 4 additions & 0 deletions DevLog/Presentation/ViewModel/TodoManageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ final class TodoManageViewModel: Store {
}

func reduce(with action: Action) -> [SideEffect] {
var state = self.state

switch action {
case .moveItem(let from, let target):
state.todoKindPreferences.move(fromOffsets: from, toOffset: target)
Expand All @@ -34,6 +36,8 @@ final class TodoManageViewModel: Store {
state.todoKindPreferences[index].isVisible.toggle()
}
}

self.state = state
return []
}
}