Added a discard button and error handling to the RecordingView view in the Recording package target.

This commit is contained in:
2026-07-04 15:59:30 +02:00
parent 7ec49264e6
commit b0c6e25639
7 changed files with 339 additions and 14 deletions
@@ -108,6 +108,11 @@ extension RecordingView {
state == .processing
}
/// Whether the discard button should be visible.
var shouldShowDiscard: Bool {
state == .paused
}
/// Whether the send button should be visible.
var shouldShowSend: Bool {
state != .notRecording
@@ -126,8 +131,43 @@ extension RecordingView {
.formatted(.time(pattern: .minuteSecond(padMinuteToLength: 2)))
}
/// The elapsed recording time, spelled out in full units for assistive technologies.
var textTimerAccessible: String {
Duration
.seconds(elapsedSeconds)
.formatted(.units(
allowed: [.minutes, .seconds],
width: .wide
))
}
// MARK: Methods
/// Handles a press of the discard button.
///
/// Throws away a paused recording: it resets the timer, returns to the not-recording state, and stops the audio capture,
/// deleting the captured audio file. Does nothing in any other state.
func pressedDiscard() {
guard state == .paused else {
return
}
state = .notRecording
stopTimer()
accumulated = .zero
elapsedSeconds = 0
enqueueCapturer {
guard let audio = try? await self.capturer.stop() else {
return
}
try? FileManager.default.removeItem(at: audio)
}
}
/// Handles a press of the main button.
///
/// Starts a recording when idle, pauses an ongoing recording, or resumes a paused one starting and stopping the timer
@@ -213,7 +253,9 @@ private extension RecordingView.Model {
)
} catch {
transcription = nil
self.error = .transcriptionFailed
self.error = error as? AudioTranscribingError == .assetsNotInstalled
? .assetsUnavailable
: .transcriptionFailed
}
} catch {
transcription = nil