oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3/// A foreground response keeps its feedback above pane and inspector changes.
4public struct NotificationActionPresenter: ViewModifier {
5 let model: EquipoAppModel
6 public init(model: EquipoAppModel) { self.model = model }
7 public func body(content: Content) -> some View {
8 content.sheet(isPresented: Binding(get: { !model.notificationActions.notices.isEmpty }, set: { showing in
9 if !showing { model.notificationActions.notices = [] }
10 })) {
11 if let notice = model.notificationActions.notices.first {
12 NotificationActionView(dispatcher: model.notificationActions, notice: notice)
13 .id(notice.id)
14 }
15 }
16 }
17}
18
19struct NotificationActionView: View {
20 let dispatcher: NotificationDispatcher
21 @Bindable var notice: NotificationNotice
22 var body: some View {
23 NavigationStack {
24 Group {
25 if let context = notice.context { TaskScreen(context: context).modifier(SettingsSheetPresenter(session: context.detail.session)) }
26 else {
27 ScrollView {
28 VStack(alignment: .leading, spacing: 16) {
29 if let card = notice.card {
30 Text(verbatim: card.question).font(.headline).textSelection(.enabled)
31 if let options = card.options, !options.isEmpty {
32 ForEach(options, id: \.self) { option in
33 Button { Task { await dispatcher.answer(notice, choice: option) } } label: { Text(verbatim: option) }
34 .buttonStyle(.bordered).disabled(notice.busy || notice.uncertain)
35 }
36 } else {
37 // A held reply arrives pre-filled; it is sent only by this tap.
38 TextField(EquipoStrings.text("chat.card.answer"), text: $notice.choice, axis: .vertical)
39 .textFieldStyle(.roundedBorder).disabled(notice.busy || notice.uncertain)
40 Button(EquipoStrings.text("chat.card.answer")) { Task { await dispatcher.answer(notice, choice: notice.choice) } }
41 .disabled(notice.busy || notice.uncertain || notice.choice.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
42 }
43 }
44 if notice.card == nil, case .answer(let text) = notice.response.intent {
45 Text(verbatim: text).lineLimit(3).textSelection(.enabled)
46 }
47 if notice.busy { ProgressView().accessibilityLabel(EquipoStrings.text("work.details.task")) }
48 if let error = notice.error { Text(error).foregroundStyle(Palette.negative) }
49 if notice.canRetry {
50 Button(EquipoStrings.text("work.pause.try_again")) { Task { await dispatcher.retry(notice) } }.disabled(notice.busy)
51 }
52 }.padding(20).frame(maxWidth: .infinity, alignment: .leading)
53 }
54 }
55 }
56 .toolbar { ToolbarItem(placement: .cancellationAction) {
57 Button(EquipoStrings.text("chat.connections.dismiss")) { dispatcher.dismiss(notice.id) }
58 } }
59 }
60 .frame(minWidth: 300, minHeight: 300)
61 }
62}
63