a native ios client for gitbay

client ios swift

https://gitbay.org

gitbay/Views/Repos/FileEditSheet.swift

ui-smoke
gitbay-ios/gitbay/Views/Repos/FileEditSheet.swift history · blame · raw

66 lines · 2387 bytes

 1import SwiftUI
 2
 3/// Edit one file and commit it. The commit is unsigned  the server
 4/// authors it  so a repository requiring signatures refuses, and the
 5/// refusal is what the sheet shows.
 6struct FileEditSheet: View {
 7
 8    let model: FileViewModel
 9    let branch: String
10    @Binding var content: String
11    let onCommitted: () -> Void
12
13    @Environment(\.dismiss) private var dismiss
14    @State private var message = ""
15
16    var body: some View {
17        NavigationStack {
18            Form {
19                Section {
20                    TextEditor(text: $content)
21                        .font(.gbMono(.caption))
22                        .frame(minHeight: 260)
23                        .autocorrectionDisabled()
24                        .textInputAutocapitalization(.never)
25                        .accessibilityIdentifier("file-edit-content")
26                } header: {
27                    Text(model.fileName)
28                } footer: {
29                    Text("Commits to \(branch) as an unsigned commit.")
30                }
31                Section("Message") {
32                    TextField("edit \(model.fileName)", text: $message)
33                        .autocorrectionDisabled()
34                        .accessibilityIdentifier("file-edit-message")
35                }
36                if let error = model.actionError {
37                    Section {
38                        GBNotice(error, .gbWarn)
39                    }
40                }
41            }
42            .navigationTitle("Edit")
43            .navigationBarTitleDisplayMode(.inline)
44            .toolbar {
45                ToolbarItem(placement: .cancellationAction) {
46                    Button("Cancel") { dismiss() }
47                }
48                ToolbarItem(placement: .confirmationAction) {
49                    if model.working {
50                        ProgressView()
51                    } else {
52                        Button("Commit") {
53                            Task {
54                                if await model.commit(content: content, message: message) {
55                                    onCommitted()
56                                }
57                            }
58                        }
59                        .accessibilityIdentifier("file-edit-commit")
60                    }
61                }
62            }
63            .interactiveDismissDisabled(model.working)
64        }
65    }
66}