From 9a1822eea4fa69d2b7d3dadc4fe416b7fef5226f Mon Sep 17 00:00:00 2001 From: Yunosuke Sakai Date: Sat, 21 Dec 2024 19:50:17 +0900 Subject: [PATCH] add delegate action to `APIKeySetting` --- Features/Sources/Settings/APIKey/APIKeySetting.swift | 11 ++++++++++- Features/Sources/Settings/Settings/Settings.swift | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Features/Sources/Settings/APIKey/APIKeySetting.swift b/Features/Sources/Settings/APIKey/APIKeySetting.swift index 145ea72..7ae239d 100644 --- a/Features/Sources/Settings/APIKey/APIKeySetting.swift +++ b/Features/Sources/Settings/APIKey/APIKeySetting.swift @@ -22,9 +22,15 @@ public struct APIKeySetting { } public enum Action: Equatable { + case delegate(Delegate) case onAppear case setAPIKeyInput(String) case updateButtonTapped + + @CasePathable + public enum Delegate { + case updated + } } @Dependency(\.apiKeyClient) private var apiKeyClient @@ -33,6 +39,9 @@ public struct APIKeySetting { public func reduce(into state: inout State, action: Action) -> Effect { switch action { + case .delegate: + return .none + case .onAppear: state.apiKeyInput = apiKeyClient.getKey() ?? .init(rawValue: "") return .none @@ -43,7 +52,7 @@ public struct APIKeySetting { case .updateButtonTapped: apiKeyClient.setKey(state.apiKeyInput) - return .none + return .send(.delegate(.updated)) } } } diff --git a/Features/Sources/Settings/Settings/Settings.swift b/Features/Sources/Settings/Settings/Settings.swift index 54a052e..563e066 100644 --- a/Features/Sources/Settings/Settings/Settings.swift +++ b/Features/Sources/Settings/Settings/Settings.swift @@ -38,7 +38,8 @@ public struct Settings { case let .path(action): switch action { - case let .element(id: id, action: .apiKeySetting(.updateButtonTapped)): + case let .element(id: id, action: .apiKeySetting(.delegate(.updated))): + state.apiKey = apiKeyClient.getKey() ?? .init(rawValue: "") state.path.pop(from: id) return .none