Skip to content

Commit

Permalink
Customize Action Text in Onboarding Screens (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed May 23, 2023
1 parent c45a579 commit 84605b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 11 additions & 3 deletions Sources/SpeziOpenAI/OpenAIAPIKeyOnboardingStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import SwiftUI
/// View to display an onboarding step for the user to enter an OpenAI API Key.
public struct OpenAIAPIKeyOnboardingStep<ComponentStandard: Standard>: View {
@EnvironmentObject private var openAI: OpenAIComponent<ComponentStandard>
private let actionText: String
private let action: () -> Void


private var apiToken: Binding<String> {
Binding(
get: {
Expand All @@ -33,7 +35,6 @@ public struct OpenAIAPIKeyOnboardingStep<ComponentStandard: Standard>: View {
)
}


public var body: some View {
OnboardingView(
titleView: {
Expand Down Expand Up @@ -63,7 +64,7 @@ public struct OpenAIAPIKeyOnboardingStep<ComponentStandard: Standard>: View {
},
actionView: {
OnboardingActionsView(
String(localized: "OPENAI_API_KEY_SAVE_BUTTON", bundle: .module),
actionText,
action: {
action()
}
Expand All @@ -74,7 +75,14 @@ public struct OpenAIAPIKeyOnboardingStep<ComponentStandard: Standard>: View {
}


public init(_ action: @escaping () -> Void) {
/// - Parameters:
/// - actionText: Text that should appear on the action button.
/// - action: Action that should be performed after the openAI API key has been persisted.
public init(
actionText: String? = nil,
_ action: @escaping () -> Void
) {
self.actionText = actionText ?? String(localized: "OPENAI_API_KEY_SAVE_BUTTON", bundle: .module)
self.action = action
}
}
12 changes: 10 additions & 2 deletions Sources/SpeziOpenAI/OpenAIModelSelectionOnboardingStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SwiftUI
/// View to display an onboarding step for the user to enter change the OpenAI model.
public struct OpenAIModelSelectionOnboardingStep<ComponentStandard: Standard>: View {
@EnvironmentObject private var openAI: OpenAIComponent<ComponentStandard>
private let actionText: String
private let action: () -> Void


Expand All @@ -38,7 +39,7 @@ public struct OpenAIModelSelectionOnboardingStep<ComponentStandard: Standard>: V
},
actionView: {
OnboardingActionsView(
String(localized: "OPENAI_MODEL_SELECTION_SAVE_BUTTON", bundle: .module),
actionText,
action: {
action()
}
Expand All @@ -48,7 +49,14 @@ public struct OpenAIModelSelectionOnboardingStep<ComponentStandard: Standard>: V
}


public init(_ action: @escaping () -> Void) {
/// - Parameters:
/// - actionText: Text that should appear on the action button.
/// - action: Action that should be performed after the openAI model selection has been persisted.
public init(
actionText: String? = nil,
_ action: @escaping () -> Void
) {
self.actionText = actionText ?? String(localized: "OPENAI_MODEL_SELECTION_SAVE_BUTTON", bundle: .module)
self.action = action
}
}

0 comments on commit 84605b9

Please sign in to comment.