Commit fa473b2f8c
Verified · cmc ci/accessibility: success
Layout: unified · split
.qlty/qlty.toml +5
| @@ -48,3 +48,8 @@ enabled = false | ||
| 48 | 48 | # Exhaustive switch-over-enum lookup tables share shape but not content. |
| 49 | 49 | [language.swift.smells.duplication] |
| 50 | 50 | filter_patterns = ["(import_declaration _)", "(switch_statement _)"] |
| 51 | ||
| 52 | # tree-sitter-swift nests each `else if` inside the previous branch, so a one-line `if` in the | |
| 53 | # fourth branch of a flat chain reports level 5. | |
| 54 | [language.swift.smells.nested_control_flow] | |
| 55 | enabled = false | |
Hutch/Views/Builds/BuildDetailView.swift +7 −53
| @@ -17,13 +17,7 @@ struct BuildDetailView: View { | ||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | var body: some View { |
| 20 | Group { | |
| 21 | if let viewModel { | |
| 22 | detailContent(viewModel) | |
| 23 | } else { | |
| 24 | SRHTLoadingStateView(message: "Loading build…") | |
| 25 | } | |
| 26 | } | |
| 20 | ModelContent(model: viewModel, loadingMessage: "Loading build…") { detailContent($0) } | |
| 27 | 21 | .navigationTitle("Job #\(jobId)") |
| 28 | 22 | .navigationBarTitleDisplayMode(.inline) |
| 29 | 23 | .toolbar { |
| @@ -71,14 +65,7 @@ struct BuildDetailView: View { | ||
| 71 | 65 | } |
| 72 | 66 | } |
| 73 | 67 | } |
| 74 | .navigationDestination(isPresented: Binding( | |
| 75 | get: { rebuiltJobId != nil }, | |
| 76 | set: { isPresented in | |
| 77 | if !isPresented { | |
| 78 | rebuiltJobId = nil | |
| 79 | } | |
| 80 | } | |
| 81 | )) { | |
| 68 | .navigationDestination(isPresented: .isPresent($rebuiltJobId)) { | |
| 82 | 69 | if let rebuiltJobId { |
| 83 | 70 | BuildDetailView(jobId: rebuiltJobId) |
| 84 | 71 | } |
| @@ -91,14 +78,7 @@ struct BuildDetailView: View { | ||
| 91 | 78 | } |
| 92 | 79 | } |
| 93 | 80 | } |
| 94 | .sheet(isPresented: Binding( | |
| 95 | get: { selectedTaskName != nil }, | |
| 96 | set: { isPresented in | |
| 97 | if !isPresented { | |
| 98 | selectedTaskName = nil | |
| 99 | } | |
| 100 | } | |
| 101 | )) { | |
| 81 | .sheet(isPresented: .isPresent($selectedTaskName)) { | |
| 102 | 82 | if let selectedTaskName, let viewModel { |
| 103 | 83 | NavigationStack { |
| 104 | 84 | BuildTaskLogView(taskName: selectedTaskName, viewModel: viewModel) |
| @@ -530,36 +510,10 @@ private struct EditResubmitBuildSheet: View { | ||
| 530 | 510 | viewModel.dismissActionError() |
| 531 | 511 | } |
| 532 | 512 | .toolbar { |
| 533 | ToolbarItem(placement: .cancellationAction) { | |
| 534 | Button("Cancel") { | |
| 535 | viewModel.dismissActionError() | |
| 536 | dismiss() | |
| 537 | } | |
| 538 | } | |
| 539 | ToolbarItem(placement: .confirmationAction) { | |
| 540 | Button { | |
| 541 | Task { | |
| 542 | if let jobId = await viewModel.submitBuild( | |
| 543 | manifest: draft.manifest, | |
| 544 | tags: draft.tags, | |
| 545 | note: draft.note, | |
| 546 | secrets: draft.secrets, | |
| 547 | execute: draft.execute, | |
| 548 | visibility: draft.visibility | |
| 549 | ) { | |
| 550 | onSubmitted(jobId) | |
| 551 | } | |
| 552 | } | |
| 553 | } label: { | |
| 554 | if viewModel.isSubmittingEditedBuild { | |
| 555 | ProgressView() | |
| 556 | .controlSize(.small) | |
| 557 | } else { | |
| 558 | Text("Submit Build") | |
| 559 | } | |
| 560 | } | |
| 561 | .disabled(!draft.hasManifest || viewModel.isSubmittingEditedBuild) | |
| 562 | } | |
| 513 | BuildDraftToolbar(draft: draft, submitter: viewModel, isSubmitting: viewModel.isSubmittingEditedBuild) { | |
| 514 | viewModel.dismissActionError() | |
| 515 | dismiss() | |
| 516 | } onSubmitted: { onSubmitted($0) } | |
| 563 | 517 | } |
| 564 | 518 | .themedList() |
| 565 | 519 | } |
Hutch/Views/Builds/BuildDraftForm.swift +55
| @@ -81,3 +81,58 @@ struct BuildDraftForm: View { | ||
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | ||
| 85 | /// Something a build draft can be submitted to, answering the new job's id. | |
| 86 | @MainActor | |
| 87 | protocol BuildSubmitting { | |
| 88 | func submitBuild( | |
| 89 | manifest: String, | |
| 90 | tags: [String], | |
| 91 | note: String, | |
| 92 | secrets: Bool, | |
| 93 | execute: Bool, | |
| 94 | visibility: Visibility | |
| 95 | ) async -> Int? | |
| 96 | } | |
| 97 | ||
| 98 | extension BuildListViewModel: BuildSubmitting {} | |
| 99 | extension BuildDetailViewModel: BuildSubmitting {} | |
| 100 | ||
| 101 | /// Cancel, and Submit Build once the draft has a manifest. | |
| 102 | struct BuildDraftToolbar: ToolbarContent { | |
| 103 | let draft: BuildDraft | |
| 104 | let submitter: any BuildSubmitting | |
| 105 | let isSubmitting: Bool | |
| 106 | let cancel: () -> Void | |
| 107 | let onSubmitted: (Int) -> Void | |
| 108 | ||
| 109 | var body: some ToolbarContent { | |
| 110 | ToolbarItem(placement: .cancellationAction) { | |
| 111 | Button("Cancel", action: cancel) | |
| 112 | } | |
| 113 | ToolbarItem(placement: .confirmationAction) { | |
| 114 | Button { | |
| 115 | Task { | |
| 116 | if let jobId = await submitter.submitBuild( | |
| 117 | manifest: draft.manifest, | |
| 118 | tags: draft.tags, | |
| 119 | note: draft.note, | |
| 120 | secrets: draft.secrets, | |
| 121 | execute: draft.execute, | |
| 122 | visibility: draft.visibility | |
| 123 | ) { | |
| 124 | onSubmitted(jobId) | |
| 125 | } | |
| 126 | } | |
| 127 | } label: { | |
| 128 | if isSubmitting { | |
| 129 | ProgressView() | |
| 130 | .controlSize(.small) | |
| 131 | } else { | |
| 132 | Text("Submit Build") | |
| 133 | } | |
| 134 | } | |
| 135 | .disabled(!draft.hasManifest || isSubmitting) | |
| 136 | } | |
| 137 | } | |
| 138 | } | |
Hutch/Views/Builds/BuildListView.swift +8 −52
| @@ -17,13 +17,7 @@ struct BuildListView: View { | ||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | var body: some View { |
| 20 | Group { | |
| 21 | if let viewModel { | |
| 22 | listContent(viewModel) | |
| 23 | } else { | |
| 24 | SRHTLoadingStateView(message: "Loading builds…") | |
| 25 | } | |
| 26 | } | |
| 20 | ModelContent(model: viewModel, loadingMessage: "Loading builds…") { listContent($0) } | |
| 27 | 21 | .navigationTitle("Builds") |
| 28 | 22 | .toolbar { |
| 29 | 23 | if let viewModel { |
| @@ -86,13 +80,8 @@ struct BuildListView: View { | ||
| 86 | 80 | } |
| 87 | 81 | .accessibilityLabel("Build filters") |
| 88 | 82 | } |
| 89 | ToolbarItem(placement: .topBarTrailing) { | |
| 90 | Button { | |
| 91 | showSubmitSheet = true | |
| 92 | } label: { | |
| 93 | Image(systemName: "plus") | |
| 94 | } | |
| 95 | .accessibilityLabel("Submit build") | |
| 83 | AddToolbarItem(label: "Submit build") { | |
| 84 | showSubmitSheet = true | |
| 96 | 85 | } |
| 97 | 86 | } |
| 98 | 87 | } |
| @@ -107,14 +96,7 @@ struct BuildListView: View { | ||
| 107 | 96 | .navigationDestination(for: JobSummary.self) { job in |
| 108 | 97 | BuildDetailView(jobId: job.id) |
| 109 | 98 | } |
| 110 | .navigationDestination(isPresented: Binding( | |
| 111 | get: { submittedJobId != nil }, | |
| 112 | set: { isPresented in | |
| 113 | if !isPresented { | |
| 114 | submittedJobId = nil | |
| 115 | } | |
| 116 | } | |
| 117 | )) { | |
| 99 | .navigationDestination(isPresented: .isPresent($submittedJobId)) { | |
| 118 | 100 | if let submittedJobId { |
| 119 | 101 | BuildDetailView(jobId: submittedJobId) |
| 120 | 102 | } |
| @@ -329,36 +311,10 @@ private struct SubmitBuildSheet: View { | ||
| 329 | 311 | viewModelBindable.error = nil |
| 330 | 312 | } |
| 331 | 313 | .toolbar { |
| 332 | ToolbarItem(placement: .cancellationAction) { | |
| 333 | Button("Cancel") { | |
| 334 | viewModelBindable.error = nil | |
| 335 | dismiss() | |
| 336 | } | |
| 337 | } | |
| 338 | ToolbarItem(placement: .confirmationAction) { | |
| 339 | Button { | |
| 340 | Task { | |
| 341 | if let jobId = await viewModel.submitBuild( | |
| 342 | manifest: draft.manifest, | |
| 343 | tags: draft.tags, | |
| 344 | note: draft.note, | |
| 345 | secrets: draft.secrets, | |
| 346 | execute: draft.execute, | |
| 347 | visibility: draft.visibility | |
| 348 | ) { | |
| 349 | onSubmitted(jobId) | |
| 350 | } | |
| 351 | } | |
| 352 | } label: { | |
| 353 | if viewModel.isSubmitting { | |
| 354 | ProgressView() | |
| 355 | .controlSize(.small) | |
| 356 | } else { | |
| 357 | Text("Submit Build") | |
| 358 | } | |
| 359 | } | |
| 360 | .disabled(!draft.hasManifest || viewModel.isSubmitting) | |
| 361 | } | |
| 314 | BuildDraftToolbar(draft: draft, submitter: viewModel, isSubmitting: viewModel.isSubmitting) { | |
| 315 | viewModelBindable.error = nil | |
| 316 | dismiss() | |
| 317 | } onSubmitted: { onSubmitted($0) } | |
| 362 | 318 | } |
| 363 | 319 | } |
| 364 | 320 | } |
Hutch/Views/Home/HomeView.swift +3 −23
| @@ -15,13 +15,7 @@ struct HomeView: View { | ||
| 15 | 15 | @State private var isShowingSystemStatus = false |
| 16 | 16 | |
| 17 | 17 | var body: some View { |
| 18 | Group { | |
| 19 | if let viewModel { | |
| 20 | content(viewModel) | |
| 21 | } else { | |
| 22 | SRHTLoadingStateView(message: "Loading Home…") | |
| 23 | } | |
| 24 | } | |
| 18 | ModelContent(model: viewModel, loadingMessage: "Loading Home…") { content($0) } | |
| 25 | 19 | .navigationTitle("Home") |
| 26 | 20 | .toolbar { |
| 27 | 21 | ToolbarItem(placement: .topBarTrailing) { |
| @@ -36,26 +30,12 @@ struct HomeView: View { | ||
| 36 | 30 | .accessibilityLabel("System status") |
| 37 | 31 | } |
| 38 | 32 | } |
| 39 | .navigationDestination(isPresented: Binding( | |
| 40 | get: { selectedPinnedProject != nil }, | |
| 41 | set: { isPresented in | |
| 42 | if !isPresented { | |
| 43 | selectedPinnedProject = nil | |
| 44 | } | |
| 45 | } | |
| 46 | )) { | |
| 33 | .navigationDestination(isPresented: .isPresent($selectedPinnedProject)) { | |
| 47 | 34 | if let selectedPinnedProject { |
| 48 | 35 | ProjectDetailView(project: selectedPinnedProject) |
| 49 | 36 | } |
| 50 | 37 | } |
| 51 | .navigationDestination(isPresented: Binding( | |
| 52 | get: { selectedPinnedUser != nil }, | |
| 53 | set: { isPresented in | |
| 54 | if !isPresented { | |
| 55 | selectedPinnedUser = nil | |
| 56 | } | |
| 57 | } | |
| 58 | )) { | |
| 38 | .navigationDestination(isPresented: .isPresent($selectedPinnedUser)) { | |
| 59 | 39 | if let selectedPinnedUser { |
| 60 | 40 | UserProfileView(user: selectedPinnedUser) |
| 61 | 41 | } |
Hutch/Views/Home/HomeViewModel.swift +43 −40
| @@ -819,7 +819,31 @@ final class HomeViewModel { | ||
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | private func fetchInboxMailingLists(forceRefresh: Bool) async throws -> [InboxMailingListReference] { |
| 822 | var subscriptions: [HomeInboxSubscription] = [] | |
| 822 | let subscriptions = try await fetchAllPages( | |
| 823 | service: .lists, | |
| 824 | query: Self.inboxSubscriptionsQuery, | |
| 825 | responseType: HomeInboxSubscriptionsResponse.self, | |
| 826 | page: { ($0.subscriptions.results, $0.subscriptions.cursor) }, | |
| 827 | cacheKey: { APICacheKeys.inboxSubscriptions(cursor: $0) }, | |
| 828 | ttl: APICacheTTLs.inboxSummary, | |
| 829 | forceRefresh: forceRefresh | |
| 830 | ) | |
| 831 | ||
| 832 | var seen = Set<String>() | |
| 833 | return subscriptions.compactMap(\.list).filter { seen.insert($0.rid).inserted } | |
| 834 | } | |
| 835 | ||
| 836 | /// Every page of a cursor-paged query, each read through the cache under `cacheKey(cursor)`. | |
| 837 | private func fetchAllPages<Response: Decodable, Item>( | |
| 838 | service: SRHTService, | |
| 839 | query: String, | |
| 840 | responseType _: Response.Type, | |
| 841 | page: (Response) -> (results: [Item], cursor: String?), | |
| 842 | cacheKey: (String?) -> String, | |
| 843 | ttl: TimeInterval, | |
| 844 | forceRefresh: Bool | |
| 845 | ) async throws -> [Item] { | |
| 846 | var items: [Item] = [] | |
| 823 | 847 | var cursor: String? |
| 824 | 848 | |
| 825 | 849 | while true { |
| @@ -829,26 +853,25 @@ final class HomeViewModel { | ||
| 829 | 853 | } |
| 830 | 854 | |
| 831 | 855 | let cached = try await client.executeCached( |
| 832 | service: .lists, | |
| 833 | query: Self.inboxSubscriptionsQuery, | |
| 856 | service: service, | |
| 857 | query: query, | |
| 834 | 858 | variables: variables.isEmpty ? nil : variables, |
| 835 | responseType: HomeInboxSubscriptionsResponse.self, | |
| 836 | cacheKey: APICacheKeys.inboxSubscriptions(cursor: cursor), | |
| 859 | responseType: Response.self, | |
| 860 | cacheKey: cacheKey(cursor), | |
| 837 | 861 | resourceType: .ticketList, |
| 838 | ttl: APICacheTTLs.inboxSummary, | |
| 862 | ttl: ttl, | |
| 839 | 863 | policy: forceRefresh ? .refreshIgnoringCache : .cacheFirstThenRefresh |
| 840 | 864 | ) |
| 841 | let response = cached.value | |
| 865 | let (results, nextCursor) = page(cached.value) | |
| 842 | 866 | |
| 843 | subscriptions.append(contentsOf: response.subscriptions.results) | |
| 844 | guard let nextCursor = response.subscriptions.cursor else { | |
| 867 | items.append(contentsOf: results) | |
| 868 | guard let nextCursor else { | |
| 845 | 869 | break |
| 846 | 870 | } |
| 847 | 871 | cursor = nextCursor |
| 848 | 872 | } |
| 849 | 873 | |
| 850 | var seen = Set<String>() | |
| 851 | return subscriptions.compactMap(\.list).filter { seen.insert($0.rid).inserted } | |
| 874 | return items | |
| 852 | 875 | } |
| 853 | 876 | |
| 854 | 877 | private func fetchUnreadThreadSnapshot(for mailingList: InboxMailingListReference, forceRefresh: Bool) async throws -> HomeInboxUnreadSnapshot { |
| @@ -934,35 +957,15 @@ final class HomeViewModel { | ||
| 934 | 957 | } |
| 935 | 958 | |
| 936 | 959 | private func fetchAllTrackers(forceRefresh: Bool) async throws -> [TrackerSummary] { |
| 937 | var allTrackers: [TrackerSummary] = [] | |
| 938 | var cursor: String? | |
| 939 | ||
| 940 | while true { | |
| 941 | var variables: [String: any Sendable] = [:] | |
| 942 | if let cursor { | |
| 943 | variables["cursor"] = cursor | |
| 944 | } | |
| 945 | ||
| 946 | let cached = try await client.executeCached( | |
| 947 | service: .todo, | |
| 948 | query: Self.trackersQuery, | |
| 949 | variables: variables.isEmpty ? nil : variables, | |
| 950 | responseType: HomeTrackersResponse.self, | |
| 951 | cacheKey: APICacheKeys.trackers(cursor: cursor), | |
| 952 | resourceType: .ticketList, | |
| 953 | ttl: APICacheTTLs.ticketList, | |
| 954 | policy: forceRefresh ? .refreshIgnoringCache : .cacheFirstThenRefresh | |
| 955 | ) | |
| 956 | let response = cached.value | |
| 957 | ||
| 958 | allTrackers.append(contentsOf: response.trackers.results) | |
| 959 | guard let nextCursor = response.trackers.cursor else { | |
| 960 | break | |
| 961 | } | |
| 962 | cursor = nextCursor | |
| 963 | } | |
| 964 | ||
| 965 | return allTrackers | |
| 960 | try await fetchAllPages( | |
| 961 | service: .todo, | |
| 962 | query: Self.trackersQuery, | |
| 963 | responseType: HomeTrackersResponse.self, | |
| 964 | page: { ($0.trackers.results, $0.trackers.cursor) }, | |
| 965 | cacheKey: { APICacheKeys.trackers(cursor: $0) }, | |
| 966 | ttl: APICacheTTLs.ticketList, | |
| 967 | forceRefresh: forceRefresh | |
| 968 | ) | |
| 966 | 969 | } |
| 967 | 970 | |
| 968 | 971 | private func fetchAssignedTickets(for trackers: [TrackerSummary], forceRefresh: Bool) async throws -> [HomeAssignedTicket] { |
Hutch/Views/Inbox/ThreadDetailView.swift +1 −7
| @@ -35,13 +35,7 @@ struct ThreadDetailView: View { | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | var body: some View { |
| 38 | Group { | |
| 39 | if let viewModel { | |
| 40 | content(viewModel) | |
| 41 | } else { | |
| 42 | SRHTLoadingStateView(message: "Loading thread…") | |
| 43 | } | |
| 44 | } | |
| 38 | ModelContent(model: viewModel, loadingMessage: "Loading thread…") { content($0) } | |
| 45 | 39 | .navigationTitle("Thread") |
| 46 | 40 | .navigationBarTitleDisplayMode(.inline) |
| 47 | 41 | .task(id: thread.id) { |
Hutch/Views/Lists/MailingListListView.swift +1 −7
| @@ -334,13 +334,7 @@ struct MailingListListView: View { | ||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | var body: some View { |
| 337 | Group { | |
| 338 | if let viewModel { | |
| 339 | content(viewModel) | |
| 340 | } else { | |
| 341 | SRHTLoadingStateView(message: "Loading mailing lists…") | |
| 342 | } | |
| 343 | } | |
| 337 | ModelContent(model: viewModel, loadingMessage: "Loading mailing lists…") { content($0) } | |
| 344 | 338 | .navigationTitle("Mailing Lists") |
| 345 | 339 | .task { |
| 346 | 340 | if viewModel == nil { |
Hutch/Views/Lookup/LookupView.swift +1 −7
| @@ -348,13 +348,7 @@ struct LookupView: View { | ||
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | var body: some View { |
| 351 | Group { | |
| 352 | if let viewModel { | |
| 353 | content(viewModel) | |
| 354 | } else { | |
| 355 | SRHTLoadingStateView(message: "Preparing lookup…") | |
| 356 | } | |
| 357 | } | |
| 351 | ModelContent(model: viewModel, loadingMessage: "Preparing lookup…") { content($0) } | |
| 358 | 352 | .navigationTitle("Look Up") |
| 359 | 353 | .task { |
| 360 | 354 | if viewModel == nil { |
Hutch/Views/More/AccountSwitcherView.swift +1 −8
| @@ -89,14 +89,7 @@ struct AccountSwitcherView: View { | ||
| 89 | 89 | } |
| 90 | 90 | .alert( |
| 91 | 91 | "Remove Account?", |
| 92 | isPresented: Binding( | |
| 93 | get: { pendingRemoval != nil }, | |
| 94 | set: { isPresented in | |
| 95 | if !isPresented { | |
| 96 | pendingRemoval = nil | |
| 97 | } | |
| 98 | } | |
| 99 | ) | |
| 92 | isPresented: .isPresent($pendingRemoval) | |
| 100 | 93 | ) { |
| 101 | 94 | Button("Cancel", role: .cancel) { |
| 102 | 95 | /* Dismiss only; removal uses the destructive button. */ |
Hutch/Views/More/ProfileView.swift +8 −37
| @@ -13,13 +13,7 @@ struct ProfileView: View { | ||
| 13 | 13 | @State private var pendingDestructiveAction: ProfileDestructiveAction? |
| 14 | 14 | |
| 15 | 15 | var body: some View { |
| 16 | Group { | |
| 17 | if let viewModel { | |
| 18 | profileContent(viewModel) | |
| 19 | } else { | |
| 20 | SRHTLoadingStateView(message: "Loading profile…") | |
| 21 | } | |
| 22 | } | |
| 16 | ModelContent(model: viewModel, loadingMessage: "Loading profile…") { profileContent($0) } | |
| 23 | 17 | .navigationTitle("Profile") |
| 24 | 18 | .task { |
| 25 | 19 | if viewModel == nil { |
| @@ -120,35 +114,12 @@ struct ProfileView: View { | ||
| 120 | 114 | Text(error) |
| 121 | 115 | } |
| 122 | 116 | } |
| 123 | .alert( | |
| 124 | pendingDestructiveAction?.title ?? "", | |
| 125 | isPresented: Binding( | |
| 126 | get: { pendingDestructiveAction != nil }, | |
| 127 | set: { isPresented in | |
| 128 | if !isPresented { | |
| 129 | pendingDestructiveAction = nil | |
| 130 | } | |
| 131 | } | |
| 132 | ) | |
| 133 | ) { | |
| 134 | Button("Cancel", role: .cancel) { | |
| 135 | /* Dismiss only; destructive action is separate. */ | |
| 136 | } | |
| 137 | Button(pendingDestructiveAction?.confirmationLabel ?? "Confirm", role: .destructive) { | |
| 138 | guard let action = pendingDestructiveAction else { return } | |
| 139 | pendingDestructiveAction = nil | |
| 140 | Task { | |
| 141 | switch action { | |
| 142 | case .deleteSSHKey(let key): | |
| 143 | await viewModel.deleteSSHKey(key) | |
| 144 | case .deletePGPKey(let key): | |
| 145 | await viewModel.deletePGPKey(key) | |
| 146 | } | |
| 147 | } | |
| 148 | } | |
| 149 | } message: { | |
| 150 | if let pendingDestructiveAction { | |
| 151 | Text(pendingDestructiveAction.message) | |
| 117 | .destructiveConfirmation($pendingDestructiveAction) { action in | |
| 118 | switch action { | |
| 119 | case .deleteSSHKey(let key): | |
| 120 | await viewModel.deleteSSHKey(key) | |
| 121 | case .deletePGPKey(let key): | |
| 122 | await viewModel.deletePGPKey(key) | |
| 152 | 123 | } |
| 153 | 124 | } |
| 154 | 125 | .refreshable { |
| @@ -713,7 +684,7 @@ private struct EditProfileSheet: View { | ||
| 713 | 684 | } |
| 714 | 685 | } |
| 715 | 686 | |
| 716 | private enum ProfileDestructiveAction { | |
| 687 | private enum ProfileDestructiveAction: DestructiveAction { | |
| 717 | 688 | case deleteSSHKey(SSHKey) |
| 718 | 689 | case deletePGPKey(PGPKey) |
| 719 | 690 | |
Hutch/Views/Pastes/PasteDetailView.swift +1 −7
| @@ -18,13 +18,7 @@ struct PasteDetailView: View { | ||
| 18 | 18 | @AppStorage(AppStorageKeys.wrapPasteFileLines) private var wrapLines = false |
| 19 | 19 | |
| 20 | 20 | var body: some View { |
| 21 | Group { | |
| 22 | if let viewModel { | |
| 23 | content(viewModel) | |
| 24 | } else { | |
| 25 | SRHTLoadingStateView(message: "Loading paste…") | |
| 26 | } | |
| 27 | } | |
| 21 | ModelContent(model: viewModel, loadingMessage: "Loading paste…") { content($0) } | |
| 28 | 22 | .navigationTitle(displayTitle) |
| 29 | 23 | .navigationBarTitleDisplayMode(.inline) |
| 30 | 24 | .toolbar { |
Hutch/Views/Pastes/PasteListView.swift +4 −22
| @@ -9,23 +9,12 @@ struct PasteListView: View { | ||
| 9 | 9 | @State private var pasteToDelete: Paste? |
| 10 | 10 | |
| 11 | 11 | var body: some View { |
| 12 | Group { | |
| 13 | if let viewModel { | |
| 14 | content(viewModel) | |
| 15 | } else { | |
| 16 | SRHTLoadingStateView(message: "Loading pastes…") | |
| 17 | } | |
| 18 | } | |
| 12 | ModelContent(model: viewModel, loadingMessage: "Loading pastes…") { content($0) } | |
| 19 | 13 | .navigationTitle("Pastes") |
| 20 | 14 | .toolbar { |
| 21 | 15 | if viewModel != nil { |
| 22 | ToolbarItem(placement: .topBarTrailing) { | |
| 23 | Button { | |
| 24 | showCreatePasteSheet = true | |
| 25 | } label: { | |
| 26 | Image(systemName: "plus") | |
| 27 | } | |
| 28 | .accessibilityLabel("Create paste") | |
| 16 | AddToolbarItem(label: "Create paste") { | |
| 17 | showCreatePasteSheet = true | |
| 29 | 18 | } |
| 30 | 19 | } |
| 31 | 20 | } |
| @@ -37,14 +26,7 @@ struct PasteListView: View { | ||
| 37 | 26 | } |
| 38 | 27 | } |
| 39 | 28 | } |
| 40 | .navigationDestination(isPresented: Binding( | |
| 41 | get: { createdPaste != nil }, | |
| 42 | set: { isPresented in | |
| 43 | if !isPresented { | |
| 44 | createdPaste = nil | |
| 45 | } | |
| 46 | } | |
| 47 | )) { | |
| 29 | .navigationDestination(isPresented: .isPresent($createdPaste)) { | |
| 48 | 30 | if let createdPaste { |
| 49 | 31 | PasteDetailView( |
| 50 | 32 | paste: createdPaste, |
Hutch/Views/Patchsets/PatchsetDetailView.swift +1 −7
| @@ -10,13 +10,7 @@ struct PatchsetDetailView: View { | ||
| 10 | 10 | @State private var expandedPatchIDs: Set<Int> = [] |
| 11 | 11 | |
| 12 | 12 | var body: some View { |
| 13 | Group { | |
| 14 | if let viewModel { | |
| 15 | content(viewModel) | |
| 16 | } else { | |
| 17 | SRHTLoadingStateView(message: "Loading Patchset…") | |
| 18 | } | |
| 19 | } | |
| 13 | ModelContent(model: viewModel, loadingMessage: "Loading Patchset…") { content($0) } | |
| 20 | 14 | .navigationTitle("Patchset") |
| 21 | 15 | .navigationBarTitleDisplayMode(.inline) |
| 22 | 16 | .toolbar { |
Hutch/Views/Projects/DiscoverProjectsView.swift +1 −7
| @@ -63,13 +63,7 @@ struct DiscoverProjectsView: View { | ||
| 63 | 63 | @State private var viewModel: DiscoverProjectsViewModel? |
| 64 | 64 | |
| 65 | 65 | var body: some View { |
| 66 | Group { | |
| 67 | if let viewModel { | |
| 68 | content(viewModel) | |
| 69 | } else { | |
| 70 | SRHTLoadingStateView(message: "Loading projects…") | |
| 71 | } | |
| 72 | } | |
| 66 | ModelContent(model: viewModel, loadingMessage: "Loading projects…") { content($0) } | |
| 73 | 67 | .navigationTitle("Discover") |
| 74 | 68 | .navigationBarTitleDisplayMode(.inline) |
| 75 | 69 | .task { |
Hutch/Views/Projects/ManageProjectResourcesView.swift +1 −7
| @@ -107,13 +107,7 @@ struct ManageProjectResourcesView: View { | ||
| 107 | 107 | |
| 108 | 108 | var body: some View { |
| 109 | 109 | NavigationStack { |
| 110 | Group { | |
| 111 | if let viewModel { | |
| 112 | content(viewModel) | |
| 113 | } else { | |
| 114 | SRHTLoadingStateView(message: "Loading…") | |
| 115 | } | |
| 116 | } | |
| 110 | ModelContent(model: viewModel, loadingMessage: "Loading…") { content($0) } | |
| 117 | 111 | .navigationTitle("Linked Resources") |
| 118 | 112 | .navigationBarTitleDisplayMode(.inline) |
| 119 | 113 | .toolbar { |
Hutch/Views/Projects/ProjectDetailView.swift +35 −35
| @@ -224,26 +224,33 @@ struct ProjectDetailView: View { | ||
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | /// A section of rows that each open their resource and dismiss, or say why they couldn't. | |
| 227 | 228 | @ViewBuilder |
| 228 | private var repositoriesSection: some View { | |
| 229 | if !displayedProject.sources.isEmpty { | |
| 230 | Section("Repositories") { | |
| 231 | ForEach(displayedProject.sources) { source in | |
| 229 | private func openSection<Resource: ProjectResource & Identifiable>( | |
| 230 | _ title: LocalizedStringKey, | |
| 231 | _ resources: [Resource], | |
| 232 | noun: String, | |
| 233 | systemImage: String, | |
| 234 | open: @escaping (Resource) async throws -> Void | |
| 235 | ) -> some View { | |
| 236 | if !resources.isEmpty { | |
| 237 | Section(title) { | |
| 238 | ForEach(resources) { resource in | |
| 232 | 239 | Button { |
| 233 | 240 | Task { |
| 234 | 241 | do { |
| 235 | try await appState.openProjectSource(source) | |
| 242 | try await open(resource) | |
| 236 | 243 | dismiss() |
| 237 | 244 | } catch { |
| 238 | self.error = "Couldn’t open repository. \(error.userFacingMessage)" | |
| 245 | self.error = "Couldn’t open \(noun). \(error.userFacingMessage)" | |
| 239 | 246 | } |
| 240 | 247 | } |
| 241 | 248 | } label: { |
| 242 | 249 | ProjectResourceRow( |
| 243 | title: source.displayName, | |
| 244 | subtitle: source.ownerDisplayName, | |
| 245 | detail: source.displayDescription, | |
| 246 | systemImage: "book.closed" | |
| 250 | title: resource.displayName, | |
| 251 | subtitle: resource.ownerDisplayName, | |
| 252 | detail: resource.displayDescription, | |
| 253 | systemImage: systemImage | |
| 247 | 254 | ) |
| 248 | 255 | } |
| 249 | 256 | .buttonStyle(.plain) |
| @@ -253,32 +260,15 @@ struct ProjectDetailView: View { | ||
| 253 | 260 | } |
| 254 | 261 | } |
| 255 | 262 | |
| 256 | @ViewBuilder | |
| 263 | private var repositoriesSection: some View { | |
| 264 | openSection("Repositories", displayedProject.sources, noun: "repository", systemImage: "book.closed") { | |
| 265 | try await appState.openProjectSource($0) | |
| 266 | } | |
| 267 | } | |
| 268 | ||
| 257 | 269 | private var trackersSection: some View { |
| 258 | if !displayedProject.trackers.isEmpty { | |
| 259 | Section("Trackers") { | |
| 260 | ForEach(displayedProject.trackers) { tracker in | |
| 261 | Button { | |
| 262 | Task { | |
| 263 | do { | |
| 264 | try await appState.openProjectTracker(tracker) | |
| 265 | dismiss() | |
| 266 | } catch { | |
| 267 | self.error = "Couldn’t open tracker. \(error.userFacingMessage)" | |
| 268 | } | |
| 269 | } | |
| 270 | } label: { | |
| 271 | ProjectResourceRow( | |
| 272 | title: tracker.displayName, | |
| 273 | subtitle: tracker.ownerDisplayName, | |
| 274 | detail: tracker.displayDescription, | |
| 275 | systemImage: "checklist" | |
| 276 | ) | |
| 277 | } | |
| 278 | .buttonStyle(.plain) | |
| 279 | } | |
| 280 | .themedRow() | |
| 281 | } | |
| 270 | openSection("Trackers", displayedProject.trackers, noun: "tracker", systemImage: "checklist") { | |
| 271 | try await appState.openProjectTracker($0) | |
| 282 | 272 | } |
| 283 | 273 | } |
| 284 | 274 | |
| @@ -382,6 +372,16 @@ private struct ProjectLink: Identifiable { | ||
| 382 | 372 | let url: URL |
| 383 | 373 | } |
| 384 | 374 | |
| 375 | /// A project's repository, tracker or mailing list, as its row shows it. | |
| 376 | private protocol ProjectResource { | |
| 377 | var displayName: String { get } | |
| 378 | var ownerDisplayName: String { get } | |
| 379 | var displayDescription: String? { get } | |
| 380 | } | |
| 381 | ||
| 382 | extension Project.SourceRepo: ProjectResource {} | |
| 383 | extension Project.Tracker: ProjectResource {} | |
| 384 | ||
| 385 | 385 | private struct ProjectResourceRow: View { |
| 386 | 386 | let title: String |
| 387 | 387 | let subtitle: String |
Hutch/Views/Projects/ProjectMailingListView.swift +1 −7
| @@ -419,13 +419,7 @@ struct MailingListDetailView: View { | ||
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | var body: some View { |
| 422 | Group { | |
| 423 | if let viewModel { | |
| 424 | content(viewModel) | |
| 425 | } else { | |
| 426 | SRHTLoadingStateView(message: "Loading mailing list…") | |
| 427 | } | |
| 428 | } | |
| 422 | ModelContent(model: viewModel, loadingMessage: "Loading mailing list…") { content($0) } | |
| 429 | 423 | .navigationTitle(mailingList.name) |
| 430 | 424 | .navigationBarTitleDisplayMode(.inline) |
| 431 | 425 | .toolbar { |
Hutch/Views/Projects/ProjectsListView.swift +2 −7
| @@ -85,13 +85,8 @@ struct ProjectsListView: View { | ||
| 85 | 85 | .accessibilityLabel("Discover public projects") |
| 86 | 86 | } |
| 87 | 87 | if appState.currentUser != nil { |
| 88 | ToolbarItem(placement: .topBarTrailing) { | |
| 89 | Button { | |
| 90 | isPresentingCreate = true | |
| 91 | } label: { | |
| 92 | Image(systemName: "plus") | |
| 93 | } | |
| 94 | .accessibilityLabel("Create project") | |
| 88 | AddToolbarItem(label: "Create project") { | |
| 89 | isPresentingCreate = true | |
| 95 | 90 | } |
| 96 | 91 | } |
| 97 | 92 | } |
Hutch/Views/Repositories/FileTreeView.swift +9 −65
| @@ -10,12 +10,8 @@ struct FileTreeView: View { | ||
| 10 | 10 | @State private var viewModel: FileTreeViewModel? |
| 11 | 11 | |
| 12 | 12 | var body: some View { |
| 13 | Group { | |
| 14 | if let viewModel { | |
| 15 | FileTreeContentView(viewModel: viewModel) | |
| 16 | } else { | |
| 17 | SRHTLoadingStateView(message: "Loading files…") | |
| 18 | } | |
| 13 | ModelContent(model: viewModel, loadingMessage: "Loading files…") { viewModel in | |
| 14 | FileTreeContentView(viewModel: viewModel) | |
| 19 | 15 | } |
| 20 | 16 | .task { |
| 21 | 17 | if viewModel == nil { |
| @@ -787,40 +783,14 @@ private struct RefPickerSheet: View { | ||
| 787 | 783 | NavigationStack { |
| 788 | 784 | List { |
| 789 | 785 | Section { |
| 790 | Button { | |
| 791 | Task { | |
| 792 | await viewModel.changeRevspec("HEAD") | |
| 793 | isPresented = false | |
| 794 | } | |
| 795 | } label: { | |
| 796 | refRow( | |
| 797 | title: "HEAD", | |
| 798 | systemImage: "arrow.triangle.branch", | |
| 799 | color: .blue, | |
| 800 | isSelected: viewModel.revspec == "HEAD" | |
| 801 | ) | |
| 802 | } | |
| 803 | .buttonStyle(.plain) | |
| 786 | choice("HEAD", title: "HEAD", systemImage: "arrow.triangle.branch", color: .blue) | |
| 804 | 787 | .themedRow() |
| 805 | 788 | } |
| 806 | 789 | |
| 807 | 790 | if !viewModel.branches.isEmpty { |
| 808 | 791 | Section("Branches") { |
| 809 | 792 | ForEach(viewModel.branches, id: \.name) { ref in |
| 810 | Button { | |
| 811 | Task { | |
| 812 | await viewModel.changeRevspec(ref.name) | |
| 813 | isPresented = false | |
| 814 | } | |
| 815 | } label: { | |
| 816 | refRow( | |
| 817 | title: ref.name.replacingOccurrences(of: "refs/heads/", with: ""), | |
| 818 | systemImage: "arrow.triangle.branch", | |
| 819 | color: .blue, | |
| 820 | isSelected: viewModel.revspec == ref.name | |
| 821 | ) | |
| 822 | } | |
| 823 | .buttonStyle(.plain) | |
| 793 | choice(ref.name, title: ref.name.replacingOccurrences(of: "refs/heads/", with: ""), systemImage: "arrow.triangle.branch", color: .blue) | |
| 824 | 794 | } |
| 825 | 795 | .themedRow() |
| 826 | 796 | } |
| @@ -829,20 +799,7 @@ private struct RefPickerSheet: View { | ||
| 829 | 799 | if !viewModel.tags.isEmpty { |
| 830 | 800 | Section("Tags") { |
| 831 | 801 | ForEach(viewModel.tags, id: \.name) { ref in |
| 832 | Button { | |
| 833 | Task { | |
| 834 | await viewModel.changeRevspec(ref.name) | |
| 835 | isPresented = false | |
| 836 | } | |
| 837 | } label: { | |
| 838 | refRow( | |
| 839 | title: ref.name.replacingOccurrences(of: "refs/tags/", with: ""), | |
| 840 | systemImage: "tag", | |
| 841 | color: .orange, | |
| 842 | isSelected: viewModel.revspec == ref.name | |
| 843 | ) | |
| 844 | } | |
| 845 | .buttonStyle(.plain) | |
| 802 | choice(ref.name, title: ref.name.replacingOccurrences(of: "refs/tags/", with: ""), systemImage: "tag", color: .orange) | |
| 846 | 803 | } |
| 847 | 804 | .themedRow() |
| 848 | 805 | } |
| @@ -867,23 +824,10 @@ private struct RefPickerSheet: View { | ||
| 867 | 824 | } |
| 868 | 825 | } |
| 869 | 826 | |
| 870 | private func refRow(title: String, systemImage: String, color: ViewColor, isSelected: Bool) -> some View { | |
| 871 | HStack(spacing: 12) { | |
| 872 | Image(systemName: systemImage) | |
| 873 | .foregroundStyle(color) | |
| 874 | ||
| 875 | Text(title) | |
| 876 | .font(.body.monospaced()) | |
| 877 | .foregroundStyle(.primary) | |
| 878 | ||
| 879 | Spacer() | |
| 880 | ||
| 881 | if isSelected { | |
| 882 | Image(systemName: "checkmark") | |
| 883 | .font(.caption.weight(.semibold)) | |
| 884 | .foregroundStyle(.tint) | |
| 885 | } | |
| 827 | private func choice(_ revspec: String, title: String, systemImage: String, color: ViewColor) -> some View { | |
| 828 | RefChoiceButton(title: title, systemImage: systemImage, color: color, isSelected: viewModel.revspec == revspec) { | |
| 829 | await viewModel.changeRevspec(revspec) | |
| 830 | isPresented = false | |
| 886 | 831 | } |
| 887 | .contentShape(Rectangle()) | |
| 888 | 832 | } |
| 889 | 833 | } |
Hutch/Views/Repositories/HgRepositoryDetailView.swift +9 −80
| @@ -47,13 +47,7 @@ struct HgRepositoryDetailView: View { | ||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | var body: some View { |
| 50 | Group { | |
| 51 | if let viewModel { | |
| 52 | content(viewModel) | |
| 53 | } else { | |
| 54 | SRHTLoadingStateView(message: "Loading repository…") | |
| 55 | } | |
| 56 | } | |
| 50 | ModelContent(model: viewModel, loadingMessage: "Loading repository…") { content($0) } | |
| 57 | 51 | .navigationTitle(repository.name) |
| 58 | 52 | .navigationBarTitleDisplayMode(.inline) |
| 59 | 53 | .toolbar { |
| @@ -672,40 +666,14 @@ private struct HgBrowseRefPickerSheet: View { | ||
| 672 | 666 | NavigationStack { |
| 673 | 667 | List { |
| 674 | 668 | Section { |
| 675 | Button { | |
| 676 | Task { | |
| 677 | await viewModel.changeBrowseRevspec("tip") | |
| 678 | isPresented = false | |
| 679 | } | |
| 680 | } label: { | |
| 681 | refRow( | |
| 682 | title: "tip", | |
| 683 | systemImage: "arrow.triangle.branch", | |
| 684 | color: .blue, | |
| 685 | isSelected: viewModel.browseRevspec == "tip" | |
| 686 | ) | |
| 687 | } | |
| 688 | .buttonStyle(.plain) | |
| 669 | choice("tip", title: "tip", systemImage: "arrow.triangle.branch", color: .blue) | |
| 689 | 670 | .themedRow() |
| 690 | 671 | } |
| 691 | 672 | |
| 692 | 673 | if !viewModel.branches.isEmpty { |
| 693 | 674 | Section("Branches") { |
| 694 | 675 | ForEach(viewModel.branches) { revision in |
| 695 | Button { | |
| 696 | Task { | |
| 697 | await viewModel.changeBrowseRevspec(revision.name) | |
| 698 | isPresented = false | |
| 699 | } | |
| 700 | } label: { | |
| 701 | refRow( | |
| 702 | title: revision.name, | |
| 703 | systemImage: "arrow.triangle.branch", | |
| 704 | color: .blue, | |
| 705 | isSelected: viewModel.browseRevspec == revision.name | |
| 706 | ) | |
| 707 | } | |
| 708 | .buttonStyle(.plain) | |
| 676 | choice(revision.name, title: revision.name, systemImage: "arrow.triangle.branch", color: .blue) | |
| 709 | 677 | } |
| 710 | 678 | .themedRow() |
| 711 | 679 | } |
| @@ -714,20 +682,7 @@ private struct HgBrowseRefPickerSheet: View { | ||
| 714 | 682 | if !viewModel.tags.isEmpty { |
| 715 | 683 | Section("Tags") { |
| 716 | 684 | ForEach(viewModel.tags) { revision in |
| 717 | Button { | |
| 718 | Task { | |
| 719 | await viewModel.changeBrowseRevspec(revision.name) | |
| 720 | isPresented = false | |
| 721 | } | |
| 722 | } label: { | |
| 723 | refRow( | |
| 724 | title: revision.name, | |
| 725 | systemImage: "tag", | |
| 726 | color: .orange, | |
| 727 | isSelected: viewModel.browseRevspec == revision.name | |
| 728 | ) | |
| 729 | } | |
| 730 | .buttonStyle(.plain) | |
| 685 | choice(revision.name, title: revision.name, systemImage: "tag", color: .orange) | |
| 731 | 686 | } |
| 732 | 687 | .themedRow() |
| 733 | 688 | } |
| @@ -736,20 +691,7 @@ private struct HgBrowseRefPickerSheet: View { | ||
| 736 | 691 | if !viewModel.bookmarks.isEmpty { |
| 737 | 692 | Section("Bookmarks") { |
| 738 | 693 | ForEach(viewModel.bookmarks) { revision in |
| 739 | Button { | |
| 740 | Task { | |
| 741 | await viewModel.changeBrowseRevspec(revision.name) | |
| 742 | isPresented = false | |
| 743 | } | |
| 744 | } label: { | |
| 745 | refRow( | |
| 746 | title: revision.name, | |
| 747 | systemImage: "bookmark", | |
| 748 | color: .purple, | |
| 749 | isSelected: viewModel.browseRevspec == revision.name | |
| 750 | ) | |
| 751 | } | |
| 752 | .buttonStyle(.plain) | |
| 694 | choice(revision.name, title: revision.name, systemImage: "bookmark", color: .purple) | |
| 753 | 695 | } |
| 754 | 696 | .themedRow() |
| 755 | 697 | } |
| @@ -769,24 +711,11 @@ private struct HgBrowseRefPickerSheet: View { | ||
| 769 | 711 | } |
| 770 | 712 | } |
| 771 | 713 | |
| 772 | private func refRow(title: String, systemImage: String, color: Color, isSelected: Bool) -> some View { | |
| 773 | HStack(spacing: 12) { | |
| 774 | Image(systemName: systemImage) | |
| 775 | .foregroundStyle(color) | |
| 776 | ||
| 777 | Text(title) | |
| 778 | .font(.body.monospaced()) | |
| 779 | .foregroundStyle(.primary) | |
| 780 | ||
| 781 | Spacer() | |
| 782 | ||
| 783 | if isSelected { | |
| 784 | Image(systemName: "checkmark") | |
| 785 | .font(.caption.weight(.semibold)) | |
| 786 | .foregroundStyle(.tint) | |
| 787 | } | |
| 714 | private func choice(_ revspec: String, title: String, systemImage: String, color: Color) -> some View { | |
| 715 | RefChoiceButton(title: title, systemImage: systemImage, color: color, isSelected: viewModel.browseRevspec == revspec) { | |
| 716 | await viewModel.changeBrowseRevspec(revspec) | |
| 717 | isPresented = false | |
| 788 | 718 | } |
| 789 | .contentShape(Rectangle()) | |
| 790 | 719 | } |
| 791 | 720 | } |
| 792 | 721 | |
Hutch/Views/Repositories/HgRepositorySettingsView.swift +1 −8
| @@ -73,14 +73,7 @@ struct HgRepositorySettingsView: View { | ||
| 73 | 73 | } message: { |
| 74 | 74 | Text("This cannot be undone.") |
| 75 | 75 | } |
| 76 | .alert("Remove Access?", isPresented: Binding( | |
| 77 | get: { pendingACLDeletion != nil }, | |
| 78 | set: { isPresented in | |
| 79 | if !isPresented { | |
| 80 | pendingACLDeletion = nil | |
| 81 | } | |
| 82 | } | |
| 83 | )) { | |
| 76 | .alert("Remove Access?", isPresented: .isPresent($pendingACLDeletion)) { | |
| 84 | 77 | Button("Cancel", role: .cancel) { |
| 85 | 78 | // Alert dismissal is implicit; no additional action required. |
| 86 | 79 | } |
Hutch/Views/Repositories/RefChoiceButton.swift added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | import SwiftUI | |
| 2 | ||
| 3 | /// A branch, tag or bookmark to browse at, checked when it's the one shown. | |
| 4 | struct RefChoiceButton: View { | |
| 5 | let title: String | |
| 6 | let systemImage: String | |
| 7 | let color: Color | |
| 8 | let isSelected: Bool | |
| 9 | let choose: () async -> Void | |
| 10 | ||
| 11 | var body: some View { | |
| 12 | Button { | |
| 13 | Task { await choose() } | |
| 14 | } label: { | |
| 15 | HStack(spacing: 12) { | |
| 16 | Image(systemName: systemImage) | |
| 17 | .foregroundStyle(color) | |
| 18 | ||
| 19 | Text(title) | |
| 20 | .font(.body.monospaced()) | |
| 21 | .foregroundStyle(.primary) | |
| 22 | ||
| 23 | Spacer() | |
| 24 | ||
| 25 | if isSelected { | |
| 26 | Image(systemName: "checkmark") | |
| 27 | .font(.caption.weight(.semibold)) | |
| 28 | .foregroundStyle(.tint) | |
| 29 | } | |
| 30 | } | |
| 31 | .contentShape(Rectangle()) | |
| 32 | } | |
| 33 | .buttonStyle(.plain) | |
| 34 | } | |
| 35 | } | |
Hutch/Views/Repositories/RepositoryACLView.swift +4 −22
| @@ -12,13 +12,7 @@ struct RepositoryACLView: View { | ||
| 12 | 12 | @State private var showAddSheet = false |
| 13 | 13 | |
| 14 | 14 | var body: some View { |
| 15 | Group { | |
| 16 | if let viewModel { | |
| 17 | content(viewModel) | |
| 18 | } else { | |
| 19 | SRHTLoadingStateView(message: "Loading access…") | |
| 20 | } | |
| 21 | } | |
| 15 | ModelContent(model: viewModel, loadingMessage: "Loading access…") { content($0) } | |
| 22 | 16 | .navigationTitle("Access") |
| 23 | 17 | .navigationBarTitleDisplayMode(.inline) |
| 24 | 18 | .toolbar { |
| @@ -29,13 +23,8 @@ struct RepositoryACLView: View { | ||
| 29 | 23 | } |
| 30 | 24 | |
| 31 | 25 | if viewModel != nil { |
| 32 | ToolbarItem(placement: .primaryAction) { | |
| 33 | Button { | |
| 34 | showAddSheet = true | |
| 35 | } label: { | |
| 36 | Image(systemName: "plus") | |
| 37 | } | |
| 38 | .accessibilityLabel("Add User") | |
| 26 | AddToolbarItem(label: "Add User", placement: .primaryAction) { | |
| 27 | showAddSheet = true | |
| 39 | 28 | } |
| 40 | 29 | } |
| 41 | 30 | } |
| @@ -102,14 +91,7 @@ struct RepositoryACLView: View { | ||
| 102 | 91 | set: { viewModel.error = $0 } |
| 103 | 92 | ) |
| 104 | 93 | ) |
| 105 | .alert("Remove Access?", isPresented: Binding( | |
| 106 | get: { pendingDeletion != nil }, | |
| 107 | set: { isPresented in | |
| 108 | if !isPresented { | |
| 109 | pendingDeletion = nil | |
| 110 | } | |
| 111 | } | |
| 112 | )) { | |
| 94 | .alert("Remove Access?", isPresented: .isPresent($pendingDeletion)) { | |
| 113 | 95 | Button("Cancel", role: .cancel) { |
| 114 | 96 | /* Dismiss only; removal is confirmed separately. */ |
| 115 | 97 | } |
Hutch/Views/Repositories/RepositoryDeployKeysView.swift +3 −14
| @@ -77,13 +77,7 @@ struct RepositoryDeployKeysView: View { | ||
| 77 | 77 | @State private var pendingDeletion: RepositoryDeployKey? |
| 78 | 78 | |
| 79 | 79 | var body: some View { |
| 80 | Group { | |
| 81 | if let viewModel { | |
| 82 | content(viewModel) | |
| 83 | } else { | |
| 84 | SRHTLoadingStateView(message: "Loading deploy keys…") | |
| 85 | } | |
| 86 | } | |
| 80 | ModelContent(model: viewModel, loadingMessage: "Loading deploy keys…") { content($0) } | |
| 87 | 81 | .navigationTitle("Deploy Keys") |
| 88 | 82 | .navigationBarTitleDisplayMode(.inline) |
| 89 | 83 | .toolbar { |
| @@ -93,13 +87,8 @@ struct RepositoryDeployKeysView: View { | ||
| 93 | 87 | } |
| 94 | 88 | } |
| 95 | 89 | if viewModel != nil { |
| 96 | ToolbarItem(placement: .topBarTrailing) { | |
| 97 | Button { | |
| 98 | showAddSheet = true | |
| 99 | } label: { | |
| 100 | Image(systemName: "plus") | |
| 101 | } | |
| 102 | .accessibilityLabel("Add deploy key") | |
| 90 | AddToolbarItem(label: "Add deploy key") { | |
| 91 | showAddSheet = true | |
| 103 | 92 | } |
| 104 | 93 | } |
| 105 | 94 | } |
Hutch/Views/Repositories/RepositoryDetailView.swift +1 −7
| @@ -45,13 +45,7 @@ struct RepositoryDetailView: View { | ||
| 45 | 45 | if currentRepository.service == .hg { |
| 46 | 46 | HgRepositoryDetailView(repository: currentRepository, onDeleted: onDeleted) |
| 47 | 47 | } else { |
| 48 | Group { | |
| 49 | if let viewModel { | |
| 50 | detailContent(viewModel) | |
| 51 | } else { | |
| 52 | SRHTLoadingStateView(message: "Loading repository…") | |
| 53 | } | |
| 54 | } | |
| 48 | ModelContent(model: viewModel, loadingMessage: "Loading repository…") { detailContent($0) } | |
| 55 | 49 | .navigationTitle(currentRepository.name) |
| 56 | 50 | .navigationBarTitleDisplayMode(.inline) |
| 57 | 51 | .toolbar { |
Hutch/Views/Repositories/RepositoryListView.swift +4 −22
| @@ -9,23 +9,12 @@ struct RepositoryListView: View { | ||
| 9 | 9 | @State private var createdRepository: RepositorySummary? |
| 10 | 10 | |
| 11 | 11 | var body: some View { |
| 12 | Group { | |
| 13 | if let viewModel { | |
| 14 | listContent(viewModel) | |
| 15 | } else { | |
| 16 | SRHTLoadingStateView(message: "Loading repositories…") | |
| 17 | } | |
| 18 | } | |
| 12 | ModelContent(model: viewModel, loadingMessage: "Loading repositories…") { listContent($0) } | |
| 19 | 13 | .navigationTitle("Repositories") |
| 20 | 14 | .toolbar { |
| 21 | 15 | if viewModel != nil { |
| 22 | ToolbarItem(placement: .topBarTrailing) { | |
| 23 | Button { | |
| 24 | showCreateRepositorySheet = true | |
| 25 | } label: { | |
| 26 | Image(systemName: "plus") | |
| 27 | } | |
| 28 | .accessibilityLabel("Create repository") | |
| 16 | AddToolbarItem(label: "Create repository") { | |
| 17 | showCreateRepositorySheet = true | |
| 29 | 18 | } |
| 30 | 19 | } |
| 31 | 20 | } |
| @@ -37,14 +26,7 @@ struct RepositoryListView: View { | ||
| 37 | 26 | } |
| 38 | 27 | } |
| 39 | 28 | } |
| 40 | .navigationDestination(isPresented: Binding( | |
| 41 | get: { createdRepository != nil }, | |
| 42 | set: { isPresented in | |
| 43 | if !isPresented { | |
| 44 | createdRepository = nil | |
| 45 | } | |
| 46 | } | |
| 47 | )) { | |
| 29 | .navigationDestination(isPresented: .isPresent($createdRepository)) { | |
| 48 | 30 | if let createdRepository { |
| 49 | 31 | RepositoryDetailView( |
| 50 | 32 | repository: createdRepository, |
Hutch/Views/Settings/SettingsView.swift +7 −30
| @@ -30,35 +30,12 @@ struct SettingsView: View { | ||
| 30 | 30 | .sheet(isPresented: $showAccountSwitcher) { |
| 31 | 31 | AccountSwitcherView() |
| 32 | 32 | } |
| 33 | .alert( | |
| 34 | pendingDestructiveAction?.title ?? "", | |
| 35 | isPresented: Binding( | |
| 36 | get: { pendingDestructiveAction != nil }, | |
| 37 | set: { isPresented in | |
| 38 | if !isPresented { | |
| 39 | pendingDestructiveAction = nil | |
| 40 | } | |
| 41 | } | |
| 42 | ) | |
| 43 | ) { | |
| 44 | Button("Cancel", role: .cancel) { | |
| 45 | /* Dismiss only; destructive action is separate. */ | |
| 46 | } | |
| 47 | Button(pendingDestructiveAction?.confirmationLabel ?? "Confirm", role: .destructive) { | |
| 48 | guard let action = pendingDestructiveAction else { return } | |
| 49 | pendingDestructiveAction = nil | |
| 50 | Task { | |
| 51 | switch action { | |
| 52 | case .resetAppData: | |
| 53 | await appState.resetAppData() | |
| 54 | case .signOut: | |
| 55 | await appState.signOut() | |
| 56 | } | |
| 57 | } | |
| 58 | } | |
| 59 | } message: { | |
| 60 | if let pendingDestructiveAction { | |
| 61 | Text(pendingDestructiveAction.message) | |
| 33 | .destructiveConfirmation($pendingDestructiveAction) { action in | |
| 34 | switch action { | |
| 35 | case .resetAppData: | |
| 36 | await appState.resetAppData() | |
| 37 | case .signOut: | |
| 38 | await appState.signOut() | |
| 62 | 39 | } |
| 63 | 40 | } |
| 64 | 41 | } |
| @@ -238,7 +215,7 @@ func settingsBioAttributedString(_ markdown: String) -> AttributedString { | ||
| 238 | 215 | profileBioAttributedString(markdown) |
| 239 | 216 | } |
| 240 | 217 | |
| 241 | private enum SettingsDestructiveAction { | |
| 218 | private enum SettingsDestructiveAction: DestructiveAction { | |
| 242 | 219 | case resetAppData |
| 243 | 220 | case signOut |
| 244 | 221 | |
Hutch/Views/Shared/DestructiveConfirmation.swift added +36
| @@ -0,0 +1,36 @@ | ||
| 1 | import SwiftUI | |
| 2 | ||
| 3 | /// Something that can't be undone, with what its confirmation alert says. | |
| 4 | protocol DestructiveAction { | |
| 5 | var title: String { get } | |
| 6 | var confirmationLabel: String { get } | |
| 7 | var message: String { get } | |
| 8 | } | |
| 9 | ||
| 10 | extension View { | |
| 11 | /// Asks to confirm `pending` while it's set, and runs `perform` with it once confirmed. | |
| 12 | func destructiveConfirmation<Action: DestructiveAction>( | |
| 13 | _ pending: Binding<Action?>, | |
| 14 | perform: @escaping (Action) async -> Void | |
| 15 | ) -> some View { | |
| 16 | alert( | |
| 17 | pending.wrappedValue?.title ?? "", | |
| 18 | isPresented: .isPresent(pending) | |
| 19 | ) { | |
| 20 | Button("Cancel", role: .cancel) { | |
| 21 | /* Dismiss only; destructive action is separate. */ | |
| 22 | } | |
| 23 | Button(pending.wrappedValue?.confirmationLabel ?? "Confirm", role: .destructive) { | |
| 24 | guard let action = pending.wrappedValue else { return } | |
| 25 | pending.wrappedValue = nil | |
| 26 | Task { | |
| 27 | await perform(action) | |
| 28 | } | |
| 29 | } | |
| 30 | } message: { | |
| 31 | if let action = pending.wrappedValue { | |
| 32 | Text(action.message) | |
| 33 | } | |
| 34 | } | |
| 35 | } | |
| 36 | } | |
Hutch/Views/Shared/ModelContent.swift added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | import SwiftUI | |
| 2 | ||
| 3 | /// A screen's content once its view model exists, and a loading state until then. | |
| 4 | struct ModelContent<Model, Content: View>: View { | |
| 5 | let model: Model? | |
| 6 | let loadingMessage: String | |
| 7 | @ViewBuilder let content: (Model) -> Content | |
| 8 | ||
| 9 | var body: some View { | |
| 10 | if let model { | |
| 11 | content(model) | |
| 12 | } else { | |
| 13 | SRHTLoadingStateView(message: loadingMessage) | |
| 14 | } | |
| 15 | } | |
| 16 | } | |
| 17 | ||
| 18 | /// The + button a list adds with. | |
| 19 | struct AddToolbarItem: ToolbarContent { | |
| 20 | let label: LocalizedStringKey | |
| 21 | var placement: ToolbarItemPlacement = .topBarTrailing | |
| 22 | let action: () -> Void | |
| 23 | ||
| 24 | var body: some ToolbarContent { | |
| 25 | ToolbarItem(placement: placement) { | |
| 26 | Button(action: action) { | |
| 27 | Image(systemName: "plus") | |
| 28 | } | |
| 29 | .accessibilityLabel(label) | |
| 30 | } | |
| 31 | } | |
| 32 | } | |
Hutch/Views/Shared/PresentedItem.swift added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | import SwiftUI | |
| 2 | ||
| 3 | extension Binding where Value == Bool { | |
| 4 | /// True while `item` holds a value; dismissing clears it. Presents a | |
| 5 | /// dialog or alert about whatever `item` names. | |
| 6 | static func isPresent<Item>(_ item: Binding<Item?>) -> Binding<Bool> { | |
| 7 | Binding(get: { item.wrappedValue != nil }, set: { if !$0 { item.wrappedValue = nil } }) | |
| 8 | } | |
| 9 | } | |
Hutch/Views/SystemStatus/SystemStatusView.swift +1 −7
| @@ -5,13 +5,7 @@ struct SystemStatusView: View { | ||
| 5 | 5 | @State private var viewModel: SystemStatusViewModel? |
| 6 | 6 | |
| 7 | 7 | var body: some View { |
| 8 | Group { | |
| 9 | if let viewModel { | |
| 10 | content(viewModel) | |
| 11 | } else { | |
| 12 | SRHTLoadingStateView(message: "Loading system status…") | |
| 13 | } | |
| 14 | } | |
| 8 | ModelContent(model: viewModel, loadingMessage: "Loading system status…") { content($0) } | |
| 15 | 9 | .navigationTitle("System Status") |
| 16 | 10 | .navigationBarTitleDisplayMode(.inline) |
| 17 | 11 | .task { |
Hutch/Views/Tickets/TicketDetailView.swift +1 −7
| @@ -36,13 +36,7 @@ struct TicketDetailView: View { | ||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | var body: some View { |
| 39 | Group { | |
| 40 | if let viewModel { | |
| 41 | detailContent(viewModel) | |
| 42 | } else { | |
| 43 | SRHTLoadingStateView(message: "Loading ticket…") | |
| 44 | } | |
| 45 | } | |
| 39 | ModelContent(model: viewModel, loadingMessage: "Loading ticket…") { detailContent($0) } | |
| 46 | 40 | .navigationTitle("#\(ticketId)") |
| 47 | 41 | .navigationBarTitleDisplayMode(.inline) |
| 48 | 42 | .toolbar { |
Hutch/Views/Tickets/TicketListView.swift +2 −15
| @@ -58,13 +58,7 @@ struct TicketListView: View { | ||
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | var body: some View { |
| 61 | Group { | |
| 62 | if let viewModel { | |
| 63 | listContent(viewModel) | |
| 64 | } else { | |
| 65 | SRHTLoadingStateView(message: "Loading tickets…") | |
| 66 | } | |
| 67 | } | |
| 61 | ModelContent(model: viewModel, loadingMessage: "Loading tickets…") { listContent($0) } | |
| 68 | 62 | .navigationTitle(navigationTitle) |
| 69 | 63 | .navigationBarTitleDisplayMode(.inline) |
| 70 | 64 | .toolbar { |
| @@ -210,14 +204,7 @@ struct TicketListView: View { | ||
| 210 | 204 | dismissButton: .default(Text("OK")) |
| 211 | 205 | ) |
| 212 | 206 | } |
| 213 | .navigationDestination(isPresented: Binding( | |
| 214 | get: { createdTicket != nil }, | |
| 215 | set: { isPresented in | |
| 216 | if !isPresented { | |
| 217 | createdTicket = nil | |
| 218 | } | |
| 219 | } | |
| 220 | )) { | |
| 207 | .navigationDestination(isPresented: .isPresent($createdTicket)) { | |
| 221 | 208 | if let createdTicket { |
| 222 | 209 | TicketDetailView( |
| 223 | 210 | ownerUsername: String(tracker.owner.canonicalName.dropFirst()), |
Hutch/Views/Tickets/TrackerListView.swift +5 −30
| @@ -9,23 +9,12 @@ struct TrackerListView: View { | ||
| 9 | 9 | @State private var pendingDeletion: TrackerSummary? |
| 10 | 10 | |
| 11 | 11 | var body: some View { |
| 12 | Group { | |
| 13 | if let viewModel { | |
| 14 | listContent(viewModel) | |
| 15 | } else { | |
| 16 | SRHTLoadingStateView(message: "Loading trackers…") | |
| 17 | } | |
| 18 | } | |
| 12 | ModelContent(model: viewModel, loadingMessage: "Loading trackers…") { listContent($0) } | |
| 19 | 13 | .navigationTitle("Trackers") |
| 20 | 14 | .toolbar { |
| 21 | 15 | if viewModel != nil { |
| 22 | ToolbarItem(placement: .topBarTrailing) { | |
| 23 | Button { | |
| 24 | showCreateTrackerSheet = true | |
| 25 | } label: { | |
| 26 | Image(systemName: "plus") | |
| 27 | } | |
| 28 | .accessibilityLabel("Create tracker") | |
| 16 | AddToolbarItem(label: "Create tracker") { | |
| 17 | showCreateTrackerSheet = true | |
| 29 | 18 | } |
| 30 | 19 | } |
| 31 | 20 | } |
| @@ -78,14 +67,7 @@ struct TrackerListView: View { | ||
| 78 | 67 | } |
| 79 | 68 | } |
| 80 | 69 | } |
| 81 | .navigationDestination(isPresented: Binding( | |
| 82 | get: { createdTracker != nil }, | |
| 83 | set: { isPresented in | |
| 84 | if !isPresented { | |
| 85 | createdTracker = nil | |
| 86 | } | |
| 87 | } | |
| 88 | )) { | |
| 70 | .navigationDestination(isPresented: .isPresent($createdTracker)) { | |
| 89 | 71 | if let createdTracker { |
| 90 | 72 | TicketListView(tracker: createdTracker) { updatedTracker in |
| 91 | 73 | viewModel?.applyTrackerUpdate(updatedTracker) |
| @@ -99,14 +81,7 @@ struct TrackerListView: View { | ||
| 99 | 81 | } |
| 100 | 82 | } |
| 101 | 83 | } |
| 102 | .alert("Delete Tracker?", isPresented: Binding( | |
| 103 | get: { pendingDeletion != nil }, | |
| 104 | set: { isPresented in | |
| 105 | if !isPresented { | |
| 106 | pendingDeletion = nil | |
| 107 | } | |
| 108 | } | |
| 109 | )) { | |
| 84 | .alert("Delete Tracker?", isPresented: .isPresent($pendingDeletion)) { | |
| 110 | 85 | Button("Cancel", role: .cancel) { |
| 111 | 86 | // no-op: .cancel role handles alert dismissal |
| 112 | 87 | } |
Hutch/Views/Tickets/TrackerManagementView.swift +2 −16
| @@ -825,14 +825,7 @@ struct TrackerACLManagementSheet: View { | ||
| 825 | 825 | await viewModel.updateDefaultACL(permissions) |
| 826 | 826 | } |
| 827 | 827 | } |
| 828 | .alert("Remove Access?", isPresented: Binding( | |
| 829 | get: { pendingDeletion != nil }, | |
| 830 | set: { isPresented in | |
| 831 | if !isPresented { | |
| 832 | pendingDeletion = nil | |
| 833 | } | |
| 834 | } | |
| 835 | )) { | |
| 828 | .alert("Remove Access?", isPresented: .isPresent($pendingDeletion)) { | |
| 836 | 829 | Button("Cancel", role: .cancel) { |
| 837 | 830 | // no-op: .cancel role handles alert dismissal |
| 838 | 831 | } |
| @@ -1194,14 +1187,7 @@ struct TrackerLabelManagementSheet: View { | ||
| 1194 | 1187 | ) |
| 1195 | 1188 | } |
| 1196 | 1189 | } |
| 1197 | .alert("Delete Label?", isPresented: Binding( | |
| 1198 | get: { pendingDeletion != nil }, | |
| 1199 | set: { isPresented in | |
| 1200 | if !isPresented { | |
| 1201 | pendingDeletion = nil | |
| 1202 | } | |
| 1203 | } | |
| 1204 | )) { | |
| 1190 | .alert("Delete Label?", isPresented: .isPresent($pendingDeletion)) { | |
| 1205 | 1191 | Button("Cancel", role: .cancel) { |
| 1206 | 1192 | // no-op: .cancel role handles alert dismissal |
| 1207 | 1193 | } |
Hutch/Views/Work/WorkView.swift +1 −7
| @@ -25,13 +25,7 @@ struct WorkView: View { | ||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | var body: some View { |
| 28 | Group { | |
| 29 | if let viewModel { | |
| 30 | content(viewModel) | |
| 31 | } else { | |
| 32 | SRHTLoadingStateView(message: "Loading Work…") | |
| 33 | } | |
| 34 | } | |
| 28 | ModelContent(model: viewModel, loadingMessage: "Loading Work…") { content($0) } | |
| 35 | 29 | .navigationTitle("Work") |
| 36 | 30 | .navigationBarTitleDisplayMode(.inline) |
| 37 | 31 | .toolbar { |