Commit 6965ce596b
6965ce596bf48e14e99af05c7f0a6361d6d26ac1
parent: b09c86e2b0
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-23 04:49 UTC
Share refusal handling for repo lists and the issue/MR edit sheet
Layout: unified · split
gitbay/Networking/GitbayClient.swift
+13
| @@ -188,6 +188,19 @@ nonisolated final class GitbayClient: Sendable { |
| 188 | _ = try await run(argv, stdin: stdin, as: NoPayload.self) |
188 | _ = try await run(argv, stdin: stdin, as: NoPayload.self) |
| 189 | } |
189 | } |
| 190 | |
190 | |
| |
191 | /// Run a command the user typed the input for: nil when it ran, else |
| |
192 | /// the message to show for its refusal. |
| |
193 | func refusal(running argv: [String], stdin: String? = nil) async -> String? { |
| |
194 | do { |
| |
195 | try await run(argv, stdin: stdin) |
| |
196 | return nil |
| |
197 | } catch let error as GitbayError { |
| |
198 | return error.messageForTypedInput |
| |
199 | } catch { |
| |
200 | return GitbayError.transport(error).userFacingMessage |
| |
201 | } |
| |
202 | } |
| |
203 | |
| 191 | // MARK: - Transport |
204 | // MARK: - Transport |
| 192 | |
205 | |
| 193 | private func perform( |
206 | private func perform( |
gitbay/Repos/RepoCredentials.swift
+6 −20
| @@ -45,19 +45,12 @@ final class BuildSecretsViewModel { |
| 45 | working = true |
45 | working = true |
| 46 | actionError = nil |
46 | actionError = nil |
| 47 | defer { working = false } |
47 | defer { working = false } |
| 48 | do { |
48 | let refusal = await client.refusal(running: argv, stdin: stdin) |
| 49 | try await client.run(argv, stdin: stdin) |
49 | actionError = refusal |
| 50 | await load() |
| |
| 51 | return true |
| |
| 52 | } catch let error as GitbayError { |
| |
| 53 | actionError = error.messageForTypedInput |
| |
| 54 | } catch { |
| |
| 55 | actionError = GitbayError.transport(error).userFacingMessage |
| |
| 56 | } |
| |
| 57 | // A refusal may mean the list changed elsewhere, e.g. a row |
50 | // A refusal may mean the list changed elsewhere, e.g. a row |
| 58 | // removed from another device. |
51 | // removed from another device. |
| 59 | await load() |
52 | await load() |
| 60 | return false |
53 | return refusal == nil |
| 61 | } |
54 | } |
| 62 | } |
55 | } |
| 63 | |
56 | |
| @@ -128,18 +121,11 @@ final class DeployKeysViewModel { |
| 128 | working = true |
121 | working = true |
| 129 | actionError = nil |
122 | actionError = nil |
| 130 | defer { working = false } |
123 | defer { working = false } |
| 131 | do { |
124 | let refusal = await client.refusal(running: argv, stdin: stdin) |
| 132 | try await client.run(argv, stdin: stdin) |
125 | actionError = refusal |
| 133 | await load() |
| |
| 134 | return true |
| |
| 135 | } catch let error as GitbayError { |
| |
| 136 | actionError = error.messageForTypedInput |
| |
| 137 | } catch { |
| |
| 138 | actionError = GitbayError.transport(error).userFacingMessage |
| |
| 139 | } |
| |
| 140 | // A refusal may mean the list changed elsewhere, e.g. a row |
126 | // A refusal may mean the list changed elsewhere, e.g. a row |
| 141 | // removed from another device. |
127 | // removed from another device. |
| 142 | await load() |
128 | await load() |
| 143 | return false |
129 | return refusal == nil |
| 144 | } |
130 | } |
| 145 | } |
131 | } |
gitbay/Repos/RepoMirrorsDomains.swift
+3 −10
| @@ -75,19 +75,12 @@ final class MirrorsViewModel { |
| 75 | working = true |
75 | working = true |
| 76 | actionError = nil |
76 | actionError = nil |
| 77 | defer { working = false } |
77 | defer { working = false } |
| 78 | do { |
78 | let refusal = await client.refusal(running: argv, stdin: stdin) |
| 79 | try await client.run(argv, stdin: stdin) |
79 | actionError = refusal |
| 80 | await load() |
| |
| 81 | return true |
| |
| 82 | } catch let error as GitbayError { |
| |
| 83 | actionError = error.messageForTypedInput |
| |
| 84 | } catch { |
| |
| 85 | actionError = GitbayError.transport(error).userFacingMessage |
| |
| 86 | } |
| |
| 87 | // A refusal may mean the list changed: a claim that expired is |
80 | // A refusal may mean the list changed: a claim that expired is |
| 88 | // removed by the verify that finds it so. |
81 | // removed by the verify that finds it so. |
| 89 | await load() |
82 | await load() |
| 90 | return false |
83 | return refusal == nil |
| 91 | } |
84 | } |
| 92 | } |
85 | } |
| 93 | |
86 | |
gitbay/Views/Issues/IssueView.swift
+2 −14
| @@ -51,20 +51,8 @@ struct IssueView: View { |
| 51 | .navigationBarTitleDisplayMode(.inline) |
51 | .navigationBarTitleDisplayMode(.inline) |
| 52 | .toolbar { toolbar } |
52 | .toolbar { toolbar } |
| 53 | .sheet(isPresented: $editing) { |
53 | .sheet(isPresented: $editing) { |
| 54 | ComposeSheet( |
54 | ComposeSheet(editing: model, heading: "Edit #\(model.number)", title: $draftTitle, |
| 55 | heading: "Edit #\(model.number)", |
55 | bodyText: $draftBody, format: $draftFormat) { editing = false } |
| 56 | submitLabel: "Save", |
| |
| 57 | working: model.working, |
| |
| 58 | errorMessage: model.actionError, |
| |
| 59 | title: $draftTitle, |
| |
| 60 | bodyText: $draftBody, |
| |
| 61 | format: $draftFormat |
| |
| 62 | ) { |
| |
| 63 | Task { |
| |
| 64 | await model.edit(title: draftTitle, body: draftBody, format: draftFormat) |
| |
| 65 | if model.actionError == nil { editing = false } |
| |
| 66 | } |
| |
| 67 | } |
| |
| 68 | } |
56 | } |
| 69 | .task { await model.load() } |
57 | .task { await model.load() } |
| 70 | .refreshable { await model.load() } |
58 | .refreshable { await model.load() } |
gitbay/Views/MRs/MRView.swift
+2 −14
| @@ -162,20 +162,8 @@ struct MRView: View { |
| 162 | } |
162 | } |
| 163 | } |
163 | } |
| 164 | .sheet(isPresented: $editing) { |
164 | .sheet(isPresented: $editing) { |
| 165 | ComposeSheet( |
165 | ComposeSheet(editing: model, heading: "Edit !\(model.number)", title: $draftTitle, |
| 166 | heading: "Edit !\(model.number)", |
166 | bodyText: $draftBody, format: $draftFormat) { editing = false } |
| 167 | submitLabel: "Save", |
| |
| 168 | working: model.working, |
| |
| 169 | errorMessage: model.actionError, |
| |
| 170 | title: $draftTitle, |
| |
| 171 | bodyText: $draftBody, |
| |
| 172 | format: $draftFormat |
| |
| 173 | ) { |
| |
| 174 | Task { |
| |
| 175 | await model.edit(title: draftTitle, body: draftBody, format: draftFormat) |
| |
| 176 | if model.actionError == nil { editing = false } |
| |
| 177 | } |
| |
| 178 | } |
| |
| 179 | } |
167 | } |
| 180 | } |
168 | } |
| 181 | |
169 | |
gitbay/Views/Shared/ComposeSheet.swift
+28
| @@ -102,3 +102,31 @@ struct ComposeSheet: View { |
| 102 | } |
102 | } |
| 103 | } |
103 | } |
| 104 | } |
104 | } |
| |
105 | |
| |
106 | /// A model whose item's title and body can be edited. |
| |
107 | @MainActor |
| |
108 | protocol TextEditable { |
| |
109 | var working: Bool { get } |
| |
110 | var actionError: String? { get } |
| |
111 | func edit(title: String, body: String, format: String?) async |
| |
112 | } |
| |
113 | |
| |
114 | extension IssueDetailViewModel: TextEditable {} |
| |
115 | extension MRDetailViewModel: TextEditable {} |
| |
116 | |
| |
117 | extension ComposeSheet { |
| |
118 | /// Editing an issue's or merge request's title and body; `saved` runs |
| |
119 | /// once the edit is accepted. |
| |
120 | init(editing model: some TextEditable, heading: String, title: Binding<String>, |
| |
121 | bodyText: Binding<String>, format: Binding<String>, saved: @escaping () -> Void) { |
| |
122 | self.init(heading: heading, submitLabel: "Save", working: model.working, |
| |
123 | errorMessage: model.actionError, title: title, bodyText: bodyText, |
| |
124 | format: format) { |
| |
125 | Task { |
| |
126 | await model.edit(title: title.wrappedValue, body: bodyText.wrappedValue, |
| |
127 | format: format.wrappedValue) |
| |
128 | if model.actionError == nil { saved() } |
| |
129 | } |
| |
130 | } |
| |
131 | } |
| |
132 | } |