Skip to content

Commit

Permalink
add delegate action to APIKeySetting
Browse files Browse the repository at this point in the history
  • Loading branch information
ski-u committed Dec 21, 2024
1 parent 0fbbdd9 commit 9a1822e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Features/Sources/Settings/APIKey/APIKeySetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +39,9 @@ public struct APIKeySetting {

public func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .delegate:
return .none

case .onAppear:
state.apiKeyInput = apiKeyClient.getKey() ?? .init(rawValue: "")
return .none
Expand All @@ -43,7 +52,7 @@ public struct APIKeySetting {

case .updateButtonTapped:
apiKeyClient.setKey(state.apiKeyInput)
return .none
return .send(.delegate(.updated))
}
}
}
3 changes: 2 additions & 1 deletion Features/Sources/Settings/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9a1822e

Please sign in to comment.