Files
attendi/Apps/Attendi/View Models/ContentViewModel.swift
T

48 lines
1.5 KiB
Swift
Raw Normal View History

import Foundation
import Observation
import Recording
extension ContentView {
/// The observable model that drives ``ContentView``.
///
/// The model owns the recording and transcribing services attached to the recording feature, and holds the transcription currently
/// presented in the view's modal sheet: ``received(_:)`` wraps the transcribed text of a processed recording for presentation, and
/// ``dismissed()`` clears it when the sheet closes.
@MainActor
@Observable
final class Model {
// MARK: Properties
/// The transcription currently presented in the modal sheet, or `nil` when none is shown.
var transcription: Transcription?
/// The service that captures the audio from the device's microphone.
@ObservationIgnored
let recorder = AudioRecordingService()
/// The service that transcribes the recorded audio into text on device.
@ObservationIgnored
let transcriber = AudioTranscribingService()
// MARK: Methods
/// Handles the transcribed text of a processed recording, presenting it in the modal sheet.
///
/// - Parameter text: The transcribed text of the processed recording.
func received(
_ text: String
) {
transcription = .init(text: text)
}
/// Handles the dismissal of the modal sheet.
func dismissed() {
transcription = nil
}
}
}