Commit 9e886c16d7

9e886c16d7284deb2902554518d1ed8accedbe8d

parent: 886645fa08

Verified · cmc ci/accessibility: success

cmc <hello@cleberg.net> · 2026-10-23 06:22 UTC

SubmitToolbar and createFlow; Qlty filters for the remaining shapes

- SubmitToolbar for the paste, ticket, repository and tracker sheets.
- createFlow for the paste and repository lists' create-then-open flow.
- Qlty: leave the widget's own decodeDateString, the paging view
  models' loadMore...IfNeeded and calls to the shared load-state views
  out of duplication.

Layout: unified · split

.qlty/qlty.toml +10 −1
@@ -47,7 +47,16 @@ enabled = false
4747
4848# Exhaustive switch-over-enum lookup tables share shape but not content.
4949[language.swift.smells.duplication]
50filter_patterns = ["(import_declaration _)", "(switch_statement _)"]
50# The widget extension is its own target with its own decodeDateString; each paging view model
51# owns its cursor state in loadMore...IfNeeded; calls to the shared load-state views differ only in
52# their arguments.
53filter_patterns = [
54 "(import_declaration _)",
55 "(switch_statement _)",
56 "(function_declaration name: (simple_identifier) @_n (#eq? @_n \"decodeDateString\"))",
57 "(function_declaration name: (simple_identifier) @_n (#match? @_n \"^loadMore[A-Za-z]*IfNeeded$\"))",
58 "(call_expression (simple_identifier) @_n (#match? @_n \"^(SearchableListState|SRHTLoadStateView)$\"))",
59]
5160
5261# tree-sitter-swift nests each `else if` inside the previous branch, so a one-line `if` in the
5362# fourth branch of a flat chain reports level 5.
Hutch/Views/Pastes/PasteListView.swift +20 −43
@@ -11,33 +11,18 @@ struct PasteListView: View {
1111 var body: some View {
1212 ModelContent(model: viewModel, loadingMessage: "Loading pastes…") { content($0) }
1313 .navigationTitle("Pastes")
14 .toolbar {
15 if viewModel != nil {
16 AddToolbarItem(label: "Create paste") {
17 showCreatePasteSheet = true
18 }
19 }
20 }
21 .sheet(isPresented: $showCreatePasteSheet) {
22 if let viewModel {
23 CreatePasteSheet(viewModel: viewModel) { paste in
24 showCreatePasteSheet = false
25 createdPaste = paste
14 .createFlow(viewModel, label: "Create paste", isPresented: $showCreatePasteSheet, created: $createdPaste) {
15 CreatePasteSheet(viewModel: $0, onCreated: $1)
16 } destination: { createdPaste in
17 PasteDetailView(
18 paste: createdPaste,
19 onUpdated: { updated in
20 viewModel?.upsertPaste(updated)
21 },
22 onDeleted: { id in
23 viewModel?.removePaste(id: id)
2624 }
27 }
28 }
29 .navigationDestination(isPresented: .isPresent($createdPaste)) {
30 if let createdPaste {
31 PasteDetailView(
32 paste: createdPaste,
33 onUpdated: { updated in
34 viewModel?.upsertPaste(updated)
35 },
36 onDeleted: { id in
37 viewModel?.removePaste(id: id)
38 }
39 )
40 }
25 )
4126 }
4227 .task {
4328 if viewModel == nil {
@@ -312,25 +297,17 @@ private struct CreatePasteSheet: View {
312297 .navigationTitle("New Paste")
313298 .navigationBarTitleDisplayMode(.inline)
314299 .toolbar {
315 ToolbarItem(placement: .cancellationAction) {
316 Button("Cancel") { dismiss() }
317 }
318 ToolbarItem(placement: .confirmationAction) {
319 Button {
320 Task {
321 if let paste = await viewModel.createPaste(files: files, visibility: visibility) {
322 onCreated(paste)
323 }
324 }
325 } label: {
326 if viewModel.isCreatingPaste {
327 ProgressView()
328 .controlSize(.small)
329 } else {
330 Text("Create Paste")
300 SubmitToolbar(
301 title: "Create Paste",
302 isWorking: viewModel.isCreatingPaste,
303 isDisabled: !hasValidContent || viewModel.isCreatingPaste,
304 cancel: { dismiss() }
305 ) {
306 Task {
307 if let paste = await viewModel.createPaste(files: files, visibility: visibility) {
308 onCreated(paste)
331309 }
332310 }
333 .disabled(!hasValidContent || viewModel.isCreatingPaste)
334311 }
335312 }
336313 }
Hutch/Views/Repositories/RepositoryListView.swift +25 −48
@@ -11,32 +11,17 @@ struct RepositoryListView: View {
1111 var body: some View {
1212 ModelContent(model: viewModel, loadingMessage: "Loading repositories…") { listContent($0) }
1313 .navigationTitle("Repositories")
14 .toolbar {
15 if viewModel != nil {
16 AddToolbarItem(label: "Create repository") {
17 showCreateRepositorySheet = true
18 }
19 }
20 }
21 .sheet(isPresented: $showCreateRepositorySheet) {
22 if let viewModel {
23 CreateRepositorySheet(viewModel: viewModel) { repository in
24 showCreateRepositorySheet = false
25 createdRepository = repository
26 }
27 }
28 }
29 .navigationDestination(isPresented: .isPresent($createdRepository)) {
30 if let createdRepository {
31 RepositoryDetailView(
32 repository: createdRepository,
33 onRepositoryUpdated: { updatedRepository in
34 self.createdRepository = updatedRepository
35 viewModel?.updateRepository(updatedRepository)
36 }
37 ) {
38 viewModel?.removeRepository(id: createdRepository.id)
14 .createFlow(viewModel, label: "Create repository", isPresented: $showCreateRepositorySheet, created: $createdRepository) {
15 CreateRepositorySheet(viewModel: $0, onCreated: $1)
16 } destination: { createdRepository in
17 RepositoryDetailView(
18 repository: createdRepository,
19 onRepositoryUpdated: { updatedRepository in
20 self.createdRepository = updatedRepository
21 viewModel?.updateRepository(updatedRepository)
3922 }
23 ) {
24 viewModel?.removeRepository(id: createdRepository.id)
4025 }
4126 }
4227 .task {
@@ -243,31 +228,23 @@ private struct CreateRepositorySheet: View {
243228 .navigationTitle(service == .git ? "New Git Repository" : "New Mercurial Repository")
244229 .navigationBarTitleDisplayMode(.inline)
245230 .toolbar {
246 ToolbarItem(placement: .cancellationAction) {
247 Button("Cancel") { dismiss() }
248 }
249 ToolbarItem(placement: .confirmationAction) {
250 Button {
251 Task {
252 if let repository = await viewModel.createRepository(
253 service: service,
254 name: name,
255 description: description,
256 visibility: visibility,
257 cloneURL: cloneURL
258 ) {
259 onCreated(repository)
260 }
261 }
262 } label: {
263 if viewModel.isCreatingRepository {
264 ProgressView()
265 .controlSize(.small)
266 } else {
267 Text("Create")
231 SubmitToolbar(
232 title: "Create",
233 isWorking: viewModel.isCreatingRepository,
234 isDisabled: name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isCreatingRepository,
235 cancel: { dismiss() }
236 ) {
237 Task {
238 if let repository = await viewModel.createRepository(
239 service: service,
240 name: name,
241 description: description,
242 visibility: visibility,
243 cloneURL: cloneURL
244 ) {
245 onCreated(repository)
268246 }
269247 }
270 .disabled(name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isCreatingRepository)
271248 }
272249 }
273250 }
Hutch/Views/Shared/ModelContent.swift +34
@@ -30,3 +30,37 @@ struct AddToolbarItem: ToolbarContent {
3030 }
3131 }
3232}
33
34extension View {
35 /// A + button, once `model` exists, that presents `sheet`. The sheet calls back with what it
36 /// created, which closes it and pushes `destination`.
37 func createFlow<Model, Item, Sheet: View, Destination: View>(
38 _ model: Model?,
39 label: LocalizedStringKey,
40 isPresented: Binding<Bool>,
41 created: Binding<Item?>,
42 @ViewBuilder sheet: @escaping (Model, @escaping (Item) -> Void) -> Sheet,
43 @ViewBuilder destination: @escaping (Item) -> Destination
44 ) -> some View {
45 toolbar {
46 if model != nil {
47 AddToolbarItem(label: label) {
48 isPresented.wrappedValue = true
49 }
50 }
51 }
52 .sheet(isPresented: isPresented) {
53 if let model {
54 sheet(model) { item in
55 isPresented.wrappedValue = false
56 created.wrappedValue = item
57 }
58 }
59 }
60 .navigationDestination(isPresented: .isPresent(created)) {
61 if let item = created.wrappedValue {
62 destination(item)
63 }
64 }
65 }
66}
Hutch/Views/Shared/SubmitToolbar.swift added +27
@@ -0,0 +1,27 @@
1import SwiftUI
2
3/// Cancel, and a confirm button that shows a spinner in place of its title while `isWorking`.
4struct SubmitToolbar: ToolbarContent {
5 let title: LocalizedStringKey
6 let isWorking: Bool
7 let isDisabled: Bool
8 let cancel: () -> Void
9 let submit: () -> Void
10
11 var body: some ToolbarContent {
12 ToolbarItem(placement: .cancellationAction) {
13 Button("Cancel", action: cancel)
14 }
15 ToolbarItem(placement: .confirmationAction) {
16 Button(action: submit) {
17 if isWorking {
18 ProgressView()
19 .controlSize(.small)
20 } else {
21 Text(title)
22 }
23 }
24 .disabled(isDisabled)
25 }
26 }
27}
Hutch/Views/Tickets/TicketListView.swift +9 −17
@@ -658,25 +658,17 @@ private struct CreateTicketSheet: View {
658658 .navigationTitle("New Ticket")
659659 .navigationBarTitleDisplayMode(.inline)
660660 .toolbar {
661 ToolbarItem(placement: .cancellationAction) {
662 Button("Cancel") { dismiss() }
663 }
664 ToolbarItem(placement: .confirmationAction) {
665 Button {
666 Task {
667 if let ticket = await viewModel.createTicket(subject: subject, body: descriptionText) {
668 onCreated(ticket)
669 }
670 }
671 } label: {
672 if viewModel.isCreatingTicket {
673 ProgressView()
674 .controlSize(.small)
675 } else {
676 Text("Create Ticket")
661 SubmitToolbar(
662 title: "Create Ticket",
663 isWorking: viewModel.isCreatingTicket,
664 isDisabled: subject.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isCreatingTicket,
665 cancel: { dismiss() }
666 ) {
667 Task {
668 if let ticket = await viewModel.createTicket(subject: subject, body: descriptionText) {
669 onCreated(ticket)
677670 }
678671 }
679 .disabled(subject.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isCreatingTicket)
680672 }
681673 }
682674 }
Hutch/Views/Tickets/TrackerManagementView.swift +17 −25
@@ -1026,34 +1026,26 @@ private struct TrackerDefaultACLEditorSheet: View {
10261026 .navigationTitle("Default ACL")
10271027 .navigationBarTitleDisplayMode(.inline)
10281028 .toolbar {
1029 ToolbarItem(placement: .cancellationAction) {
1030 Button("Cancel") { dismiss() }
1031 }
1032 ToolbarItem(placement: .confirmationAction) {
1033 Button {
1034 Task {
1035 let didSave = await onSave(
1036 TrackerACLPermissions(
1037 browse: browse,
1038 submit: submit,
1039 comment: comment,
1040 edit: edit,
1041 triage: triage
1042 )
1029 SubmitToolbar(
1030 title: "Save",
1031 isWorking: isSaving,
1032 isDisabled: isSaving,
1033 cancel: { dismiss() }
1034 ) {
1035 Task {
1036 let didSave = await onSave(
1037 TrackerACLPermissions(
1038 browse: browse,
1039 submit: submit,
1040 comment: comment,
1041 edit: edit,
1042 triage: triage
10431043 )
1044 if didSave {
1045 dismiss()
1046 }
1047 }
1048 } label: {
1049 if isSaving {
1050 ProgressView()
1051 .controlSize(.small)
1052 } else {
1053 Text("Save")
1044 )
1045 if didSave {
1046 dismiss()
10541047 }
10551048 }
1056 .disabled(isSaving)
10571049 }
10581050 }
10591051 }