2026-07-04 10:32:59 +02:00
|
|
|
import Recording
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
/// The root view of the Attendi sample app.
|
|
|
|
|
///
|
|
|
|
|
/// The view hosts the `RecordingView` feature from the `Recording` target of the `Features` package, which drives the whole recording flow,
|
|
|
|
|
/// inside a navigation stack, and presents the transcribed text of every processed recording in a modal sheet of its own navigation stack.
|
|
|
|
|
///
|
|
|
|
|
/// The services attached to the feature and the transcription shown in the sheet live in the view's ``Model``; the view itself only renders it and
|
|
|
|
|
/// forwards the feature's output and the sheet's dismissal. The navigation titles of the stacks are localized through the app's string catalog.
|
|
|
|
|
struct ContentView: View {
|
|
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
/// The model that owns the attached services and the transcription presented in the modal sheet.
|
|
|
|
|
@State private var model = Model()
|
|
|
|
|
|
|
|
|
|
// MARK: Body
|
|
|
|
|
|
2026-07-04 12:59:18 +02:00
|
|
|
/// The content of the view: a navigation stack with the recording feature's view, attached to the model's services, with a toolbar picker
|
2026-07-04 13:23:42 +02:00
|
|
|
/// for the locale of the spoken language to transcribe, and a modal sheet presenting the transcribed text of every processed recording —
|
|
|
|
|
/// or a content unavailable message when the transcription is empty — closable through its toolbar button or a swipe.
|
2026-07-04 10:32:59 +02:00
|
|
|
var body: some View {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
RecordingView(
|
|
|
|
|
recorder: model.recorder,
|
2026-07-04 12:11:24 +02:00
|
|
|
transcriber: model.transcriber,
|
|
|
|
|
locale: $model.locale,
|
|
|
|
|
) { transcription in
|
|
|
|
|
model.received(transcription)
|
2026-07-04 10:32:59 +02:00
|
|
|
}
|
|
|
|
|
.navigationTitle("view.recording.navigation.title")
|
|
|
|
|
#if !os(macOS)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
|
#endif
|
2026-07-04 12:59:18 +02:00
|
|
|
.toolbar {
|
|
|
|
|
ToolbarItem(placement: .primaryAction) {
|
|
|
|
|
Menu {
|
|
|
|
|
Picker(
|
|
|
|
|
"view.recording.picker.locale.title",
|
|
|
|
|
selection: $model.locale
|
|
|
|
|
) {
|
|
|
|
|
ForEach(
|
|
|
|
|
model.locales,
|
|
|
|
|
id: \.self
|
|
|
|
|
) {
|
|
|
|
|
Text(model.name(for: $0))
|
|
|
|
|
.tag($0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.pickerStyle(.inline)
|
|
|
|
|
} label: {
|
|
|
|
|
Label(
|
|
|
|
|
"view.recording.picker.locale.title",
|
|
|
|
|
systemImage: "globe"
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
.disabled(model.locales.isEmpty)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.task {
|
|
|
|
|
await model.load()
|
|
|
|
|
}
|
2026-07-04 10:32:59 +02:00
|
|
|
}
|
|
|
|
|
.sheet(item: $model.transcription) { transcription in
|
|
|
|
|
NavigationStack {
|
2026-07-04 13:23:42 +02:00
|
|
|
Group {
|
|
|
|
|
if transcription.isEmpty {
|
|
|
|
|
ContentUnavailableView(
|
|
|
|
|
"view.transcription.unavailable.title",
|
|
|
|
|
systemImage: "text.page.slash",
|
|
|
|
|
description: Text("view.transcription.unavailable.description")
|
2026-07-04 10:32:59 +02:00
|
|
|
)
|
2026-07-04 13:23:42 +02:00
|
|
|
} else {
|
|
|
|
|
ScrollView {
|
|
|
|
|
Text(transcription.text)
|
|
|
|
|
.font(.body)
|
|
|
|
|
.fontWeight(.regular)
|
|
|
|
|
.foregroundStyle(.primary)
|
|
|
|
|
.frame(
|
|
|
|
|
maxWidth: .infinity,
|
|
|
|
|
alignment: .leading
|
|
|
|
|
)
|
|
|
|
|
.padding()
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-04 10:32:59 +02:00
|
|
|
}
|
|
|
|
|
.navigationTitle("view.transcription.navigation.title")
|
|
|
|
|
#if !os(macOS)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
|
#endif
|
|
|
|
|
.toolbar {
|
|
|
|
|
Button(role: .close) {
|
|
|
|
|
model.dismissed()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.presentationDetents([.medium, .large])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Previews
|
|
|
|
|
|
|
|
|
|
#Preview(
|
|
|
|
|
"Content view"
|
|
|
|
|
) {
|
|
|
|
|
ContentView()
|
|
|
|
|
}
|