39 lines · 1.5 KB · SwiftRaw
import SwiftUI/// A list declaration's one row act. Its question is the command's question;/// tapping it cannot also open the slip beside it.struct RecordRowCommandChip: View { let command: RecordCommand let identifier: String let run: () async throws -> Void @State private var confirming: RecordCommand? @State private var busy = false @Environment(ToastCenter.self) private var toasts var body: some View { Button { if command.asksFirst { confirming = command } else { perform() } } label: { Text(command.label).paperBody(13, ink: command.asksFirst ? .red : .ink) .fixedSize(horizontal: false, vertical: true) .padding(.horizontal, 10).padding(.vertical, 8) .background(PaperDye.straw.fill, in: RoundedRectangle(cornerRadius: 3)) } .buttonStyle(.plain) .disabled(busy) .accessibilityIdentifier(identifier) .confirmDecision(item: $confirming, title: { $0.label }, message: { $0.confirm ?? ShellLines.line("record", "changes_your_copy") }, confirmLabel: { $0.label }, identifier: identifier + "-confirm", onConfirm: { _ in perform() }) } private func perform() { guard !busy else { return } busy = true Task { defer { busy = false } do { try await run() } catch { toasts.show(RecordCommand.refusal(error), tone: .error) } } }}