Skip to content

Commit

Permalink
Add action and store to support updating notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo committed Dec 20, 2024
1 parent 9963dc7 commit 9d38e56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Yosemite/Yosemite/Actions/AccountAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public enum AccountAction: Action {
case synchronizeSitesAndReturnSelectedSiteInfo(siteAddress: String, onCompletion: (Result<Site, Error>) -> Void)
case synchronizeSitePlan(siteID: Int64, onCompletion: (Result<Void, Error>) -> Void)
case updateAccountSettings(userID: Int64, tracksOptOut: Bool, onCompletion: (Result<Void, Error>) -> Void)
case updateNotificationSettings(notificationSettings: NotificationSettings, onCompletion: (Result<Void, Error>) -> Void)
case closeAccount(onCompletion: (Result<Void, Error>) -> Void)
}
13 changes: 13 additions & 0 deletions Yosemite/Yosemite/Stores/AccountStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class AccountStore: Store {
synchronizeSitePlan(siteID: siteID, onCompletion: onCompletion)
case .updateAccountSettings(let userID, let tracksOptOut, let onCompletion):
updateAccountSettings(userID: userID, tracksOptOut: tracksOptOut, onCompletion: onCompletion)
case .updateNotificationSettings(let notificationSettings, let onCompletion):
updateNotificationSettings(notificationSettings: notificationSettings, onCompletion: onCompletion)
case .closeAccount(let onCompletion):
closeAccount(onCompletion: onCompletion)
}
Expand Down Expand Up @@ -223,6 +225,17 @@ private extension AccountStore {
}
}

func updateNotificationSettings(notificationSettings: NotificationSettings, onCompletion: @escaping (Result<Void, Error>) -> Void) {
Task {
do {
try await remote.updateNotificationSettings(with: notificationSettings)
onCompletion(.success(()))
} catch {
onCompletion(.failure(error))
}
}
}

func closeAccount(onCompletion: @escaping (Result<Void, Error>) -> Void) {
Task {
do {
Expand Down

0 comments on commit 9d38e56

Please sign in to comment.