mana-swift-ui/Sources/ManaLLMUI/ManaLLMSettingsLink.swift
Till JS d2adcb7e5f feat(ManaLLMUI): KI-Einstellungen als geteilte Unterseite (Link + Screen)
ManaLLMSettingsLink (NavigationLink-Zeile) + ManaLLMSettingsScreen
(Form-Unterseite mit generischem extra-Slot) buendeln die vier KI-
Sektionen hinter einer Zeile statt inline. Flottenweites Muster; additiv
zu ManaLLMSettingsView (unveraendert). Default Titel 'Kuenstliche
Intelligenz' + SF-Symbol 'sparkles'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 22:01:19 +02:00

94 lines
2.8 KiB
Swift

import ManaLLM
import SwiftUI
/// Eine `NavigationLink`-Zeile, die auf die geteilte ``ManaLLMSettingsScreen``
/// pusht. Das flottenweite Muster für KI-Einstellungen: **eine** Zeile im
/// Konto-/Settings-Tab statt der vier KI-Sections inline.
///
/// In eine `Form`/`List` der App gehängt:
///
/// ```swift
/// Section {
/// ManaLLMSettingsLink(context: myContext)
/// }
/// ```
///
/// Mit app-eigener KI-Section auf der Zielseite (z.B. memoros Server-LLM):
///
/// ```swift
/// ManaLLMSettingsLink(context: myContext, showByok: false) {
/// serverLLMSection
/// }
/// ```
///
/// Die Zeile zeigt ein SF-Symbol, den Titel und — als Untertitel — den
/// `context.useCaseShort`, damit auf einen Blick klar ist, wofür die App
/// KI nutzt (z.B. „Story-Synopsis"). Titel und Icon sind überschreibbar.
public struct ManaLLMSettingsLink<Extra: View>: View {
private let context: ManaLLMContext
private let showByok: Bool
private let title: String
private let icon: String
private let extra: Extra
/// - Parameters:
/// - context: App-spezifische Use-Case-Texte. `useCaseShort` wird als
/// Untertitel der Zeile gezeigt.
/// - showByok: An die ``ManaLLMSettingsScreen`` durchgereicht.
/// - title: Zeilen-Titel **und** Navigations-Titel der Zielseite.
/// - icon: SF-Symbol der Zeile. Default `"sparkles"`.
/// - extra: App-eigene KI-Sections für die Zielseite.
public init(
context: ManaLLMContext = .generic,
showByok: Bool = true,
title: String = "Künstliche Intelligenz",
icon: String = "sparkles",
@ViewBuilder extra: () -> Extra
) {
self.context = context
self.showByok = showByok
self.title = title
self.icon = icon
self.extra = extra()
}
public var body: some View {
NavigationLink {
ManaLLMSettingsScreen(
context: context,
showByok: showByok,
title: title
) { extra }
} label: {
Label {
VStack(alignment: .leading, spacing: 2) {
Text(title)
Text(context.useCaseShort)
.font(.caption)
.foregroundStyle(.secondary)
}
} icon: {
Image(systemName: icon)
}
}
}
}
public extension ManaLLMSettingsLink where Extra == EmptyView {
/// Bequemlichkeits-Init ohne app-eigenen Zusatz-Inhalt.
init(
context: ManaLLMContext = .generic,
showByok: Bool = true,
title: String = "Künstliche Intelligenz",
icon: String = "sparkles"
) {
self.init(
context: context,
showByok: showByok,
title: title,
icon: icon
) {
EmptyView()
}
}
}