Commit 11590735a0
Verified · cmc
Layout: unified · split
.qlty/.gitignore added +7
| @@ -0,0 +1,7 @@ | |||
| 1 | * | ||
| 2 | !configs | ||
| 3 | !configs/** | ||
| 4 | !hooks | ||
| 5 | !hooks/** | ||
| 6 | !qlty.toml | ||
| 7 | !.gitignore | ||
.qlty/qlty.toml added +48
| @@ -0,0 +1,48 @@ | |||
| 1 | config_version = "0" | ||
| 2 | |||
| 3 | exclude_patterns = [ | ||
| 4 | "**/vendor/**", | ||
| 5 | "**/node_modules/**", | ||
| 6 | "**/testdata/**", | ||
| 7 | "**/dist/**", | ||
| 8 | "**/.build/**", | ||
| 9 | "**/build/**", | ||
| 10 | "**/*.min.*", | ||
| 11 | "**/generated/**", | ||
| 12 | ".claude/**", | ||
| 13 | "**/Pods/**", | ||
| 14 | ] | ||
| 15 | |||
| 16 | test_patterns = [ | ||
| 17 | "**/test/**", | ||
| 18 | "**/tests/**", | ||
| 19 | "**/Tests/**", | ||
| 20 | "**/*_test.*", | ||
| 21 | "**/test_*.*", | ||
| 22 | "**/*.test.*", | ||
| 23 | "**/*Tests.swift", | ||
| 24 | "e2e/**", | ||
| 25 | ] | ||
| 26 | |||
| 27 | [[source]] | ||
| 28 | name = "default" | ||
| 29 | default = true | ||
| 30 | |||
| 31 | [[plugin]] | ||
| 32 | name = "osv-scanner" | ||
| 33 | |||
| 34 | [[plugin]] | ||
| 35 | name = "trufflehog" | ||
| 36 | |||
| 37 | # Early returns are guard clauses, which keep the happy path unindented. | ||
| 38 | [smells.return_statements] | ||
| 39 | enabled = false | ||
| 40 | |||
| 41 | # Total file complexity is the sum of its functions, which function_complexity | ||
| 42 | # already checks. | ||
| 43 | [smells.file_complexity] | ||
| 44 | enabled = false | ||
| 45 | |||
| 46 | # Exhaustive switch-over-enum lookup tables share shape but not content. | ||
| 47 | [language.swift.smells.duplication] | ||
| 48 | filter_patterns = ["(import_declaration _)", "(switch_statement _)"] | ||
Hutch/Extensions/ErrorViews.swift +22
| @@ -158,3 +158,25 @@ extension View { | |||
| 158 | modifier(ConnectivityOverlay(hasContent: hasContent, retryAction: retryAction)) | 158 | modifier(ConnectivityOverlay(hasContent: hasContent, retryAction: retryAction)) |
| 159 | } | 159 | } |
| 160 | } | 160 | } |
| 161 | |||
| 162 | /// A screen's loading or error state while it has nothing to show, and `content` otherwise. | ||
| 163 | struct SRHTLoadStateView<Content: View>: View { | ||
| 164 | let isLoading: Bool | ||
| 165 | let error: String? | ||
| 166 | /// Whether nothing has loaded that could be shown instead. | ||
| 167 | let isEmpty: Bool | ||
| 168 | let loadingMessage: String | ||
| 169 | let errorTitle: String | ||
| 170 | let retryAction: (() async -> Void)? | ||
| 171 | @ViewBuilder var content: () -> Content | ||
| 172 | |||
| 173 | var body: some View { | ||
| 174 | if isLoading, isEmpty { | ||
| 175 | SRHTLoadingStateView(message: loadingMessage) | ||
| 176 | } else if let error, isEmpty { | ||
| 177 | SRHTErrorStateView(title: errorTitle, message: error, retryAction: retryAction) | ||
| 178 | } else { | ||
| 179 | content() | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
Hutch/Models/Inbox.swift +65
| @@ -235,3 +235,68 @@ nonisolated enum InboxReadStateStore { | |||
| 235 | return true | 235 | return true |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | |||
| 239 | extension InboxThreadSummary { | ||
| 240 | /// This summary marked read or unread. | ||
| 241 | nonisolated func withUnread(_ isUnread: Bool) -> InboxThreadSummary { | ||
| 242 | InboxThreadSummary( | ||
| 243 | rootEmailID: rootEmailID, | ||
| 244 | rootMessageID: rootMessageID, | ||
| 245 | threadRootEmailIDs: threadRootEmailIDs, | ||
| 246 | threadRootMessageIDs: threadRootMessageIDs, | ||
| 247 | listID: listID, | ||
| 248 | listRID: listRID, | ||
| 249 | listName: listName, | ||
| 250 | listOwner: listOwner, | ||
| 251 | subject: subject, | ||
| 252 | latestSender: latestSender, | ||
| 253 | lastActivityAt: lastActivityAt, | ||
| 254 | messageCount: messageCount, | ||
| 255 | repo: repo, | ||
| 256 | containsPatch: containsPatch, | ||
| 257 | isUnread: isUnread | ||
| 258 | ) | ||
| 259 | } | ||
| 260 | |||
| 261 | /// One summary per thread grouping key, unsorted: the latest summary's fields, with the | ||
| 262 | /// root IDs, counts, patch and unread flags of every summary for that thread. | ||
| 263 | nonisolated static func mergedByThread(_ threads: [InboxThreadSummary]) -> [InboxThreadSummary] { | ||
| 264 | var grouped: [String: InboxThreadSummary] = [:] | ||
| 265 | |||
| 266 | for thread in threads { | ||
| 267 | guard let existing = grouped[thread.threadGroupingKey] else { | ||
| 268 | grouped[thread.threadGroupingKey] = thread | ||
| 269 | continue | ||
| 270 | } | ||
| 271 | |||
| 272 | let latest = thread.lastActivityAt >= existing.lastActivityAt ? thread : existing | ||
| 273 | let mergedRootEmailIDs = Array(Set(existing.threadRootEmailIDs + thread.threadRootEmailIDs)).sorted() | ||
| 274 | let mergedRootMessageIDs = Array(Set(existing.threadRootMessageIDs + thread.threadRootMessageIDs)).sorted() | ||
| 275 | let mergedMessageCount = max( | ||
| 276 | existing.messageCount ?? existing.threadRootMessageIDs.count, | ||
| 277 | thread.messageCount ?? thread.threadRootMessageIDs.count, | ||
| 278 | mergedRootMessageIDs.count | ||
| 279 | ) | ||
| 280 | |||
| 281 | grouped[thread.threadGroupingKey] = InboxThreadSummary( | ||
| 282 | rootEmailID: latest.rootEmailID, | ||
| 283 | rootMessageID: latest.rootMessageID, | ||
| 284 | threadRootEmailIDs: mergedRootEmailIDs, | ||
| 285 | threadRootMessageIDs: mergedRootMessageIDs, | ||
| 286 | listID: latest.listID, | ||
| 287 | listRID: latest.listRID, | ||
| 288 | listName: latest.listName, | ||
| 289 | listOwner: latest.listOwner, | ||
| 290 | subject: latest.subject, | ||
| 291 | latestSender: latest.latestSender, | ||
| 292 | lastActivityAt: max(existing.lastActivityAt, thread.lastActivityAt), | ||
| 293 | messageCount: mergedMessageCount, | ||
| 294 | repo: latest.repo ?? existing.repo, | ||
| 295 | containsPatch: latest.containsPatch || existing.containsPatch, | ||
| 296 | isUnread: latest.isUnread || existing.isUnread | ||
| 297 | ) | ||
| 298 | } | ||
| 299 | |||
| 300 | return Array(grouped.values) | ||
| 301 | } | ||
| 302 | } | ||
Hutch/Models/RepositorySummary.swift +33
| @@ -94,3 +94,36 @@ nonisolated extension RepositorySummary { | |||
| 94 | referenceName.replacingOccurrences(of: "refs/heads/", with: "") | 94 | referenceName.replacingOccurrences(of: "refs/heads/", with: "") |
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | |||
| 98 | /// A git repository as the GraphQL API returns it. | ||
| 99 | nonisolated struct RepositoryPayload: Decodable, Sendable { | ||
| 100 | let id: Int | ||
| 101 | let rid: String | ||
| 102 | let name: String | ||
| 103 | let description: String? | ||
| 104 | let visibility: Visibility | ||
| 105 | let updated: Date | ||
| 106 | let owner: Entity | ||
| 107 | let head: Reference? | ||
| 108 | |||
| 109 | enum CodingKeys: String, CodingKey { | ||
| 110 | case id, rid, name, description, visibility, updated, owner | ||
| 111 | case head = "HEAD" | ||
| 112 | } | ||
| 113 | |||
| 114 | func repositorySummary(service: SRHTService) -> RepositorySummary { | ||
| 115 | RepositorySummary( | ||
| 116 | fields: .init( | ||
| 117 | id: id, | ||
| 118 | rid: rid, | ||
| 119 | service: service, | ||
| 120 | name: name, | ||
| 121 | description: description, | ||
| 122 | visibility: visibility, | ||
| 123 | updated: updated, | ||
| 124 | owner: owner, | ||
| 125 | head: head | ||
| 126 | ) | ||
| 127 | ) | ||
| 128 | } | ||
| 129 | } | ||
Hutch/Networking/Pagination.swift +14 −15
| @@ -155,22 +155,21 @@ struct RawJSON: Decodable, Sendable { | |||
| 155 | 155 | ||
| 156 | init(from decoder: any Decoder) throws { | 156 | init(from decoder: any Decoder) throws { |
| 157 | let container = try decoder.singleValueContainer() | 157 | let container = try decoder.singleValueContainer() |
| 158 | if let dict = try? container.decode([String: RawJSON].self) { | 158 | guard let value = Self.value(in: container) else { |
| 159 | value = dict.mapValues(\.value) | ||
| 160 | } else if let array = try? container.decode([RawJSON].self) { | ||
| 161 | value = array.map(\.value) | ||
| 162 | } else if let string = try? container.decode(String.self) { | ||
| 163 | value = string | ||
| 164 | } else if let int = try? container.decode(Int.self) { | ||
| 165 | value = int | ||
| 166 | } else if let double = try? container.decode(Double.self) { | ||
| 167 | value = double | ||
| 168 | } else if let bool = try? container.decode(Bool.self) { | ||
| 169 | value = bool | ||
| 170 | } else if container.decodeNil() { | ||
| 171 | value = NSNull() | ||
| 172 | } else { | ||
| 173 | throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unsupported JSON value") | 159 | throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unsupported JSON value") |
| 174 | } | 160 | } |
| 161 | self.value = value | ||
| 162 | } | ||
| 163 | |||
| 164 | /// The first of object, array, string, integer, double, bool or null the value decodes as. | ||
| 165 | private static func value(in container: any SingleValueDecodingContainer) -> Any? { | ||
| 166 | if let dict = try? container.decode([String: RawJSON].self) { return dict.mapValues(\.value) } | ||
| 167 | if let array = try? container.decode([RawJSON].self) { return array.map(\.value) } | ||
| 168 | if let string = try? container.decode(String.self) { return string } | ||
| 169 | if let int = try? container.decode(Int.self) { return int } | ||
| 170 | if let double = try? container.decode(Double.self) { return double } | ||
| 171 | if let bool = try? container.decode(Bool.self) { return bool } | ||
| 172 | if container.decodeNil() { return NSNull() } | ||
| 173 | return nil | ||
| 175 | } | 174 | } |
| 176 | } | 175 | } |
Hutch/Networking/ProjectService.swift +4 −28
| @@ -100,13 +100,14 @@ private struct ProjectDetailPayload: Decodable, Sendable { | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | private struct ProjectMailingListPage: Decodable, Sendable { | 102 | private struct ProjectMailingListPage: Decodable, Sendable { |
| 103 | let results: [ProjectMailingListPayload] | 103 | let results: [ProjectResourcePayload] |
| 104 | let cursor: String? | 104 | let cursor: String? |
| 105 | 105 | ||
| 106 | static let empty = ProjectMailingListPage(results: [], cursor: nil) | 106 | static let empty = ProjectMailingListPage(results: [], cursor: nil) |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | private struct ProjectMailingListPayload: Decodable, Sendable { | 109 | /// A mailing list or tracker linked to a project; both decode the same fields. |
| 110 | private struct ProjectResourcePayload: Decodable, Sendable { | ||
| 110 | let rid: String | 111 | let rid: String |
| 111 | let name: String | 112 | let name: String |
| 112 | let description: String? | 113 | let description: String? |
| @@ -167,37 +168,12 @@ private struct ProjectSourcePayload: Decodable, Sendable { | |||
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | private struct ProjectTrackerPage: Decodable, Sendable { | 170 | private struct ProjectTrackerPage: Decodable, Sendable { |
| 170 | let results: [ProjectTrackerPayload] | 171 | let results: [ProjectResourcePayload] |
| 171 | let cursor: String? | 172 | let cursor: String? |
| 172 | 173 | ||
| 173 | static let empty = ProjectTrackerPage(results: [], cursor: nil) | 174 | static let empty = ProjectTrackerPage(results: [], cursor: nil) |
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | private struct ProjectTrackerPayload: Decodable, Sendable { | ||
| 177 | let rid: String | ||
| 178 | let name: String | ||
| 179 | let description: String? | ||
| 180 | let visibility: Visibility | ||
| 181 | let owner: Entity | ||
| 182 | |||
| 183 | private enum CodingKeys: String, CodingKey { | ||
| 184 | case rid | ||
| 185 | case name | ||
| 186 | case description | ||
| 187 | case visibility | ||
| 188 | case owner | ||
| 189 | } | ||
| 190 | |||
| 191 | init(from decoder: any Decoder) throws { | ||
| 192 | let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| 193 | rid = try container.decode(String.self, forKey: .rid) | ||
| 194 | name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" | ||
| 195 | description = try container.decodeIfPresent(String.self, forKey: .description) | ||
| 196 | visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility | ||
| 197 | owner = try container.decodeIfPresent(Entity.self, forKey: .owner) ?? Entity(canonicalName: "~unknown") | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | /// A public project surfaced by discovery, carrying its owner for display. | 177 | /// A public project surfaced by discovery, carrying its owner for display. |
| 202 | struct DiscoveredProject: Identifiable, Hashable, Sendable { | 178 | struct DiscoveredProject: Identifiable, Hashable, Sendable { |
| 203 | let project: Project | 179 | let project: Project |
Hutch/Views/Builds/BuildDetailView.swift +267 −275
| @@ -156,222 +156,54 @@ struct BuildDetailView: View { | |||
| 156 | 156 | ||
| 157 | @ViewBuilder | 157 | @ViewBuilder |
| 158 | private func detailContent(_ viewModel: BuildDetailViewModel) -> some View { | 158 | private func detailContent(_ viewModel: BuildDetailViewModel) -> some View { |
| 159 | if viewModel.isLoading, viewModel.job == nil { | 159 | SRHTLoadStateView( |
| 160 | SRHTLoadingStateView(message: "Loading build…") | 160 | isLoading: viewModel.isLoading, |
| 161 | } else if let error = viewModel.error, viewModel.job == nil { | 161 | error: viewModel.error, |
| 162 | SRHTErrorStateView( | 162 | isEmpty: viewModel.job == nil, |
| 163 | title: "Couldn't Load Build", | 163 | loadingMessage: "Loading build…", |
| 164 | message: error, | 164 | errorTitle: "Couldn't Load Build", |
| 165 | retryAction: { await reloadDetail(viewModel) } | 165 | retryAction: { await reloadDetail(viewModel) } |
| 166 | ) | 166 | ) { |
| 167 | } else if let job = viewModel.job { | 167 | if let job = viewModel.job { |
| 168 | List { | 168 | List { |
| 169 | if let cacheMetadata = viewModel.cacheMetadata { | 169 | cacheSection(job, viewModel) |
| 170 | Section { | ||
| 171 | StaleCacheStatusRow(metadata: cacheMetadata, isRefreshing: viewModel.isRefreshingCachedData) | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | Section("Details") { | ||
| 176 | HStack { | ||
| 177 | Text("Status") | ||
| 178 | Spacer() | ||
| 179 | HStack(spacing: 6) { | ||
| 180 | JobStatusIcon(status: job.status) | ||
| 181 | Text(job.status.rawValue) | ||
| 182 | .font(.subheadline.weight(.medium)) | ||
| 183 | } | ||
| 184 | } | ||
| 185 | .themedRow() | ||
| 186 | 170 | ||
| 187 | if let note = job.note, !note.isEmpty { | 171 | detailsSection(job, viewModel) |
| 188 | LabeledContent("Note", value: note) | ||
| 189 | .themedRow() | ||
| 190 | } | ||
| 191 | 172 | ||
| 192 | if let image = job.image { | 173 | debugSection(job, viewModel) |
| 193 | LabeledContent("Image", value: image) | ||
| 194 | .themedRow() | ||
| 195 | } | ||
| 196 | 174 | ||
| 197 | if !job.tags.isEmpty { | 175 | sourceSection(job, viewModel) |
| 198 | LabeledContent("Tags", value: job.tags.joined(separator: ", ")) | ||
| 199 | .themedRow() | ||
| 200 | } | ||
| 201 | 176 | ||
| 202 | if let visibility = job.visibility { | 177 | artifactsSection(job, viewModel) |
| 203 | LabeledContent("Visibility", value: visibility.rawValue.capitalized) | ||
| 204 | .themedRow() | ||
| 205 | } | ||
| 206 | 178 | ||
| 207 | LabeledContent("Owner", value: job.owner.canonicalName) | 179 | // Per-task logs |
| 208 | .themedRow() | 180 | taskSections(job, viewModel) |
| 209 | LabeledContent("Created", value: job.created.relativeDescription) | ||
| 210 | .themedRow() | ||
| 211 | LabeledContent("Updated", value: job.updated.relativeDescription) | ||
| 212 | .themedRow() | ||
| 213 | } | ||
| 214 | 181 | ||
| 215 | if appState.isDebugModeEnabled { | 182 | // Cancel button |
| 216 | Section("Debug") { | 183 | cancelSection(job, viewModel) |
| 217 | DebugTextBlock( | ||
| 218 | title: "Diagnostics", | ||
| 219 | content: """ | ||
| 220 | jobId: \(job.id) | ||
| 221 | status: \(job.status.rawValue) | ||
| 222 | tasks: \(job.tasks.count) | ||
| 223 | artifacts: \(job.artifacts.count) | ||
| 224 | owner: \(job.owner.canonicalName) | ||
| 225 | url: \(SRHTWebURL.build(jobId: job.id, ownerCanonicalName: job.owner.canonicalName)?.absoluteString ?? "unavailable") | ||
| 226 | """ | ||
| 227 | ) | ||
| 228 | .themedRow() | ||
| 229 | 184 | ||
| 230 | if let rawJobResponse = viewModel.rawJobResponse { | 185 | rebuildSection(job, viewModel) |
| 231 | DebugTextBlock(title: "Raw Response", content: rawJobResponse) | ||
| 232 | .themedRow() | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | 186 | } |
| 236 | 187 | .themedList() | |
| 237 | if let repositoryReference = HomeViewModel.primaryRepositoryReference(in: job.manifest) { | 188 | .task(id: job.id) { |
| 238 | Section("Source") { | 189 | RecentActivityStore.recordBuild( |
| 239 | Button { | 190 | jobId: job.id, |
| 240 | openRepository(ownerCanonicalName: repositoryReference.ownerCanonicalName, repositoryName: repositoryReference.name) | 191 | title: recentActivityTitle(for: job), |
| 241 | } label: { | 192 | defaults: appState.accountDefaults |
| 242 | HStack { | 193 | ) |
| 243 | Label("\(repositoryReference.ownerCanonicalName)/\(repositoryReference.name)", systemImage: "book.closed") | ||
| 244 | Spacer() | ||
| 245 | if isOpeningRepository { | ||
| 246 | ProgressView() | ||
| 247 | .controlSize(.small) | ||
| 248 | } else { | ||
| 249 | Image(systemName: "arrow.up.right") | ||
| 250 | .font(.caption) | ||
| 251 | .foregroundStyle(.tertiary) | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } | ||
| 255 | .disabled(isOpeningRepository) | ||
| 256 | .themedRow() | ||
| 257 | } | ||
| 258 | } | 194 | } |
| 259 | 195 | .refreshable { | |
| 260 | if !job.artifacts.isEmpty { | 196 | await reloadDetail(viewModel) |
| 261 | Section { | ||
| 262 | ForEach(job.artifacts) { artifact in | ||
| 263 | BuildArtifactRow(artifact: artifact) { | ||
| 264 | guard let url = artifact.url else { return } | ||
| 265 | openURL(url) | ||
| 266 | } | ||
| 267 | } | ||
| 268 | .themedRow() | ||
| 269 | } header: { | ||
| 270 | Text("Artifacts") | ||
| 271 | } footer: { | ||
| 272 | if job.artifacts.contains(where: { !$0.isDownloadable }) { | ||
| 273 | Text("Artifacts without a download URL are no longer available for download.") | ||
| 274 | } | ||
| 275 | } | ||
| 276 | } | 197 | } |
| 277 | 198 | .srhtErrorBanner(error: Binding( | |
| 278 | // Per-task logs | 199 | get: { viewModel.error }, |
| 279 | if !job.tasks.isEmpty { | 200 | set: { viewModel.error = $0 } |
| 280 | ForEach(job.tasks) { task in | 201 | )) |
| 281 | Section { | 202 | .srhtErrorBanner(error: Binding( |
| 282 | Button { | 203 | get: { viewModel.actionError }, |
| 283 | selectedTaskName = task.name | 204 | set: { _ in viewModel.dismissActionError() } |
| 284 | } label: { | 205 | )) |
| 285 | HStack { | ||
| 286 | Text(task.status.rawValue.capitalized) | ||
| 287 | .font(.subheadline) | ||
| 288 | .foregroundStyle(.secondary) | ||
| 289 | Spacer() | ||
| 290 | Image(systemName: "chevron.right") | ||
| 291 | .font(.caption) | ||
| 292 | .foregroundStyle(.tertiary) | ||
| 293 | } | ||
| 294 | } | ||
| 295 | .foregroundStyle(.primary) | ||
| 296 | .themedRow() | ||
| 297 | } header: { | ||
| 298 | HStack(spacing: 6) { | ||
| 299 | TaskStatusIcon(status: task.status) | ||
| 300 | Text(task.name) | ||
| 301 | } | ||
| 302 | } | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | // Cancel button | ||
| 307 | if job.status.isCancellable { | ||
| 308 | Section { | ||
| 309 | Button(role: .destructive) { | ||
| 310 | showCancelConfirmation = true | ||
| 311 | } label: { | ||
| 312 | HStack { | ||
| 313 | Text("Cancel Build") | ||
| 314 | if viewModel.isCancelling { | ||
| 315 | Spacer() | ||
| 316 | ProgressView() | ||
| 317 | } | ||
| 318 | } | ||
| 319 | } | ||
| 320 | .disabled(viewModel.isCancelling) | ||
| 321 | .themedRow() | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | if let manifest = job.manifest, | ||
| 326 | !manifest.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | ||
| 327 | Section { | ||
| 328 | Button { | ||
| 329 | Task { | ||
| 330 | rebuiltJobId = await viewModel.rebuildJob() | ||
| 331 | } | ||
| 332 | } label: { | ||
| 333 | HStack { | ||
| 334 | Text(job.status == .failed || job.status == .cancelled || job.status == .timeout ? "Retry Build" : "Rebuild") | ||
| 335 | if viewModel.isRebuilding { | ||
| 336 | Spacer() | ||
| 337 | ProgressView() | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | .disabled(viewModel.isRebuilding) | ||
| 342 | .themedRow() | ||
| 343 | |||
| 344 | Button { | ||
| 345 | showEditResubmitSheet = true | ||
| 346 | } label: { | ||
| 347 | Text("Edit & Resubmit") | ||
| 348 | } | ||
| 349 | .disabled(viewModel.isSubmittingEditedBuild) | ||
| 350 | .themedRow() | ||
| 351 | } footer: { | ||
| 352 | Text("Creates a new build using this job’s saved manifest, tags, note, and visibility.") | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | ||
| 356 | .themedList() | ||
| 357 | .task(id: job.id) { | ||
| 358 | RecentActivityStore.recordBuild( | ||
| 359 | jobId: job.id, | ||
| 360 | title: recentActivityTitle(for: job), | ||
| 361 | defaults: appState.accountDefaults | ||
| 362 | ) | ||
| 363 | } | 206 | } |
| 364 | .refreshable { | ||
| 365 | await reloadDetail(viewModel) | ||
| 366 | } | ||
| 367 | .srhtErrorBanner(error: Binding( | ||
| 368 | get: { viewModel.error }, | ||
| 369 | set: { viewModel.error = $0 } | ||
| 370 | )) | ||
| 371 | .srhtErrorBanner(error: Binding( | ||
| 372 | get: { viewModel.actionError }, | ||
| 373 | set: { _ in viewModel.dismissActionError() } | ||
| 374 | )) | ||
| 375 | } | 207 | } |
| 376 | } | 208 | } |
| 377 | 209 | ||
| @@ -407,6 +239,216 @@ struct BuildDetailView: View { | |||
| 407 | } | 239 | } |
| 408 | return "Job #\(job.id)" | 240 | return "Job #\(job.id)" |
| 409 | } | 241 | } |
| 242 | |||
| 243 | |||
| 244 | @ViewBuilder | ||
| 245 | private func cancelSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 246 | if job.status.isCancellable { | ||
| 247 | Section { | ||
| 248 | Button(role: .destructive) { | ||
| 249 | showCancelConfirmation = true | ||
| 250 | } label: { | ||
| 251 | HStack { | ||
| 252 | Text("Cancel Build") | ||
| 253 | if viewModel.isCancelling { | ||
| 254 | Spacer() | ||
| 255 | ProgressView() | ||
| 256 | } | ||
| 257 | } | ||
| 258 | } | ||
| 259 | .disabled(viewModel.isCancelling) | ||
| 260 | .themedRow() | ||
| 261 | } | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | @ViewBuilder | ||
| 266 | private func taskSections(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 267 | if !job.tasks.isEmpty { | ||
| 268 | ForEach(job.tasks) { task in | ||
| 269 | Section { | ||
| 270 | Button { | ||
| 271 | selectedTaskName = task.name | ||
| 272 | } label: { | ||
| 273 | HStack { | ||
| 274 | Text(task.status.rawValue.capitalized) | ||
| 275 | .font(.subheadline) | ||
| 276 | .foregroundStyle(.secondary) | ||
| 277 | Spacer() | ||
| 278 | Image(systemName: "chevron.right") | ||
| 279 | .font(.caption) | ||
| 280 | .foregroundStyle(.tertiary) | ||
| 281 | } | ||
| 282 | } | ||
| 283 | .foregroundStyle(.primary) | ||
| 284 | .themedRow() | ||
| 285 | } header: { | ||
| 286 | HStack(spacing: 6) { | ||
| 287 | TaskStatusIcon(status: task.status) | ||
| 288 | Text(task.name) | ||
| 289 | } | ||
| 290 | } | ||
| 291 | } | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | @ViewBuilder | ||
| 296 | private func artifactsSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 297 | if !job.artifacts.isEmpty { | ||
| 298 | Section { | ||
| 299 | ForEach(job.artifacts) { artifact in | ||
| 300 | BuildArtifactRow(artifact: artifact) { | ||
| 301 | guard let url = artifact.url else { return } | ||
| 302 | openURL(url) | ||
| 303 | } | ||
| 304 | } | ||
| 305 | .themedRow() | ||
| 306 | } header: { | ||
| 307 | Text("Artifacts") | ||
| 308 | } footer: { | ||
| 309 | if job.artifacts.contains(where: { !$0.isDownloadable }) { | ||
| 310 | Text("Artifacts without a download URL are no longer available for download.") | ||
| 311 | } | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | @ViewBuilder | ||
| 317 | private func sourceSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 318 | if let repositoryReference = HomeViewModel.primaryRepositoryReference(in: job.manifest) { | ||
| 319 | Section("Source") { | ||
| 320 | Button { | ||
| 321 | openRepository(ownerCanonicalName: repositoryReference.ownerCanonicalName, repositoryName: repositoryReference.name) | ||
| 322 | } label: { | ||
| 323 | HStack { | ||
| 324 | Label("\(repositoryReference.ownerCanonicalName)/\(repositoryReference.name)", systemImage: "book.closed") | ||
| 325 | Spacer() | ||
| 326 | if isOpeningRepository { | ||
| 327 | ProgressView() | ||
| 328 | .controlSize(.small) | ||
| 329 | } else { | ||
| 330 | Image(systemName: "arrow.up.right") | ||
| 331 | .font(.caption) | ||
| 332 | .foregroundStyle(.tertiary) | ||
| 333 | } | ||
| 334 | } | ||
| 335 | } | ||
| 336 | .disabled(isOpeningRepository) | ||
| 337 | .themedRow() | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | @ViewBuilder | ||
| 343 | private func debugSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 344 | if appState.isDebugModeEnabled { | ||
| 345 | Section("Debug") { | ||
| 346 | DebugTextBlock( | ||
| 347 | title: "Diagnostics", | ||
| 348 | content: """ | ||
| 349 | jobId: \(job.id) | ||
| 350 | status: \(job.status.rawValue) | ||
| 351 | tasks: \(job.tasks.count) | ||
| 352 | artifacts: \(job.artifacts.count) | ||
| 353 | owner: \(job.owner.canonicalName) | ||
| 354 | url: \(SRHTWebURL.build(jobId: job.id, ownerCanonicalName: job.owner.canonicalName)?.absoluteString ?? "unavailable") | ||
| 355 | """ | ||
| 356 | ) | ||
| 357 | .themedRow() | ||
| 358 | |||
| 359 | if let rawJobResponse = viewModel.rawJobResponse { | ||
| 360 | DebugTextBlock(title: "Raw Response", content: rawJobResponse) | ||
| 361 | .themedRow() | ||
| 362 | } | ||
| 363 | } | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | @ViewBuilder | ||
| 368 | private func detailsSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 369 | Section("Details") { | ||
| 370 | HStack { | ||
| 371 | Text("Status") | ||
| 372 | Spacer() | ||
| 373 | HStack(spacing: 6) { | ||
| 374 | JobStatusIcon(status: job.status) | ||
| 375 | Text(job.status.rawValue) | ||
| 376 | .font(.subheadline.weight(.medium)) | ||
| 377 | } | ||
| 378 | } | ||
| 379 | .themedRow() | ||
| 380 | |||
| 381 | if let note = job.note, !note.isEmpty { | ||
| 382 | LabeledContent("Note", value: note) | ||
| 383 | .themedRow() | ||
| 384 | } | ||
| 385 | |||
| 386 | if let image = job.image { | ||
| 387 | LabeledContent("Image", value: image) | ||
| 388 | .themedRow() | ||
| 389 | } | ||
| 390 | |||
| 391 | if !job.tags.isEmpty { | ||
| 392 | LabeledContent("Tags", value: job.tags.joined(separator: ", ")) | ||
| 393 | .themedRow() | ||
| 394 | } | ||
| 395 | |||
| 396 | if let visibility = job.visibility { | ||
| 397 | LabeledContent("Visibility", value: visibility.rawValue.capitalized) | ||
| 398 | .themedRow() | ||
| 399 | } | ||
| 400 | |||
| 401 | LabeledContent("Owner", value: job.owner.canonicalName) | ||
| 402 | .themedRow() | ||
| 403 | LabeledContent("Created", value: job.created.relativeDescription) | ||
| 404 | .themedRow() | ||
| 405 | LabeledContent("Updated", value: job.updated.relativeDescription) | ||
| 406 | .themedRow() | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | @ViewBuilder | ||
| 411 | private func cacheSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 412 | if let cacheMetadata = viewModel.cacheMetadata { | ||
| 413 | Section { | ||
| 414 | StaleCacheStatusRow(metadata: cacheMetadata, isRefreshing: viewModel.isRefreshingCachedData) | ||
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | @ViewBuilder | ||
| 420 | private func rebuildSection(_ job: JobDetail, _ viewModel: BuildDetailViewModel) -> some View { | ||
| 421 | if let manifest = job.manifest, | ||
| 422 | !manifest.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | ||
| 423 | Section { | ||
| 424 | Button { | ||
| 425 | Task { | ||
| 426 | rebuiltJobId = await viewModel.rebuildJob() | ||
| 427 | } | ||
| 428 | } label: { | ||
| 429 | HStack { | ||
| 430 | Text(job.status == .failed || job.status == .cancelled || job.status == .timeout ? "Retry Build" : "Rebuild") | ||
| 431 | if viewModel.isRebuilding { | ||
| 432 | Spacer() | ||
| 433 | ProgressView() | ||
| 434 | } | ||
| 435 | } | ||
| 436 | } | ||
| 437 | .disabled(viewModel.isRebuilding) | ||
| 438 | .themedRow() | ||
| 439 | |||
| 440 | Button { | ||
| 441 | showEditResubmitSheet = true | ||
| 442 | } label: { | ||
| 443 | Text("Edit & Resubmit") | ||
| 444 | } | ||
| 445 | .disabled(viewModel.isSubmittingEditedBuild) | ||
| 446 | .themedRow() | ||
| 447 | } footer: { | ||
| 448 | Text("Creates a new build using this job’s saved manifest, tags, note, and visibility.") | ||
| 449 | } | ||
| 450 | } | ||
| 451 | } | ||
| 410 | } | 452 | } |
| 411 | 453 | ||
| 412 | private struct BuildArtifactRow: View { | 454 | private struct BuildArtifactRow: View { |
| @@ -460,74 +502,28 @@ private struct EditResubmitBuildSheet: View { | |||
| 460 | let onSubmitted: (Int) -> Void | 502 | let onSubmitted: (Int) -> Void |
| 461 | 503 | ||
| 462 | @Environment(\.dismiss) private var dismiss | 504 | @Environment(\.dismiss) private var dismiss |
| 463 | @State private var manifest: String | 505 | @State private var draft: BuildDraft |
| 464 | @State private var tagsText: String | ||
| 465 | @State private var note: String | ||
| 466 | @State private var secrets = false | ||
| 467 | @State private var execute = true | ||
| 468 | @State private var visibility: Visibility | ||
| 469 | 506 | ||
| 470 | init(viewModel: BuildDetailViewModel, job: JobDetail, onSubmitted: @escaping (Int) -> Void) { | 507 | init(viewModel: BuildDetailViewModel, job: JobDetail, onSubmitted: @escaping (Int) -> Void) { |
| 471 | self.viewModel = viewModel | 508 | self.viewModel = viewModel |
| 472 | self.job = job | 509 | self.job = job |
| 473 | self.onSubmitted = onSubmitted | 510 | self.onSubmitted = onSubmitted |
| 474 | _manifest = State(initialValue: job.manifest ?? "") | 511 | _draft = State(initialValue: BuildDraft( |
| 475 | _tagsText = State(initialValue: job.tags.joined(separator: ", ")) | 512 | manifest: job.manifest ?? "", |
| 476 | _note = State(initialValue: job.note ?? "") | 513 | tagsText: job.tags.joined(separator: ", "), |
| 477 | _visibility = State(initialValue: job.visibility ?? .publicVisibility) | 514 | note: job.note ?? "", |
| 515 | visibility: job.visibility ?? .publicVisibility | ||
| 516 | )) | ||
| 478 | } | 517 | } |
| 479 | 518 | ||
| 480 | var body: some View { | 519 | var body: some View { |
| 481 | NavigationStack { | 520 | NavigationStack { |
| 482 | Form { | 521 | BuildDraftForm( |
| 483 | Section("Build Manifest") { | 522 | draft: $draft, |
| 484 | TextField("Build manifest", text: $manifest, axis: .vertical) | 523 | manifestPlaceholder: "Build manifest", |
| 485 | .font(.system(.body, design: .monospaced)) | 524 | footnote: "This submits a new build. “Start build now” and “Allow build secrets” use local defaults because the current job does not include those original values.", |
| 486 | .lineLimit(12...24) | 525 | error: viewModel.actionError |
| 487 | .textInputAutocapitalization(.never) | 526 | ) |
| 488 | .autocorrectionDisabled() | ||
| 489 | .themedRow() | ||
| 490 | } | ||
| 491 | |||
| 492 | Section("Build Options") { | ||
| 493 | TextField("Note (optional)", text: $note) | ||
| 494 | .themedRow() | ||
| 495 | TextField("Tags (comma-separated, optional)", text: $tagsText) | ||
| 496 | .textInputAutocapitalization(.never) | ||
| 497 | .autocorrectionDisabled() | ||
| 498 | .themedRow() | ||
| 499 | Picker("Visibility", selection: $visibility) { | ||
| 500 | Text("Public").tag(Visibility.publicVisibility) | ||
| 501 | Text("Unlisted").tag(Visibility.unlisted) | ||
| 502 | Text("Private").tag(Visibility.privateVisibility) | ||
| 503 | } | ||
| 504 | .themedRow() | ||
| 505 | Toggle("Start build now", isOn: $execute) | ||
| 506 | .themedRow() | ||
| 507 | Toggle("Allow build secrets", isOn: $secrets) | ||
| 508 | .themedRow() | ||
| 509 | } | ||
| 510 | |||
| 511 | Section { | ||
| 512 | Text("This submits a new build. “Start build now” and “Allow build secrets” use local defaults because the current job does not include those original values.") | ||
| 513 | .font(.footnote) | ||
| 514 | .foregroundStyle(.secondary) | ||
| 515 | .themedRow() | ||
| 516 | } | ||
| 517 | |||
| 518 | if let actionError = viewModel.actionError { | ||
| 519 | Section { | ||
| 520 | Label { | ||
| 521 | Text(actionError) | ||
| 522 | } icon: { | ||
| 523 | Image(systemName: "exclamationmark.triangle.fill") | ||
| 524 | .foregroundStyle(.red) | ||
| 525 | } | ||
| 526 | .foregroundStyle(.red) | ||
| 527 | .themedRow() | ||
| 528 | } | ||
| 529 | } | ||
| 530 | } | ||
| 531 | .navigationTitle("Edit & Resubmit") | 527 | .navigationTitle("Edit & Resubmit") |
| 532 | .navigationBarTitleDisplayMode(.inline) | 528 | .navigationBarTitleDisplayMode(.inline) |
| 533 | .onDisappear { | 529 | .onDisappear { |
| @@ -543,17 +539,13 @@ private struct EditResubmitBuildSheet: View { | |||
| 543 | ToolbarItem(placement: .confirmationAction) { | 539 | ToolbarItem(placement: .confirmationAction) { |
| 544 | Button { | 540 | Button { |
| 545 | Task { | 541 | Task { |
| 546 | let tags = tagsText | ||
| 547 | .split(separator: ",") | ||
| 548 | .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
| 549 | .filter { !$0.isEmpty } | ||
| 550 | if let jobId = await viewModel.submitBuild( | 542 | if let jobId = await viewModel.submitBuild( |
| 551 | manifest: manifest, | 543 | manifest: draft.manifest, |
| 552 | tags: tags, | 544 | tags: draft.tags, |
| 553 | note: note, | 545 | note: draft.note, |
| 554 | secrets: secrets, | 546 | secrets: draft.secrets, |
| 555 | execute: execute, | 547 | execute: draft.execute, |
| 556 | visibility: visibility | 548 | visibility: draft.visibility |
| 557 | ) { | 549 | ) { |
| 558 | onSubmitted(jobId) | 550 | onSubmitted(jobId) |
| 559 | } | 551 | } |
| @@ -566,7 +558,7 @@ private struct EditResubmitBuildSheet: View { | |||
| 566 | Text("Submit Build") | 558 | Text("Submit Build") |
| 567 | } | 559 | } |
| 568 | } | 560 | } |
| 569 | .disabled(manifest.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isSubmittingEditedBuild) | 561 | .disabled(!draft.hasManifest || viewModel.isSubmittingEditedBuild) |
| 570 | } | 562 | } |
| 571 | } | 563 | } |
| 572 | .themedList() | 564 | .themedList() |
Hutch/Views/Builds/BuildDraftForm.swift added +83
| @@ -0,0 +1,83 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | /// A build about to be submitted: its manifest and the options it runs with. | ||
| 4 | struct BuildDraft { | ||
| 5 | var manifest = "" | ||
| 6 | var tagsText = "" | ||
| 7 | var note = "" | ||
| 8 | var secrets = false | ||
| 9 | var execute = true | ||
| 10 | var visibility: Visibility = .publicVisibility | ||
| 11 | |||
| 12 | /// The comma-separated tags, trimmed, without empties. | ||
| 13 | var tags: [String] { | ||
| 14 | tagsText | ||
| 15 | .split(separator: ",") | ||
| 16 | .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
| 17 | .filter { !$0.isEmpty } | ||
| 18 | } | ||
| 19 | |||
| 20 | var hasManifest: Bool { | ||
| 21 | !manifest.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | /// The fields of a build submission, with a note under them and the last error, if any. | ||
| 26 | struct BuildDraftForm: View { | ||
| 27 | @Binding var draft: BuildDraft | ||
| 28 | let manifestPlaceholder: String | ||
| 29 | let footnote: String | ||
| 30 | let error: String? | ||
| 31 | |||
| 32 | var body: some View { | ||
| 33 | Form { | ||
| 34 | Section("Build Manifest") { | ||
| 35 | TextField(manifestPlaceholder, text: $draft.manifest, axis: .vertical) | ||
| 36 | .font(.system(.body, design: .monospaced)) | ||
| 37 | .lineLimit(12...24) | ||
| 38 | .textInputAutocapitalization(.never) | ||
| 39 | .autocorrectionDisabled() | ||
| 40 | .themedRow() | ||
| 41 | } | ||
| 42 | |||
| 43 | Section("Build Options") { | ||
| 44 | TextField("Note (optional)", text: $draft.note) | ||
| 45 | .themedRow() | ||
| 46 | TextField("Tags (comma-separated, optional)", text: $draft.tagsText) | ||
| 47 | .textInputAutocapitalization(.never) | ||
| 48 | .autocorrectionDisabled() | ||
| 49 | .themedRow() | ||
| 50 | Picker("Visibility", selection: $draft.visibility) { | ||
| 51 | Text("Public").tag(Visibility.publicVisibility) | ||
| 52 | Text("Unlisted").tag(Visibility.unlisted) | ||
| 53 | Text("Private").tag(Visibility.privateVisibility) | ||
| 54 | } | ||
| 55 | .themedRow() | ||
| 56 | Toggle("Start build now", isOn: $draft.execute) | ||
| 57 | .themedRow() | ||
| 58 | Toggle("Allow build secrets", isOn: $draft.secrets) | ||
| 59 | .themedRow() | ||
| 60 | } | ||
| 61 | |||
| 62 | Section { | ||
| 63 | Text(footnote) | ||
| 64 | .font(.footnote) | ||
| 65 | .foregroundStyle(.secondary) | ||
| 66 | .themedRow() | ||
| 67 | } | ||
| 68 | |||
| 69 | if let error { | ||
| 70 | Section { | ||
| 71 | Label { | ||
| 72 | Text(error) | ||
| 73 | } icon: { | ||
| 74 | Image(systemName: "exclamationmark.triangle.fill") | ||
| 75 | .foregroundStyle(.red) | ||
| 76 | } | ||
| 77 | .foregroundStyle(.red) | ||
| 78 | .themedRow() | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
Hutch/Views/Builds/BuildListView.swift +82 −123
| @@ -168,48 +168,7 @@ struct BuildListView: View { | |||
| 168 | .listRowSeparator(.hidden) | 168 | .listRowSeparator(.hidden) |
| 169 | 169 | ||
| 170 | ForEach(viewModel.filteredJobs) { job in | 170 | ForEach(viewModel.filteredJobs) { job in |
| 171 | NavigationLink(value: job) { | 171 | jobRow(job, viewModel) |
| 172 | BuildRowView(job: job) | ||
| 173 | .equatable() | ||
| 174 | } | ||
| 175 | .contextMenu { | ||
| 176 | Button { | ||
| 177 | appState.copyToPasteboard(String(job.id), label: "job ID") | ||
| 178 | } label: { | ||
| 179 | Label("Copy Job ID", systemImage: "doc.on.doc") | ||
| 180 | } | ||
| 181 | |||
| 182 | if let note = job.note, !note.isEmpty { | ||
| 183 | Button { | ||
| 184 | appState.copyToPasteboard(note, label: "build note") | ||
| 185 | } label: { | ||
| 186 | Label("Copy Note", systemImage: "text.alignleft") | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | if !job.tags.isEmpty { | ||
| 191 | Button { | ||
| 192 | appState.copyToPasteboard(job.tags.joined(separator: ", "), label: "build tags") | ||
| 193 | } label: { | ||
| 194 | Label("Copy Tags", systemImage: "tag") | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 199 | if swipeActionsEnabled, job.status.isCancellable { | ||
| 200 | Button { | ||
| 201 | Task { | ||
| 202 | await viewModel.cancelJob(job) | ||
| 203 | } | ||
| 204 | } label: { | ||
| 205 | Label("Cancel", systemImage: "xmark.circle") | ||
| 206 | } | ||
| 207 | .tint(.red) | ||
| 208 | } | ||
| 209 | } | ||
| 210 | .task { | ||
| 211 | await viewModel.loadMoreIfNeeded(currentItem: job) | ||
| 212 | } | ||
| 213 | } | 172 | } |
| 214 | .themedRow() | 173 | .themedRow() |
| 215 | 174 | ||
| @@ -250,16 +209,29 @@ struct BuildListView: View { | |||
| 250 | viewModel.recordRecentSearch(query) | 209 | viewModel.recordRecentSearch(query) |
| 251 | } | 210 | } |
| 252 | .overlay { | 211 | .overlay { |
| 253 | if viewModel.isLoading, viewModel.jobs.isEmpty { | 212 | emptyState(viewModel) |
| 254 | SRHTLoadingStateView(message: "Loading builds…") | 213 | } |
| 255 | } else if let error = viewModel.error, viewModel.jobs.isEmpty { | 214 | .connectivityOverlay(hasContent: !viewModel.jobs.isEmpty) { |
| 256 | SRHTErrorStateView( | 215 | await viewModel.loadJobs() |
| 257 | title: "Couldn't Load Builds", | 216 | } |
| 258 | message: error, | 217 | .srhtErrorBanner(error: $vm.error) |
| 259 | retryAction: { await viewModel.loadJobs() } | 218 | .refreshable { |
| 260 | ) | 219 | await viewModel.loadJobs() |
| 261 | } else if !viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, | 220 | } |
| 262 | viewModel.filteredJobs.isEmpty { | 221 | } |
| 222 | |||
| 223 | @ViewBuilder | ||
| 224 | private func emptyState(_ viewModel: BuildListViewModel) -> some View { | ||
| 225 | SRHTLoadStateView( | ||
| 226 | isLoading: viewModel.isLoading, | ||
| 227 | error: viewModel.error, | ||
| 228 | isEmpty: viewModel.jobs.isEmpty, | ||
| 229 | loadingMessage: "Loading builds…", | ||
| 230 | errorTitle: "Couldn't Load Builds", | ||
| 231 | retryAction: { await viewModel.loadJobs() } | ||
| 232 | ) { | ||
| 233 | if !viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, | ||
| 234 | viewModel.filteredJobs.isEmpty { | ||
| 263 | ContentUnavailableView( | 235 | ContentUnavailableView( |
| 264 | "No Build Matches", | 236 | "No Build Matches", |
| 265 | systemImage: "magnifyingglass", | 237 | systemImage: "magnifyingglass", |
| @@ -279,12 +251,51 @@ struct BuildListView: View { | |||
| 279 | ) | 251 | ) |
| 280 | } | 252 | } |
| 281 | } | 253 | } |
| 282 | .connectivityOverlay(hasContent: !viewModel.jobs.isEmpty) { | 254 | } |
| 283 | await viewModel.loadJobs() | 255 | |
| 256 | @ViewBuilder | ||
| 257 | private func jobRow(_ job: JobSummary, _ viewModel: BuildListViewModel) -> some View { | ||
| 258 | NavigationLink(value: job) { | ||
| 259 | BuildRowView(job: job) | ||
| 260 | .equatable() | ||
| 284 | } | 261 | } |
| 285 | .srhtErrorBanner(error: $vm.error) | 262 | .contextMenu { |
| 286 | .refreshable { | 263 | Button { |
| 287 | await viewModel.loadJobs() | 264 | appState.copyToPasteboard(String(job.id), label: "job ID") |
| 265 | } label: { | ||
| 266 | Label("Copy Job ID", systemImage: "doc.on.doc") | ||
| 267 | } | ||
| 268 | |||
| 269 | if let note = job.note, !note.isEmpty { | ||
| 270 | Button { | ||
| 271 | appState.copyToPasteboard(note, label: "build note") | ||
| 272 | } label: { | ||
| 273 | Label("Copy Note", systemImage: "text.alignleft") | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | if !job.tags.isEmpty { | ||
| 278 | Button { | ||
| 279 | appState.copyToPasteboard(job.tags.joined(separator: ", "), label: "build tags") | ||
| 280 | } label: { | ||
| 281 | Label("Copy Tags", systemImage: "tag") | ||
| 282 | } | ||
| 283 | } | ||
| 284 | } | ||
| 285 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 286 | if swipeActionsEnabled, job.status.isCancellable { | ||
| 287 | Button { | ||
| 288 | Task { | ||
| 289 | await viewModel.cancelJob(job) | ||
| 290 | } | ||
| 291 | } label: { | ||
| 292 | Label("Cancel", systemImage: "xmark.circle") | ||
| 293 | } | ||
| 294 | .tint(.red) | ||
| 295 | } | ||
| 296 | } | ||
| 297 | .task { | ||
| 298 | await viewModel.loadMoreIfNeeded(currentItem: job) | ||
| 288 | } | 299 | } |
| 289 | } | 300 | } |
| 290 | } | 301 | } |
| @@ -295,12 +306,7 @@ private struct SubmitBuildSheet: View { | |||
| 295 | 306 | ||
| 296 | @Environment(\.dismiss) private var dismiss | 307 | @Environment(\.dismiss) private var dismiss |
| 297 | @Bindable var viewModelBindable: BuildListViewModel | 308 | @Bindable var viewModelBindable: BuildListViewModel |
| 298 | @State private var manifest = "" | 309 | @State private var draft = BuildDraft() |
| 299 | @State private var tagsText = "" | ||
| 300 | @State private var note = "" | ||
| 301 | @State private var secrets = false | ||
| 302 | @State private var execute = true | ||
| 303 | @State private var visibility: Visibility = .publicVisibility | ||
| 304 | 310 | ||
| 305 | init(viewModel: BuildListViewModel, onSubmitted: @escaping (Int) -> Void) { | 311 | init(viewModel: BuildListViewModel, onSubmitted: @escaping (Int) -> Void) { |
| 306 | self.viewModel = viewModel | 312 | self.viewModel = viewModel |
| @@ -310,55 +316,12 @@ private struct SubmitBuildSheet: View { | |||
| 310 | 316 | ||
| 311 | var body: some View { | 317 | var body: some View { |
| 312 | NavigationStack { | 318 | NavigationStack { |
| 313 | Form { | 319 | BuildDraftForm( |
| 314 | Section("Build Manifest") { | 320 | draft: $draft, |
| 315 | TextField("Paste a build manifest", text: $manifest, axis: .vertical) | 321 | manifestPlaceholder: "Paste a build manifest", |
| 316 | .font(.system(.body, design: .monospaced)) | 322 | footnote: "You need a valid builds.sr.ht manifest and a token with BUILDS:RW.", |
| 317 | .lineLimit(12...24) | 323 | error: viewModel.error |
| 318 | .textInputAutocapitalization(.never) | 324 | ) |
| 319 | .autocorrectionDisabled() | ||
| 320 | .themedRow() | ||
| 321 | } | ||
| 322 | |||
| 323 | Section("Build Options") { | ||
| 324 | TextField("Note (optional)", text: $note) | ||
| 325 | .themedRow() | ||
| 326 | TextField("Tags (comma-separated, optional)", text: $tagsText) | ||
| 327 | .textInputAutocapitalization(.never) | ||
| 328 | .autocorrectionDisabled() | ||
| 329 | .themedRow() | ||
| 330 | Picker("Visibility", selection: $visibility) { | ||
| 331 | Text("Public").tag(Visibility.publicVisibility) | ||
| 332 | Text("Unlisted").tag(Visibility.unlisted) | ||
| 333 | Text("Private").tag(Visibility.privateVisibility) | ||
| 334 | } | ||
| 335 | .themedRow() | ||
| 336 | Toggle("Start build now", isOn: $execute) | ||
| 337 | .themedRow() | ||
| 338 | Toggle("Allow build secrets", isOn: $secrets) | ||
| 339 | .themedRow() | ||
| 340 | } | ||
| 341 | |||
| 342 | Section { | ||
| 343 | Text("You need a valid builds.sr.ht manifest and a token with BUILDS:RW.") | ||
| 344 | .font(.footnote) | ||
| 345 | .foregroundStyle(.secondary) | ||
| 346 | .themedRow() | ||
| 347 | } | ||
| 348 | |||
| 349 | if let error = viewModel.error { | ||
| 350 | Section { | ||
| 351 | Label { | ||
| 352 | Text(error) | ||
| 353 | } icon: { | ||
| 354 | Image(systemName: "exclamationmark.triangle.fill") | ||
| 355 | .foregroundStyle(.red) | ||
| 356 | } | ||
| 357 | .foregroundStyle(.red) | ||
| 358 | .themedRow() | ||
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
| 362 | .themedList() | 325 | .themedList() |
| 363 | .navigationTitle("Submit Build") | 326 | .navigationTitle("Submit Build") |
| 364 | .navigationBarTitleDisplayMode(.inline) | 327 | .navigationBarTitleDisplayMode(.inline) |
| @@ -375,17 +338,13 @@ private struct SubmitBuildSheet: View { | |||
| 375 | ToolbarItem(placement: .confirmationAction) { | 338 | ToolbarItem(placement: .confirmationAction) { |
| 376 | Button { | 339 | Button { |
| 377 | Task { | 340 | Task { |
| 378 | let tags = tagsText | ||
| 379 | .split(separator: ",") | ||
| 380 | .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
| 381 | .filter { !$0.isEmpty } | ||
| 382 | if let jobId = await viewModel.submitBuild( | 341 | if let jobId = await viewModel.submitBuild( |
| 383 | manifest: manifest, | 342 | manifest: draft.manifest, |
| 384 | tags: tags, | 343 | tags: draft.tags, |
| 385 | note: note, | 344 | note: draft.note, |
| 386 | secrets: secrets, | 345 | secrets: draft.secrets, |
| 387 | execute: execute, | 346 | execute: draft.execute, |
| 388 | visibility: visibility | 347 | visibility: draft.visibility |
| 389 | ) { | 348 | ) { |
| 390 | onSubmitted(jobId) | 349 | onSubmitted(jobId) |
| 391 | } | 350 | } |
| @@ -398,7 +357,7 @@ private struct SubmitBuildSheet: View { | |||
| 398 | Text("Submit Build") | 357 | Text("Submit Build") |
| 399 | } | 358 | } |
| 400 | } | 359 | } |
| 401 | .disabled(manifest.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || viewModel.isSubmitting) | 360 | .disabled(!draft.hasManifest || viewModel.isSubmitting) |
| 402 | } | 361 | } |
| 403 | } | 362 | } |
| 404 | } | 363 | } |
Hutch/Views/Home/HomeView.swift +1 −7
| @@ -438,13 +438,7 @@ struct HomeView: View { | |||
| 438 | return viewModel | 438 | return viewModel |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | let newViewModel = HomeViewModel( | 441 | let newViewModel = HomeViewModel(currentUser: currentUser, appState: appState) |
| 442 | currentUser: currentUser, | ||
| 443 | client: appState.client, | ||
| 444 | systemStatusRepository: appState.systemStatusRepository, | ||
| 445 | defaults: appState.accountDefaults, | ||
| 446 | accountID: appState.activeAccountID | ||
| 447 | ) | ||
| 448 | viewModel = newViewModel | 442 | viewModel = newViewModel |
| 449 | return newViewModel | 443 | return newViewModel |
| 450 | } | 444 | } |
Hutch/Views/Home/HomeViewModel.swift +13 −54
| @@ -329,6 +329,17 @@ final class HomeViewModel { | |||
| 329 | private let defaults: UserDefaults | 329 | private let defaults: UserDefaults |
| 330 | private let accountID: String | 330 | private let accountID: String |
| 331 | 331 | ||
| 332 | /// A view model for `currentUser` on the app's active account. | ||
| 333 | convenience init(currentUser: User, appState: AppState) { | ||
| 334 | self.init( | ||
| 335 | currentUser: currentUser, | ||
| 336 | client: appState.client, | ||
| 337 | systemStatusRepository: appState.systemStatusRepository, | ||
| 338 | defaults: appState.accountDefaults, | ||
| 339 | accountID: appState.activeAccountID | ||
| 340 | ) | ||
| 341 | } | ||
| 342 | |||
| 332 | init( | 343 | init( |
| 333 | currentUser: User, | 344 | currentUser: User, |
| 334 | client: SRHTClient, | 345 | client: SRHTClient, |
| @@ -694,23 +705,7 @@ final class HomeViewModel { | |||
| 694 | InboxReadStateStore.markUnread(for: thread.threadGroupingKey, defaults: defaults) | 705 | InboxReadStateStore.markUnread(for: thread.threadGroupingKey, defaults: defaults) |
| 695 | if unreadInboxThreads.contains(where: { $0.id == thread.id }) == false { | 706 | if unreadInboxThreads.contains(where: { $0.id == thread.id }) == false { |
| 696 | unreadInboxThreads.append( | 707 | unreadInboxThreads.append( |
| 697 | InboxThreadSummary( | 708 | thread.withUnread(true) |
| 698 | rootEmailID: thread.rootEmailID, | ||
| 699 | rootMessageID: thread.rootMessageID, | ||
| 700 | threadRootEmailIDs: thread.threadRootEmailIDs, | ||
| 701 | threadRootMessageIDs: thread.threadRootMessageIDs, | ||
| 702 | listID: thread.listID, | ||
| 703 | listRID: thread.listRID, | ||
| 704 | listName: thread.listName, | ||
| 705 | listOwner: thread.listOwner, | ||
| 706 | subject: thread.subject, | ||
| 707 | latestSender: thread.latestSender, | ||
| 708 | lastActivityAt: thread.lastActivityAt, | ||
| 709 | messageCount: thread.messageCount, | ||
| 710 | repo: thread.repo, | ||
| 711 | containsPatch: thread.containsPatch, | ||
| 712 | isUnread: true | ||
| 713 | ) | ||
| 714 | ) | 709 | ) |
| 715 | unreadInboxThreads.sort(by: Self.sortInboxThreadsForTriage) | 710 | unreadInboxThreads.sort(by: Self.sortInboxThreadsForTriage) |
| 716 | } | 711 | } |
| @@ -1203,43 +1198,7 @@ final class HomeViewModel { | |||
| 1203 | } | 1198 | } |
| 1204 | 1199 | ||
| 1205 | nonisolated static func deduplicateInboxThreads(_ threads: [InboxThreadSummary]) -> [InboxThreadSummary] { | 1200 | nonisolated static func deduplicateInboxThreads(_ threads: [InboxThreadSummary]) -> [InboxThreadSummary] { |
| 1206 | var grouped: [String: InboxThreadSummary] = [:] | 1201 | return InboxThreadSummary.mergedByThread(threads).sorted(by: sortInboxThreadsForTriage) |
| 1207 | |||
| 1208 | for thread in threads { | ||
| 1209 | guard let existing = grouped[thread.threadGroupingKey] else { | ||
| 1210 | grouped[thread.threadGroupingKey] = thread | ||
| 1211 | continue | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | let latest = thread.lastActivityAt >= existing.lastActivityAt ? thread : existing | ||
| 1215 | let mergedRootEmailIDs = Array(Set(existing.threadRootEmailIDs + thread.threadRootEmailIDs)).sorted() | ||
| 1216 | let mergedRootMessageIDs = Array(Set(existing.threadRootMessageIDs + thread.threadRootMessageIDs)).sorted() | ||
| 1217 | let mergedMessageCount = max( | ||
| 1218 | existing.messageCount ?? existing.threadRootMessageIDs.count, | ||
| 1219 | thread.messageCount ?? thread.threadRootMessageIDs.count, | ||
| 1220 | mergedRootMessageIDs.count | ||
| 1221 | ) | ||
| 1222 | |||
| 1223 | grouped[thread.threadGroupingKey] = InboxThreadSummary( | ||
| 1224 | rootEmailID: latest.rootEmailID, | ||
| 1225 | rootMessageID: latest.rootMessageID, | ||
| 1226 | threadRootEmailIDs: mergedRootEmailIDs, | ||
| 1227 | threadRootMessageIDs: mergedRootMessageIDs, | ||
| 1228 | listID: latest.listID, | ||
| 1229 | listRID: latest.listRID, | ||
| 1230 | listName: latest.listName, | ||
| 1231 | listOwner: latest.listOwner, | ||
| 1232 | subject: latest.subject, | ||
| 1233 | latestSender: latest.latestSender, | ||
| 1234 | lastActivityAt: max(existing.lastActivityAt, thread.lastActivityAt), | ||
| 1235 | messageCount: mergedMessageCount, | ||
| 1236 | repo: latest.repo ?? existing.repo, | ||
| 1237 | containsPatch: latest.containsPatch || existing.containsPatch, | ||
| 1238 | isUnread: latest.isUnread || existing.isUnread | ||
| 1239 | ) | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | return grouped.values.sorted(by: sortInboxThreadsForTriage) | ||
| 1243 | } | 1202 | } |
| 1244 | 1203 | ||
| 1245 | nonisolated static func matchesCurrentUserAssignee(_ entity: Entity, currentUser: User) -> Bool { | 1204 | nonisolated static func matchesCurrentUserAssignee(_ entity: Entity, currentUser: User) -> Bool { |
Hutch/Views/Inbox/ThreadDetailView.swift +89 −79
| @@ -114,54 +114,9 @@ struct ThreadDetailView: View { | |||
| 114 | 114 | ||
| 115 | List { | 115 | List { |
| 116 | if let thread = viewModel.thread { | 116 | if let thread = viewModel.thread { |
| 117 | Section { | 117 | headerSection(thread) |
| 118 | VStack(alignment: .leading, spacing: 6) { | ||
| 119 | Text(thread.displaySubject) | ||
| 120 | .font(.headline) | ||
| 121 | Text(headerMetadata(thread)) | ||
| 122 | .font(.caption) | ||
| 123 | .foregroundStyle(.secondary) | ||
| 124 | } | ||
| 125 | .padding(.vertical, 4) | ||
| 126 | .themedRow() | ||
| 127 | } | ||
| 128 | 118 | ||
| 129 | Section("Related") { | 119 | relatedSection(thread) |
| 130 | Button { | ||
| 131 | appState.navigateToMailingList( | ||
| 132 | InboxMailingListReference( | ||
| 133 | id: thread.listID, | ||
| 134 | rid: thread.listRID, | ||
| 135 | name: thread.listName, | ||
| 136 | owner: thread.listOwner | ||
| 137 | ) | ||
| 138 | ) | ||
| 139 | } label: { | ||
| 140 | Label(thread.listDisplayName, systemImage: "list.bullet") | ||
| 141 | } | ||
| 142 | .themedRow() | ||
| 143 | |||
| 144 | if let repo = self.thread.repo { | ||
| 145 | Button { | ||
| 146 | openRepository(named: repo, ownerCanonicalName: thread.listOwner.canonicalName) | ||
| 147 | } label: { | ||
| 148 | HStack { | ||
| 149 | Label("\(thread.listOwner.canonicalName)/\(repo)", systemImage: "book.closed") | ||
| 150 | Spacer() | ||
| 151 | if isOpeningRepository { | ||
| 152 | ProgressView() | ||
| 153 | .controlSize(.small) | ||
| 154 | } else { | ||
| 155 | Image(systemName: "arrow.up.right") | ||
| 156 | .font(.caption) | ||
| 157 | .foregroundStyle(.tertiary) | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | .disabled(isOpeningRepository) | ||
| 162 | .themedRow() | ||
| 163 | } | ||
| 164 | } | ||
| 165 | 120 | ||
| 166 | if let partialWarning = viewModel.partialWarning { | 121 | if let partialWarning = viewModel.partialWarning { |
| 167 | Section { | 122 | Section { |
| @@ -179,11 +134,7 @@ struct ThreadDetailView: View { | |||
| 179 | canCollapse: thread.messages.count > 1, | 134 | canCollapse: thread.messages.count > 1, |
| 180 | onToggleCollapse: { | 135 | onToggleCollapse: { |
| 181 | withAnimation(.easeInOut(duration: 0.2)) { | 136 | withAnimation(.easeInOut(duration: 0.2)) { |
| 182 | if collapsedMessageIDs.contains(message.id) { | 137 | collapsedMessageIDs.formSymmetricDifference([message.id]) |
| 183 | collapsedMessageIDs.remove(message.id) | ||
| 184 | } else { | ||
| 185 | collapsedMessageIDs.insert(message.id) | ||
| 186 | } | ||
| 187 | } | 138 | } |
| 188 | } | 139 | } |
| 189 | ) | 140 | ) |
| @@ -195,36 +146,18 @@ struct ThreadDetailView: View { | |||
| 195 | .listStyle(.plain) | 146 | .listStyle(.plain) |
| 196 | .toolbar { | 147 | .toolbar { |
| 197 | ToolbarItem(placement: .topBarTrailing) { | 148 | ToolbarItem(placement: .topBarTrailing) { |
| 198 | HStack { | 149 | toolbarButtons(viewModel) |
| 199 | if onMarkRead != nil || onMarkUnread != nil { | ||
| 200 | Button(isUnread ? "Mark Read" : "Mark Unread") { | ||
| 201 | suppressAutoMarkViewed = !isUnread | ||
| 202 | if isUnread { | ||
| 203 | onMarkRead?() | ||
| 204 | isUnread = false | ||
| 205 | } else { | ||
| 206 | onMarkUnread?() | ||
| 207 | isUnread = true | ||
| 208 | } | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | Button("Reply") { | ||
| 213 | viewModel.prepareReply() | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } | 150 | } |
| 217 | } | 151 | } |
| 218 | .overlay { | 152 | .overlay { |
| 219 | if viewModel.isLoading, viewModel.thread == nil { | 153 | SRHTLoadStateView( |
| 220 | SRHTLoadingStateView(message: "Loading thread…") | 154 | isLoading: viewModel.isLoading, |
| 221 | } else if let error = viewModel.error, viewModel.thread == nil { | 155 | error: viewModel.error, |
| 222 | SRHTErrorStateView( | 156 | isEmpty: viewModel.thread == nil, |
| 223 | title: "Failed to load thread", | 157 | loadingMessage: "Loading thread…", |
| 224 | message: error, | 158 | errorTitle: "Failed to load thread", |
| 225 | retryAction: { await viewModel.loadThread() } | 159 | retryAction: { await viewModel.loadThread() } |
| 226 | ) | 160 | ) {} |
| 227 | } | ||
| 228 | } | 161 | } |
| 229 | .srhtErrorBanner(error: $vm.error) | 162 | .srhtErrorBanner(error: $vm.error) |
| 230 | .refreshable { | 163 | .refreshable { |
| @@ -255,6 +188,83 @@ struct ThreadDetailView: View { | |||
| 255 | } | 188 | } |
| 256 | } | 189 | } |
| 257 | } | 190 | } |
| 191 | |||
| 192 | @ViewBuilder | ||
| 193 | private func relatedSection(_ thread: InboxThreadDetail) -> some View { | ||
| 194 | Section("Related") { | ||
| 195 | Button { | ||
| 196 | appState.navigateToMailingList( | ||
| 197 | InboxMailingListReference( | ||
| 198 | id: thread.listID, | ||
| 199 | rid: thread.listRID, | ||
| 200 | name: thread.listName, | ||
| 201 | owner: thread.listOwner | ||
| 202 | ) | ||
| 203 | ) | ||
| 204 | } label: { | ||
| 205 | Label(thread.listDisplayName, systemImage: "list.bullet") | ||
| 206 | } | ||
| 207 | .themedRow() | ||
| 208 | |||
| 209 | if let repo = self.thread.repo { | ||
| 210 | Button { | ||
| 211 | openRepository(named: repo, ownerCanonicalName: thread.listOwner.canonicalName) | ||
| 212 | } label: { | ||
| 213 | HStack { | ||
| 214 | Label("\(thread.listOwner.canonicalName)/\(repo)", systemImage: "book.closed") | ||
| 215 | Spacer() | ||
| 216 | if isOpeningRepository { | ||
| 217 | ProgressView() | ||
| 218 | .controlSize(.small) | ||
| 219 | } else { | ||
| 220 | Image(systemName: "arrow.up.right") | ||
| 221 | .font(.caption) | ||
| 222 | .foregroundStyle(.tertiary) | ||
| 223 | } | ||
| 224 | } | ||
| 225 | } | ||
| 226 | .disabled(isOpeningRepository) | ||
| 227 | .themedRow() | ||
| 228 | } | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | @ViewBuilder | ||
| 233 | private func headerSection(_ thread: InboxThreadDetail) -> some View { | ||
| 234 | Section { | ||
| 235 | VStack(alignment: .leading, spacing: 6) { | ||
| 236 | Text(thread.displaySubject) | ||
| 237 | .font(.headline) | ||
| 238 | Text(headerMetadata(thread)) | ||
| 239 | .font(.caption) | ||
| 240 | .foregroundStyle(.secondary) | ||
| 241 | } | ||
| 242 | .padding(.vertical, 4) | ||
| 243 | .themedRow() | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | @ViewBuilder | ||
| 248 | private func toolbarButtons(_ viewModel: ThreadViewModel) -> some View { | ||
| 249 | HStack { | ||
| 250 | if onMarkRead != nil || onMarkUnread != nil { | ||
| 251 | Button(isUnread ? "Mark Read" : "Mark Unread") { | ||
| 252 | suppressAutoMarkViewed = !isUnread | ||
| 253 | if isUnread { | ||
| 254 | onMarkRead?() | ||
| 255 | isUnread = false | ||
| 256 | } else { | ||
| 257 | onMarkUnread?() | ||
| 258 | isUnread = true | ||
| 259 | } | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | Button("Reply") { | ||
| 264 | viewModel.prepareReply() | ||
| 265 | } | ||
| 266 | } | ||
| 267 | } | ||
| 258 | } | 268 | } |
| 259 | 269 | ||
| 260 | private struct InboxMessageRow: View { | 270 | private struct InboxMessageRow: View { |
Hutch/Views/Lists/MailingListListView.swift +17 −16
| @@ -461,22 +461,23 @@ struct MailingListListView: View { | |||
| 461 | Text("This permanently deletes the list and its entire archive, for everyone. This cannot be undone.") | 461 | Text("This permanently deletes the list and its entire archive, for everyone. This cannot be undone.") |
| 462 | } | 462 | } |
| 463 | .overlay { | 463 | .overlay { |
| 464 | if viewModel.isLoading, viewModel.mailingLists.isEmpty { | 464 | SRHTLoadStateView( |
| 465 | SRHTLoadingStateView(message: "Loading mailing lists…") | 465 | isLoading: viewModel.isLoading, |
| 466 | } else if let error = viewModel.error, viewModel.mailingLists.isEmpty { | 466 | error: viewModel.error, |
| 467 | SRHTErrorStateView( | 467 | isEmpty: viewModel.mailingLists.isEmpty, |
| 468 | title: "Couldn't Load Mailing Lists", | 468 | loadingMessage: "Loading mailing lists…", |
| 469 | message: error, | 469 | errorTitle: "Couldn't Load Mailing Lists", |
| 470 | retryAction: { await viewModel.loadMailingLists() } | 470 | retryAction: { await viewModel.loadMailingLists() } |
| 471 | ) | 471 | ) { |
| 472 | } else if !viewModel.mailingLists.isEmpty, viewModel.filteredMailingLists.isEmpty { | 472 | if !viewModel.mailingLists.isEmpty, viewModel.filteredMailingLists.isEmpty { |
| 473 | ContentUnavailableView.search(text: viewModel.searchText) | 473 | ContentUnavailableView.search(text: viewModel.searchText) |
| 474 | } else if viewModel.mailingLists.isEmpty { | 474 | } else if viewModel.mailingLists.isEmpty { |
| 475 | ContentUnavailableView( | 475 | ContentUnavailableView( |
| 476 | "No Mailing Lists", | 476 | "No Mailing Lists", |
| 477 | systemImage: "list.bullet.rectangle", | 477 | systemImage: "list.bullet.rectangle", |
| 478 | description: Text("Your subscribed mailing lists will appear here.") | 478 | description: Text("Your subscribed mailing lists will appear here.") |
| 479 | ) | 479 | ) |
| 480 | } | ||
| 480 | } | 481 | } |
| 481 | } | 482 | } |
| 482 | .srhtErrorBanner(error: $vm.error) | 483 | .srhtErrorBanner(error: $vm.error) |
Hutch/Views/Lookup/UserProfileView.swift +3 −2
| @@ -177,7 +177,7 @@ struct UserProfileView: View { | |||
| 177 | NavigationLink { | 177 | NavigationLink { |
| 178 | TicketListView(tracker: tracker) | 178 | TicketListView(tracker: tracker) |
| 179 | } label: { | 179 | } label: { |
| 180 | UserProfileTrackerRowView(tracker: tracker) | 180 | TrackerSummaryRow(tracker: tracker) |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | .themedRow() | 183 | .themedRow() |
| @@ -260,7 +260,8 @@ struct UserProfileView: View { | |||
| 260 | } | 260 | } |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | struct UserProfileTrackerRowView: View { | 263 | /// A tracker's name, visibility, owner, description and last update. |
| 264 | struct TrackerSummaryRow: View { | ||
| 264 | let tracker: TrackerSummary | 265 | let tracker: TrackerSummary |
| 265 | 266 | ||
| 266 | var body: some View { | 267 | var body: some View { |
Hutch/Views/Lookup/UserProfileViewModel.swift −33
| @@ -169,39 +169,6 @@ final class UserProfileViewModel { | |||
| 169 | let results: [RepositoryPayload] | 169 | let results: [RepositoryPayload] |
| 170 | let cursor: String? | 170 | let cursor: String? |
| 171 | } | 171 | } |
| 172 | |||
| 173 | private struct RepositoryPayload: Decodable, Sendable { | ||
| 174 | let id: Int | ||
| 175 | let rid: String | ||
| 176 | let name: String | ||
| 177 | let description: String? | ||
| 178 | let visibility: Visibility | ||
| 179 | let updated: Date | ||
| 180 | let owner: Entity | ||
| 181 | let head: Reference? | ||
| 182 | |||
| 183 | enum CodingKeys: String, CodingKey { | ||
| 184 | case id, rid, name, description, visibility, updated, owner | ||
| 185 | case head = "HEAD" | ||
| 186 | } | ||
| 187 | |||
| 188 | func repositorySummary(service: SRHTService) -> RepositorySummary { | ||
| 189 | RepositorySummary( | ||
| 190 | fields: .init( | ||
| 191 | id: id, | ||
| 192 | rid: rid, | ||
| 193 | service: service, | ||
| 194 | name: name, | ||
| 195 | description: description, | ||
| 196 | visibility: visibility, | ||
| 197 | updated: updated, | ||
| 198 | owner: owner, | ||
| 199 | head: head | ||
| 200 | ) | ||
| 201 | ) | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | private struct UserTrackersResponse: Decodable, Sendable { | 172 | private struct UserTrackersResponse: Decodable, Sendable { |
| 206 | let user: UserTrackersContainer | 173 | let user: UserTrackersContainer |
| 207 | } | 174 | } |
Hutch/Views/Lookup/UserTrackersView.swift +1 −1
| @@ -9,7 +9,7 @@ struct UserTrackersView: View { | |||
| 9 | NavigationLink { | 9 | NavigationLink { |
| 10 | TicketListView(tracker: tracker) | 10 | TicketListView(tracker: tracker) |
| 11 | } label: { | 11 | } label: { |
| 12 | UserProfileTrackerRowView(tracker: tracker) | 12 | TrackerSummaryRow(tracker: tracker) |
| 13 | } | 13 | } |
| 14 | } | 14 | } |
| 15 | .themedRow() | 15 | .themedRow() |
Hutch/Views/More/ProfileView.swift +146 −141
| @@ -89,15 +89,14 @@ struct ProfileView: View { | |||
| 89 | } | 89 | } |
| 90 | .themedList() | 90 | .themedList() |
| 91 | .overlay { | 91 | .overlay { |
| 92 | if viewModel.isLoading, viewModel.profile == nil { | 92 | SRHTLoadStateView( |
| 93 | SRHTLoadingStateView(message: "Loading profile…") | 93 | isLoading: viewModel.isLoading, |
| 94 | } else if let error = viewModel.error, viewModel.profile == nil { | 94 | error: viewModel.error, |
| 95 | SRHTErrorStateView( | 95 | isEmpty: viewModel.profile == nil, |
| 96 | title: "Couldn't Load Profile", | 96 | loadingMessage: "Loading profile…", |
| 97 | message: error, | 97 | errorTitle: "Couldn't Load Profile", |
| 98 | retryAction: { await viewModel.loadProfile() } | 98 | retryAction: { await viewModel.loadProfile() } |
| 99 | ) | 99 | ) {} |
| 100 | } | ||
| 101 | } | 100 | } |
| 102 | .sheet(isPresented: Binding( | 101 | .sheet(isPresented: Binding( |
| 103 | get: { viewModel.isEditingProfile }, | 102 | get: { viewModel.isEditingProfile }, |
| @@ -160,36 +159,7 @@ struct ProfileView: View { | |||
| 160 | @ViewBuilder | 159 | @ViewBuilder |
| 161 | private func profileSection(_ profile: UserProfile, viewModel: SettingsViewModel) -> some View { | 160 | private func profileSection(_ profile: UserProfile, viewModel: SettingsViewModel) -> some View { |
| 162 | Section("Profile") { | 161 | Section("Profile") { |
| 163 | HStack(spacing: 12) { | 162 | profileHeader(profile) |
| 164 | AsyncImage(url: profile.avatar.flatMap { URL(string: $0) }) { phase in | ||
| 165 | if case .success(let image) = phase { | ||
| 166 | image | ||
| 167 | .resizable() | ||
| 168 | .scaledToFill() | ||
| 169 | } else { | ||
| 170 | Image(systemName: "person.crop.circle.fill") | ||
| 171 | .resizable() | ||
| 172 | .foregroundStyle(.secondary) | ||
| 173 | } | ||
| 174 | } | ||
| 175 | .frame(width: 56, height: 56) | ||
| 176 | .clipShape(Circle()) | ||
| 177 | |||
| 178 | VStack(alignment: .leading, spacing: 2) { | ||
| 179 | Text(profile.canonicalName) | ||
| 180 | .font(.headline) | ||
| 181 | Text(profile.email) | ||
| 182 | .font(.subheadline) | ||
| 183 | .foregroundStyle(.secondary) | ||
| 184 | if let userType = profile.userType { | ||
| 185 | Text(userType.capitalized) | ||
| 186 | .font(.caption) | ||
| 187 | .foregroundStyle(.tertiary) | ||
| 188 | } | ||
| 189 | } | ||
| 190 | } | ||
| 191 | .padding(.vertical, 4) | ||
| 192 | .themedRow() | ||
| 193 | 163 | ||
| 194 | if let bio = profile.bio, !bio.isEmpty { | 164 | if let bio = profile.bio, !bio.isEmpty { |
| 195 | VStack(alignment: .leading, spacing: 2) { | 165 | VStack(alignment: .leading, spacing: 2) { |
| @@ -216,16 +186,7 @@ struct ProfileView: View { | |||
| 216 | .themedRow() | 186 | .themedRow() |
| 217 | } | 187 | } |
| 218 | 188 | ||
| 219 | if let sub = profile.subscription { | 189 | subscriptionRows(profile) |
| 220 | if let status = sub.status { | ||
| 221 | LabeledContent("Subscription", value: status.capitalized) | ||
| 222 | .themedRow() | ||
| 223 | } | ||
| 224 | if let interval = sub.interval { | ||
| 225 | LabeledContent("Interval", value: interval.capitalized) | ||
| 226 | .themedRow() | ||
| 227 | } | ||
| 228 | } | ||
| 229 | 190 | ||
| 230 | Button("Edit Profile") { | 191 | Button("Edit Profile") { |
| 231 | viewModel.isEditingProfile = true | 192 | viewModel.isEditingProfile = true |
| @@ -275,39 +236,13 @@ struct ProfileView: View { | |||
| 275 | } | 236 | } |
| 276 | .themedRow() | 237 | .themedRow() |
| 277 | 238 | ||
| 278 | if viewModel.isAddingSSHKey { | 239 | AddKeyControls( |
| 279 | TextField( | 240 | kind: "SSH", |
| 280 | "Paste SSH public key", | 241 | systemImage: "key", |
| 281 | text: Binding( | 242 | isAdding: Binding(get: { viewModel.isAddingSSHKey }, set: { viewModel.isAddingSSHKey = $0 }), |
| 282 | get: { viewModel.newSSHKey }, | 243 | key: Binding(get: { viewModel.newSSHKey }, set: { viewModel.newSSHKey = $0 }) |
| 283 | set: { viewModel.newSSHKey = $0 } | 244 | ) { |
| 284 | ), | 245 | await viewModel.addSSHKey() |
| 285 | axis: .vertical | ||
| 286 | ) | ||
| 287 | .font(.caption.monospaced()) | ||
| 288 | .lineLimit(3...6) | ||
| 289 | .themedRow() | ||
| 290 | |||
| 291 | HStack { | ||
| 292 | Button("Cancel") { | ||
| 293 | viewModel.isAddingSSHKey = false | ||
| 294 | viewModel.newSSHKey = "" | ||
| 295 | } | ||
| 296 | Spacer() | ||
| 297 | Button("Add") { | ||
| 298 | Task { await viewModel.addSSHKey() } | ||
| 299 | } | ||
| 300 | .buttonStyle(.borderedProminent) | ||
| 301 | .disabled(viewModel.newSSHKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| 302 | } | ||
| 303 | .themedRow() | ||
| 304 | } else { | ||
| 305 | Button { | ||
| 306 | viewModel.isAddingSSHKey = true | ||
| 307 | } label: { | ||
| 308 | SwiftUI.Label("Add SSH Key", systemImage: "key") | ||
| 309 | } | ||
| 310 | .themedRow() | ||
| 311 | } | 246 | } |
| 312 | } header: { | 247 | } header: { |
| 313 | Text("SSH Keys") | 248 | Text("SSH Keys") |
| @@ -338,39 +273,13 @@ struct ProfileView: View { | |||
| 338 | } | 273 | } |
| 339 | .themedRow() | 274 | .themedRow() |
| 340 | 275 | ||
| 341 | if viewModel.isAddingPGPKey { | 276 | AddKeyControls( |
| 342 | TextField( | 277 | kind: "PGP", |
| 343 | "Paste PGP public key", | 278 | systemImage: "key.fill", |
| 344 | text: Binding( | 279 | isAdding: Binding(get: { viewModel.isAddingPGPKey }, set: { viewModel.isAddingPGPKey = $0 }), |
| 345 | get: { viewModel.newPGPKey }, | 280 | key: Binding(get: { viewModel.newPGPKey }, set: { viewModel.newPGPKey = $0 }) |
| 346 | set: { viewModel.newPGPKey = $0 } | 281 | ) { |
| 347 | ), | 282 | await viewModel.addPGPKey() |
| 348 | axis: .vertical | ||
| 349 | ) | ||
| 350 | .font(.caption.monospaced()) | ||
| 351 | .lineLimit(3...6) | ||
| 352 | .themedRow() | ||
| 353 | |||
| 354 | HStack { | ||
| 355 | Button("Cancel") { | ||
| 356 | viewModel.isAddingPGPKey = false | ||
| 357 | viewModel.newPGPKey = "" | ||
| 358 | } | ||
| 359 | Spacer() | ||
| 360 | Button("Add") { | ||
| 361 | Task { await viewModel.addPGPKey() } | ||
| 362 | } | ||
| 363 | .buttonStyle(.borderedProminent) | ||
| 364 | .disabled(viewModel.newPGPKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| 365 | } | ||
| 366 | .themedRow() | ||
| 367 | } else { | ||
| 368 | Button { | ||
| 369 | viewModel.isAddingPGPKey = true | ||
| 370 | } label: { | ||
| 371 | SwiftUI.Label("Add PGP Key", systemImage: "key.fill") | ||
| 372 | } | ||
| 373 | .themedRow() | ||
| 374 | } | 283 | } |
| 375 | } header: { | 284 | } header: { |
| 376 | Text("PGP Keys") | 285 | Text("PGP Keys") |
| @@ -396,32 +305,7 @@ struct ProfileView: View { | |||
| 396 | .themedRow() | 305 | .themedRow() |
| 397 | } else { | 306 | } else { |
| 398 | ForEach(viewModel.personalAccessTokens) { token in | 307 | ForEach(viewModel.personalAccessTokens) { token in |
| 399 | VStack(alignment: .leading, spacing: 4) { | 308 | PersonalAccessTokenRow(token: token) |
| 400 | HStack { | ||
| 401 | Text(token.comment ?? "Token #\(token.id)") | ||
| 402 | .font(.subheadline) | ||
| 403 | Spacer() | ||
| 404 | } | ||
| 405 | |||
| 406 | HStack(spacing: 12) { | ||
| 407 | Text("Issued \(token.issued.relativeDescription)") | ||
| 408 | .font(.caption2) | ||
| 409 | .foregroundStyle(.secondary) | ||
| 410 | |||
| 411 | if let expires = token.expires { | ||
| 412 | Text("Expires \(expires.relativeDescription)") | ||
| 413 | .font(.caption2) | ||
| 414 | .foregroundStyle(expires < Date.now ? .red : .secondary) | ||
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | if let grants = token.grants, !grants.isEmpty { | ||
| 419 | Text(grants) | ||
| 420 | .font(.caption2.monospaced()) | ||
| 421 | .foregroundStyle(.tertiary) | ||
| 422 | .lineLimit(2) | ||
| 423 | } | ||
| 424 | } | ||
| 425 | } | 309 | } |
| 426 | .themedRow() | 310 | .themedRow() |
| 427 | } | 311 | } |
| @@ -488,6 +372,127 @@ struct ProfileView: View { | |||
| 488 | Text("Recent security-relevant activity on your account, newest first. The full log lives on meta.sr.ht.") | 372 | Text("Recent security-relevant activity on your account, newest first. The full log lives on meta.sr.ht.") |
| 489 | } | 373 | } |
| 490 | } | 374 | } |
| 375 | |||
| 376 | @ViewBuilder | ||
| 377 | private func subscriptionRows(_ profile: UserProfile) -> some View { | ||
| 378 | if let sub = profile.subscription { | ||
| 379 | if let status = sub.status { | ||
| 380 | LabeledContent("Subscription", value: status.capitalized) | ||
| 381 | .themedRow() | ||
| 382 | } | ||
| 383 | if let interval = sub.interval { | ||
| 384 | LabeledContent("Interval", value: interval.capitalized) | ||
| 385 | .themedRow() | ||
| 386 | } | ||
| 387 | } | ||
| 388 | } | ||
| 389 | |||
| 390 | @ViewBuilder | ||
| 391 | private func profileHeader(_ profile: UserProfile) -> some View { | ||
| 392 | HStack(spacing: 12) { | ||
| 393 | AsyncImage(url: profile.avatar.flatMap { URL(string: $0) }) { phase in | ||
| 394 | if case .success(let image) = phase { | ||
| 395 | image | ||
| 396 | .resizable() | ||
| 397 | .scaledToFill() | ||
| 398 | } else { | ||
| 399 | Image(systemName: "person.crop.circle.fill") | ||
| 400 | .resizable() | ||
| 401 | .foregroundStyle(.secondary) | ||
| 402 | } | ||
| 403 | } | ||
| 404 | .frame(width: 56, height: 56) | ||
| 405 | .clipShape(Circle()) | ||
| 406 | |||
| 407 | VStack(alignment: .leading, spacing: 2) { | ||
| 408 | Text(profile.canonicalName) | ||
| 409 | .font(.headline) | ||
| 410 | Text(profile.email) | ||
| 411 | .font(.subheadline) | ||
| 412 | .foregroundStyle(.secondary) | ||
| 413 | if let userType = profile.userType { | ||
| 414 | Text(userType.capitalized) | ||
| 415 | .font(.caption) | ||
| 416 | .foregroundStyle(.tertiary) | ||
| 417 | } | ||
| 418 | } | ||
| 419 | } | ||
| 420 | .padding(.vertical, 4) | ||
| 421 | .themedRow() | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | /// A key list's add field and its Cancel and Add buttons, or the button that opens them. | ||
| 426 | private struct AddKeyControls: View { | ||
| 427 | /// "SSH", "PGP". | ||
| 428 | let kind: String | ||
| 429 | let systemImage: String | ||
| 430 | @Binding var isAdding: Bool | ||
| 431 | @Binding var key: String | ||
| 432 | let add: () async -> Void | ||
| 433 | |||
| 434 | var body: some View { | ||
| 435 | if isAdding { | ||
| 436 | TextField("Paste \(kind) public key", text: $key, axis: .vertical) | ||
| 437 | .font(.caption.monospaced()) | ||
| 438 | .lineLimit(3...6) | ||
| 439 | .themedRow() | ||
| 440 | |||
| 441 | HStack { | ||
| 442 | Button("Cancel") { | ||
| 443 | isAdding = false | ||
| 444 | key = "" | ||
| 445 | } | ||
| 446 | Spacer() | ||
| 447 | Button("Add") { | ||
| 448 | Task { await add() } | ||
| 449 | } | ||
| 450 | .buttonStyle(.borderedProminent) | ||
| 451 | .disabled(key.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| 452 | } | ||
| 453 | .themedRow() | ||
| 454 | } else { | ||
| 455 | Button { | ||
| 456 | isAdding = true | ||
| 457 | } label: { | ||
| 458 | SwiftUI.Label("Add \(kind) Key", systemImage: systemImage) | ||
| 459 | } | ||
| 460 | .themedRow() | ||
| 461 | } | ||
| 462 | } | ||
| 463 | } | ||
| 464 | |||
| 465 | private struct PersonalAccessTokenRow: View { | ||
| 466 | let token: PersonalAccessToken | ||
| 467 | |||
| 468 | var body: some View { | ||
| 469 | VStack(alignment: .leading, spacing: 4) { | ||
| 470 | HStack { | ||
| 471 | Text(token.comment ?? "Token #\(token.id)") | ||
| 472 | .font(.subheadline) | ||
| 473 | Spacer() | ||
| 474 | } | ||
| 475 | |||
| 476 | HStack(spacing: 12) { | ||
| 477 | Text("Issued \(token.issued.relativeDescription)") | ||
| 478 | .font(.caption2) | ||
| 479 | .foregroundStyle(.secondary) | ||
| 480 | |||
| 481 | if let expires = token.expires { | ||
| 482 | Text("Expires \(expires.relativeDescription)") | ||
| 483 | .font(.caption2) | ||
| 484 | .foregroundStyle(expires < Date.now ? .red : .secondary) | ||
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 | if let grants = token.grants, !grants.isEmpty { | ||
| 489 | Text(grants) | ||
| 490 | .font(.caption2.monospaced()) | ||
| 491 | .foregroundStyle(.tertiary) | ||
| 492 | .lineLimit(2) | ||
| 493 | } | ||
| 494 | } | ||
| 495 | } | ||
| 491 | } | 496 | } |
| 492 | 497 | ||
| 493 | private struct ProfileBioView: View { | 498 | private struct ProfileBioView: View { |
Hutch/Views/Pastes/PasteDetailView.swift +35 −54
| @@ -110,38 +110,39 @@ struct PasteDetailView: View { | |||
| 110 | private func content(_ viewModel: PasteDetailViewModel) -> some View { | 110 | private func content(_ viewModel: PasteDetailViewModel) -> some View { |
| 111 | @Bindable var vm = viewModel | 111 | @Bindable var vm = viewModel |
| 112 | 112 | ||
| 113 | if viewModel.isLoading, viewModel.paste == nil { | 113 | SRHTLoadStateView( |
| 114 | SRHTLoadingStateView(message: "Loading paste…") | 114 | isLoading: viewModel.isLoading, |
| 115 | } else if let error = viewModel.error, viewModel.paste == nil { | 115 | error: viewModel.error, |
| 116 | SRHTErrorStateView( | 116 | isEmpty: viewModel.paste == nil, |
| 117 | title: "Couldn't Load Paste", | 117 | loadingMessage: "Loading paste…", |
| 118 | message: error, | 118 | errorTitle: "Couldn't Load Paste", |
| 119 | retryAction: { await viewModel.loadPaste() } | 119 | retryAction: { await viewModel.loadPaste() } |
| 120 | ) | 120 | ) { |
| 121 | } else if let paste = viewModel.paste { | 121 | if let paste = viewModel.paste { |
| 122 | VStack(spacing: 0) { | 122 | VStack(spacing: 0) { |
| 123 | fileHeaderBar(paste: paste, viewModel: viewModel) | 123 | fileHeaderBar(paste: paste, viewModel: viewModel) |
| 124 | Divider() | 124 | Divider() |
| 125 | fileContentArea(viewModel: viewModel) | 125 | fileContentArea(viewModel: viewModel) |
| 126 | } | ||
| 127 | .safeAreaInset(edge: .bottom, spacing: 0) { | ||
| 128 | actionToolbar(viewModel: viewModel) | ||
| 129 | } | ||
| 130 | .srhtErrorBanner(error: $vm.error) | ||
| 131 | .sheet(isPresented: $showInfoSheet) { | ||
| 132 | PasteInfoSheet(paste: paste, selectedFile: viewModel.selectedFile) | ||
| 133 | } | ||
| 134 | .sheet(isPresented: $showFileShareSheet) { | ||
| 135 | if let contents = viewModel.selectedFileContents { | ||
| 136 | FileContentShareSheet(activityItems: [contents]) | ||
| 137 | } | 126 | } |
| 138 | } | 127 | .safeAreaInset(edge: .bottom, spacing: 0) { |
| 139 | .alert("Share Unavailable", isPresented: $showShareUnavailableAlert) { | 128 | actionToolbar(viewModel: viewModel) |
| 140 | Button("OK", role: .cancel) { | 129 | } |
| 141 | // Alert dismissal is implicit; no additional action required. | 130 | .srhtErrorBanner(error: $vm.error) |
| 131 | .sheet(isPresented: $showInfoSheet) { | ||
| 132 | PasteInfoSheet(paste: paste, selectedFile: viewModel.selectedFile) | ||
| 133 | } | ||
| 134 | .sheet(isPresented: $showFileShareSheet) { | ||
| 135 | if let contents = viewModel.selectedFileContents { | ||
| 136 | FileContentShareSheet(activityItems: [contents]) | ||
| 137 | } | ||
| 138 | } | ||
| 139 | .alert("Share Unavailable", isPresented: $showShareUnavailableAlert) { | ||
| 140 | Button("OK", role: .cancel) { | ||
| 141 | // Alert dismissal is implicit; no additional action required. | ||
| 142 | } | ||
| 143 | } message: { | ||
| 144 | Text(SRHTShareTarget.file.fallbackMessage) | ||
| 142 | } | 145 | } |
| 143 | } message: { | ||
| 144 | Text(SRHTShareTarget.file.fallbackMessage) | ||
| 145 | } | 146 | } |
| 146 | } | 147 | } |
| 147 | } | 148 | } |
| @@ -240,7 +241,7 @@ struct PasteDetailView: View { | |||
| 240 | 241 | ||
| 241 | private func actionToolbar(viewModel: PasteDetailViewModel) -> some View { | 242 | private func actionToolbar(viewModel: PasteDetailViewModel) -> some View { |
| 242 | HStack(spacing: 0) { | 243 | HStack(spacing: 0) { |
| 243 | toolbarButton( | 244 | BottomToolbarButton( |
| 244 | title: didCopyContents ? "Copied" : "Copy All", | 245 | title: didCopyContents ? "Copied" : "Copy All", |
| 245 | systemImage: didCopyContents ? "checkmark" : "doc.on.doc" | 246 | systemImage: didCopyContents ? "checkmark" : "doc.on.doc" |
| 246 | ) { | 247 | ) { |
| @@ -257,7 +258,7 @@ struct PasteDetailView: View { | |||
| 257 | } | 258 | } |
| 258 | .disabled(viewModel.selectedFileContents == nil) | 259 | .disabled(viewModel.selectedFileContents == nil) |
| 259 | 260 | ||
| 260 | toolbarButton( | 261 | BottomToolbarButton( |
| 261 | title: "Share", | 262 | title: "Share", |
| 262 | systemImage: "square.and.arrow.up" | 263 | systemImage: "square.and.arrow.up" |
| 263 | ) { | 264 | ) { |
| @@ -269,14 +270,14 @@ struct PasteDetailView: View { | |||
| 269 | } | 270 | } |
| 270 | .disabled(viewModel.selectedFileContents == nil) | 271 | .disabled(viewModel.selectedFileContents == nil) |
| 271 | 272 | ||
| 272 | toolbarButton( | 273 | BottomToolbarButton( |
| 273 | title: wrapLines ? "Wrap On" : "Wrap Off", | 274 | title: wrapLines ? "Wrap On" : "Wrap Off", |
| 274 | systemImage: "text.word.spacing" | 275 | systemImage: "text.word.spacing" |
| 275 | ) { | 276 | ) { |
| 276 | wrapLines.toggle() | 277 | wrapLines.toggle() |
| 277 | } | 278 | } |
| 278 | 279 | ||
| 279 | toolbarButton( | 280 | BottomToolbarButton( |
| 280 | title: "Details", | 281 | title: "Details", |
| 281 | systemImage: "info.circle" | 282 | systemImage: "info.circle" |
| 282 | ) { | 283 | ) { |
| @@ -291,26 +292,6 @@ struct PasteDetailView: View { | |||
| 291 | Divider() | 292 | Divider() |
| 292 | } | 293 | } |
| 293 | } | 294 | } |
| 294 | |||
| 295 | private func toolbarButton( | ||
| 296 | title: String, | ||
| 297 | systemImage: String, | ||
| 298 | action: @escaping () -> Void | ||
| 299 | ) -> some View { | ||
| 300 | Button(action: action) { | ||
| 301 | VStack(spacing: 4) { | ||
| 302 | Image(systemName: systemImage) | ||
| 303 | .font(.system(size: 17, weight: .semibold)) | ||
| 304 | Text(title) | ||
| 305 | .font(.caption2) | ||
| 306 | .lineLimit(1) | ||
| 307 | } | ||
| 308 | .frame(maxWidth: .infinity) | ||
| 309 | .contentShape(Rectangle()) | ||
| 310 | } | ||
| 311 | .buttonStyle(.plain) | ||
| 312 | .foregroundStyle(.primary) | ||
| 313 | } | ||
| 314 | } | 295 | } |
| 315 | 296 | ||
| 316 | // MARK: - Paste Info Sheet | 297 | // MARK: - Paste Info Sheet |
Hutch/Views/Pastes/PasteListView.swift +17 −16
| @@ -123,22 +123,23 @@ struct PasteListView: View { | |||
| 123 | prompt: "Search pastes" | 123 | prompt: "Search pastes" |
| 124 | ) | 124 | ) |
| 125 | .overlay { | 125 | .overlay { |
| 126 | if viewModel.isLoading, viewModel.pastes.isEmpty { | 126 | SRHTLoadStateView( |
| 127 | SRHTLoadingStateView(message: "Loading pastes…") | 127 | isLoading: viewModel.isLoading, |
| 128 | } else if let error = viewModel.error, viewModel.pastes.isEmpty { | 128 | error: viewModel.error, |
| 129 | SRHTErrorStateView( | 129 | isEmpty: viewModel.pastes.isEmpty, |
| 130 | title: "Couldn't Load Pastes", | 130 | loadingMessage: "Loading pastes…", |
| 131 | message: error, | 131 | errorTitle: "Couldn't Load Pastes", |
| 132 | retryAction: { await viewModel.loadPastes() } | 132 | retryAction: { await viewModel.loadPastes() } |
| 133 | ) | 133 | ) { |
| 134 | } else if !viewModel.pastes.isEmpty, viewModel.filteredPastes.isEmpty { | 134 | if !viewModel.pastes.isEmpty, viewModel.filteredPastes.isEmpty { |
| 135 | ContentUnavailableView.search(text: viewModel.searchText) | 135 | ContentUnavailableView.search(text: viewModel.searchText) |
| 136 | } else if viewModel.pastes.isEmpty { | 136 | } else if viewModel.pastes.isEmpty { |
| 137 | ContentUnavailableView( | 137 | ContentUnavailableView( |
| 138 | "No Pastes", | 138 | "No Pastes", |
| 139 | systemImage: "doc.on.clipboard", | 139 | systemImage: "doc.on.clipboard", |
| 140 | description: Text("Your pastes will appear here.") | 140 | description: Text("Your pastes will appear here.") |
| 141 | ) | 141 | ) |
| 142 | } | ||
| 142 | } | 143 | } |
| 143 | } | 144 | } |
| 144 | .connectivityOverlay(hasContent: !viewModel.pastes.isEmpty) { | 145 | .connectivityOverlay(hasContent: !viewModel.pastes.isEmpty) { |
Hutch/Views/Projects/DiscoverProjectsView.swift +15 −14
| @@ -113,20 +113,21 @@ struct DiscoverProjectsView: View { | |||
| 113 | .themedList() | 113 | .themedList() |
| 114 | .listStyle(.plain) | 114 | .listStyle(.plain) |
| 115 | .overlay { | 115 | .overlay { |
| 116 | if viewModel.isLoading, viewModel.projects.isEmpty { | 116 | SRHTLoadStateView( |
| 117 | SRHTLoadingStateView(message: "Loading projects…") | 117 | isLoading: viewModel.isLoading, |
| 118 | } else if let error = viewModel.error, viewModel.projects.isEmpty { | 118 | error: viewModel.error, |
| 119 | SRHTErrorStateView( | 119 | isEmpty: viewModel.projects.isEmpty, |
| 120 | title: "Couldn't Load Projects", | 120 | loadingMessage: "Loading projects…", |
| 121 | message: error, | 121 | errorTitle: "Couldn't Load Projects", |
| 122 | retryAction: { await viewModel.reload() } | 122 | retryAction: { await viewModel.reload() } |
| 123 | ) | 123 | ) { |
| 124 | } else if viewModel.projects.isEmpty { | 124 | if viewModel.projects.isEmpty { |
| 125 | ContentUnavailableView( | 125 | ContentUnavailableView( |
| 126 | "No Public Projects", | 126 | "No Public Projects", |
| 127 | systemImage: "sparkle.magnifyingglass", | 127 | systemImage: "sparkle.magnifyingglass", |
| 128 | description: Text("Public projects on SourceHut will appear here.") | 128 | description: Text("Public projects on SourceHut will appear here.") |
| 129 | ) | 129 | ) |
| 130 | } | ||
| 130 | } | 131 | } |
| 131 | } | 132 | } |
| 132 | .srhtErrorBanner( | 133 | .srhtErrorBanner( |
Hutch/Views/Projects/ProjectMailingListView.swift +72 −124
| @@ -304,23 +304,7 @@ final class MailingListDetailViewModel { | |||
| 304 | 304 | ||
| 305 | threads = threads.map { thread in | 305 | threads = threads.map { thread in |
| 306 | guard thread.isUnread else { return thread } | 306 | guard thread.isUnread else { return thread } |
| 307 | return InboxThreadSummary( | 307 | return thread.withUnread(false) |
| 308 | rootEmailID: thread.rootEmailID, | ||
| 309 | rootMessageID: thread.rootMessageID, | ||
| 310 | threadRootEmailIDs: thread.threadRootEmailIDs, | ||
| 311 | threadRootMessageIDs: thread.threadRootMessageIDs, | ||
| 312 | listID: thread.listID, | ||
| 313 | listRID: thread.listRID, | ||
| 314 | listName: thread.listName, | ||
| 315 | listOwner: thread.listOwner, | ||
| 316 | subject: thread.subject, | ||
| 317 | latestSender: thread.latestSender, | ||
| 318 | lastActivityAt: thread.lastActivityAt, | ||
| 319 | messageCount: thread.messageCount, | ||
| 320 | repo: thread.repo, | ||
| 321 | containsPatch: thread.containsPatch, | ||
| 322 | isUnread: false | ||
| 323 | ) | ||
| 324 | } | 308 | } |
| 325 | 309 | ||
| 326 | NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -unreadThreads.count, accountID: accountID) | 310 | NeedsAttentionSnapshotStore.adjustUnreadInboxThreads(by: -unreadThreads.count, accountID: accountID) |
| @@ -363,63 +347,11 @@ final class MailingListDetailViewModel { | |||
| 363 | private func updateThread(_ thread: InboxThreadSummary, isUnread: Bool) { | 347 | private func updateThread(_ thread: InboxThreadSummary, isUnread: Bool) { |
| 364 | guard let index = threads.firstIndex(where: { $0.id == thread.id }) else { return } | 348 | guard let index = threads.firstIndex(where: { $0.id == thread.id }) else { return } |
| 365 | let current = threads[index] | 349 | let current = threads[index] |
| 366 | threads[index] = InboxThreadSummary( | 350 | threads[index] = current.withUnread(isUnread) |
| 367 | rootEmailID: current.rootEmailID, | ||
| 368 | rootMessageID: current.rootMessageID, | ||
| 369 | threadRootEmailIDs: current.threadRootEmailIDs, | ||
| 370 | threadRootMessageIDs: current.threadRootMessageIDs, | ||
| 371 | listID: current.listID, | ||
| 372 | listRID: current.listRID, | ||
| 373 | listName: current.listName, | ||
| 374 | listOwner: current.listOwner, | ||
| 375 | subject: current.subject, | ||
| 376 | latestSender: current.latestSender, | ||
| 377 | lastActivityAt: current.lastActivityAt, | ||
| 378 | messageCount: current.messageCount, | ||
| 379 | repo: current.repo, | ||
| 380 | containsPatch: current.containsPatch, | ||
| 381 | isUnread: isUnread | ||
| 382 | ) | ||
| 383 | } | 351 | } |
| 384 | 352 | ||
| 385 | private func deduplicateThreads(_ threads: [InboxThreadSummary]) -> [InboxThreadSummary] { | 353 | private func deduplicateThreads(_ threads: [InboxThreadSummary]) -> [InboxThreadSummary] { |
| 386 | var grouped: [String: InboxThreadSummary] = [:] | 354 | return InboxThreadSummary.mergedByThread(threads).sorted { lhs, rhs in |
| 387 | |||
| 388 | for thread in threads { | ||
| 389 | guard let existing = grouped[thread.threadGroupingKey] else { | ||
| 390 | grouped[thread.threadGroupingKey] = thread | ||
| 391 | continue | ||
| 392 | } | ||
| 393 | |||
| 394 | let latest = thread.lastActivityAt >= existing.lastActivityAt ? thread : existing | ||
| 395 | let mergedRootEmailIDs = Array(Set(existing.threadRootEmailIDs + thread.threadRootEmailIDs)).sorted() | ||
| 396 | let mergedRootMessageIDs = Array(Set(existing.threadRootMessageIDs + thread.threadRootMessageIDs)).sorted() | ||
| 397 | let mergedMessageCount = max( | ||
| 398 | existing.messageCount ?? existing.threadRootMessageIDs.count, | ||
| 399 | thread.messageCount ?? thread.threadRootMessageIDs.count, | ||
| 400 | mergedRootMessageIDs.count | ||
| 401 | ) | ||
| 402 | |||
| 403 | grouped[thread.threadGroupingKey] = InboxThreadSummary( | ||
| 404 | rootEmailID: latest.rootEmailID, | ||
| 405 | rootMessageID: latest.rootMessageID, | ||
| 406 | threadRootEmailIDs: mergedRootEmailIDs, | ||
| 407 | threadRootMessageIDs: mergedRootMessageIDs, | ||
| 408 | listID: latest.listID, | ||
| 409 | listRID: latest.listRID, | ||
| 410 | listName: latest.listName, | ||
| 411 | listOwner: latest.listOwner, | ||
| 412 | subject: latest.subject, | ||
| 413 | latestSender: latest.latestSender, | ||
| 414 | lastActivityAt: max(existing.lastActivityAt, thread.lastActivityAt), | ||
| 415 | messageCount: mergedMessageCount, | ||
| 416 | repo: latest.repo ?? existing.repo, | ||
| 417 | containsPatch: latest.containsPatch || existing.containsPatch, | ||
| 418 | isUnread: latest.isUnread || existing.isUnread | ||
| 419 | ) | ||
| 420 | } | ||
| 421 | |||
| 422 | return grouped.values.sorted { lhs, rhs in | ||
| 423 | if lhs.lastActivityAt == rhs.lastActivityAt { | 355 | if lhs.lastActivityAt == rhs.lastActivityAt { |
| 424 | return lhs.displaySubject.localizedCaseInsensitiveCompare(rhs.displaySubject) == .orderedAscending | 356 | return lhs.displaySubject.localizedCaseInsensitiveCompare(rhs.displaySubject) == .orderedAscending |
| 425 | } | 357 | } |
| @@ -578,48 +510,11 @@ struct MailingListDetailView: View { | |||
| 578 | ForEach(viewModel.filteredPatchsets) { patchset in | 510 | ForEach(viewModel.filteredPatchsets) { patchset in |
| 579 | // Pushed directly rather than by value: this view is also shown | 511 | // Pushed directly rather than by value: this view is also shown |
| 580 | // from a project, whose stack declares no MoreRoute destination. | 512 | // from a project, whose stack declares no MoreRoute destination. |
| 581 | NavigationLink { | 513 | patchsetRow(patchset, viewModel) |
| 582 | PatchsetDetailView(patchsetID: patchset.id, listName: mailingList.name) | ||
| 583 | } label: { | ||
| 584 | PatchsetRow(patchset: patchset) | ||
| 585 | } | ||
| 586 | .themedRow() | ||
| 587 | } | 514 | } |
| 588 | } else { | 515 | } else { |
| 589 | ForEach(viewModel.filteredThreads) { thread in | 516 | ForEach(viewModel.filteredThreads) { thread in |
| 590 | NavigationLink { | 517 | threadRow(thread, viewModel) |
| 591 | ThreadDetailView( | ||
| 592 | thread: thread, | ||
| 593 | onViewed: { | ||
| 594 | viewModel.markThreadRead(thread) | ||
| 595 | }, | ||
| 596 | onMarkRead: { | ||
| 597 | viewModel.markThreadRead(thread) | ||
| 598 | }, | ||
| 599 | onMarkUnread: { | ||
| 600 | viewModel.markThreadUnread(thread) | ||
| 601 | } | ||
| 602 | ) | ||
| 603 | } label: { | ||
| 604 | InboxThreadRow(thread: thread) | ||
| 605 | } | ||
| 606 | .swipeActions(edge: .trailing, allowsFullSwipe: true) { | ||
| 607 | Button { | ||
| 608 | withAnimation(.easeInOut(duration: 0.2)) { | ||
| 609 | if thread.isUnread { | ||
| 610 | viewModel.markThreadRead(thread) | ||
| 611 | } else { | ||
| 612 | viewModel.markThreadUnread(thread) | ||
| 613 | } | ||
| 614 | } | ||
| 615 | } label: { | ||
| 616 | Label( | ||
| 617 | thread.isUnread ? "Mark as Read" : "Mark as Unread", | ||
| 618 | systemImage: thread.isUnread ? "envelope.open" : "envelope.badge" | ||
| 619 | ) | ||
| 620 | } | ||
| 621 | .tint(thread.isUnread ? .blue : .gray) | ||
| 622 | } | ||
| 623 | } | 518 | } |
| 624 | .themedRow() | 519 | .themedRow() |
| 625 | } | 520 | } |
| @@ -632,15 +527,29 @@ struct MailingListDetailView: View { | |||
| 632 | prompt: showingPatches(viewModel) ? "Search patches" : "Search messages" | 527 | prompt: showingPatches(viewModel) ? "Search patches" : "Search messages" |
| 633 | ) | 528 | ) |
| 634 | .overlay { | 529 | .overlay { |
| 635 | if viewModel.isLoading, viewModel.threads.isEmpty { | 530 | emptyState(viewModel) |
| 636 | SRHTLoadingStateView(message: "Loading mailing list…") | 531 | } |
| 637 | } else if let error = viewModel.error, viewModel.threads.isEmpty { | 532 | .refreshable { |
| 638 | SRHTErrorStateView( | 533 | await viewModel.loadThreads() |
| 639 | title: "Couldn't Load Mailing List", | 534 | } |
| 640 | message: error, | 535 | .srhtErrorBanner(error: $vm.error) |
| 641 | retryAction: { await viewModel.loadThreads() } | 536 | } |
| 642 | ) | 537 | |
| 643 | } else if showingPatches(viewModel) { | 538 | private func showingPatches(_ viewModel: MailingListDetailViewModel) -> Bool { |
| 539 | scope == .patches && !viewModel.patchsets.isEmpty | ||
| 540 | } | ||
| 541 | |||
| 542 | @ViewBuilder | ||
| 543 | private func emptyState(_ viewModel: MailingListDetailViewModel) -> some View { | ||
| 544 | SRHTLoadStateView( | ||
| 545 | isLoading: viewModel.isLoading, | ||
| 546 | error: viewModel.error, | ||
| 547 | isEmpty: viewModel.threads.isEmpty, | ||
| 548 | loadingMessage: "Loading mailing list…", | ||
| 549 | errorTitle: "Couldn't Load Mailing List", | ||
| 550 | retryAction: { await viewModel.loadThreads() } | ||
| 551 | ) { | ||
| 552 | if showingPatches(viewModel) { | ||
| 644 | if !viewModel.patchsets.isEmpty, viewModel.filteredPatchsets.isEmpty { | 553 | if !viewModel.patchsets.isEmpty, viewModel.filteredPatchsets.isEmpty { |
| 645 | ContentUnavailableView.search(text: viewModel.searchText) | 554 | ContentUnavailableView.search(text: viewModel.searchText) |
| 646 | } | 555 | } |
| @@ -654,14 +563,53 @@ struct MailingListDetailView: View { | |||
| 654 | ) | 563 | ) |
| 655 | } | 564 | } |
| 656 | } | 565 | } |
| 657 | .refreshable { | 566 | } |
| 658 | await viewModel.loadThreads() | 567 | |
| 568 | @ViewBuilder | ||
| 569 | private func threadRow(_ thread: InboxThreadSummary, _ viewModel: MailingListDetailViewModel) -> some View { | ||
| 570 | NavigationLink { | ||
| 571 | ThreadDetailView( | ||
| 572 | thread: thread, | ||
| 573 | onViewed: { | ||
| 574 | viewModel.markThreadRead(thread) | ||
| 575 | }, | ||
| 576 | onMarkRead: { | ||
| 577 | viewModel.markThreadRead(thread) | ||
| 578 | }, | ||
| 579 | onMarkUnread: { | ||
| 580 | viewModel.markThreadUnread(thread) | ||
| 581 | } | ||
| 582 | ) | ||
| 583 | } label: { | ||
| 584 | InboxThreadRow(thread: thread) | ||
| 585 | } | ||
| 586 | .swipeActions(edge: .trailing, allowsFullSwipe: true) { | ||
| 587 | Button { | ||
| 588 | withAnimation(.easeInOut(duration: 0.2)) { | ||
| 589 | if thread.isUnread { | ||
| 590 | viewModel.markThreadRead(thread) | ||
| 591 | } else { | ||
| 592 | viewModel.markThreadUnread(thread) | ||
| 593 | } | ||
| 594 | } | ||
| 595 | } label: { | ||
| 596 | Label( | ||
| 597 | thread.isUnread ? "Mark as Read" : "Mark as Unread", | ||
| 598 | systemImage: thread.isUnread ? "envelope.open" : "envelope.badge" | ||
| 599 | ) | ||
| 600 | } | ||
| 601 | .tint(thread.isUnread ? .blue : .gray) | ||
| 659 | } | 602 | } |
| 660 | .srhtErrorBanner(error: $vm.error) | ||
| 661 | } | 603 | } |
| 662 | 604 | ||
| 663 | private func showingPatches(_ viewModel: MailingListDetailViewModel) -> Bool { | 605 | @ViewBuilder |
| 664 | scope == .patches && !viewModel.patchsets.isEmpty | 606 | private func patchsetRow(_ patchset: PatchsetSummary, _ viewModel: MailingListDetailViewModel) -> some View { |
| 607 | NavigationLink { | ||
| 608 | PatchsetDetailView(patchsetID: patchset.id, listName: mailingList.name) | ||
| 609 | } label: { | ||
| 610 | PatchsetRow(patchset: patchset) | ||
| 611 | } | ||
| 612 | .themedRow() | ||
| 665 | } | 613 | } |
| 666 | } | 614 | } |
| 667 | 615 | ||
Hutch/Views/Projects/ProjectsListView.swift +17 −16
| @@ -144,22 +144,23 @@ struct ProjectsListView: View { | |||
| 144 | prompt: "Search projects" | 144 | prompt: "Search projects" |
| 145 | ) | 145 | ) |
| 146 | .overlay { | 146 | .overlay { |
| 147 | if viewModel.isLoading, viewModel.projects.isEmpty { | 147 | SRHTLoadStateView( |
| 148 | SRHTLoadingStateView(message: "Loading projects…") | 148 | isLoading: viewModel.isLoading, |
| 149 | } else if let error = viewModel.error, viewModel.projects.isEmpty { | 149 | error: viewModel.error, |
| 150 | SRHTErrorStateView( | 150 | isEmpty: viewModel.projects.isEmpty, |
| 151 | title: "Couldn't Load Projects", | 151 | loadingMessage: "Loading projects…", |
| 152 | message: error, | 152 | errorTitle: "Couldn't Load Projects", |
| 153 | retryAction: { await viewModel.loadProjects() } | 153 | retryAction: { await viewModel.loadProjects() } |
| 154 | ) | 154 | ) { |
| 155 | } else if !viewModel.projects.isEmpty, viewModel.filteredProjects.isEmpty { | 155 | if !viewModel.projects.isEmpty, viewModel.filteredProjects.isEmpty { |
| 156 | ContentUnavailableView.search(text: viewModel.searchText) | 156 | ContentUnavailableView.search(text: viewModel.searchText) |
| 157 | } else if viewModel.projects.isEmpty { | 157 | } else if viewModel.projects.isEmpty { |
| 158 | ContentUnavailableView( | 158 | ContentUnavailableView( |
| 159 | "No Projects", | 159 | "No Projects", |
| 160 | systemImage: "square.stack.3d.up", | 160 | systemImage: "square.stack.3d.up", |
| 161 | description: Text("Projects from your SourceHut account will appear here when available.") | 161 | description: Text("Projects from your SourceHut account will appear here when available.") |
| 162 | ) | 162 | ) |
| 163 | } | ||
| 163 | } | 164 | } |
| 164 | } | 165 | } |
| 165 | .srhtErrorBanner( | 166 | .srhtErrorBanner( |
Hutch/Views/Repositories/CommitDetailView.swift +51 −46
| @@ -85,52 +85,7 @@ struct CommitDetailView: View { | |||
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | } else if let commit = viewModel.commit { | 87 | } else if let commit = viewModel.commit { |
| 88 | ScrollView { | 88 | commitBody(commit) |
| 89 | LazyVStack(alignment: .leading, spacing: 0) { | ||
| 90 | // Header | ||
| 91 | commitHeader(commit) | ||
| 92 | |||
| 93 | sectionDivider | ||
| 94 | |||
| 95 | // Message | ||
| 96 | commitMessage(commit) | ||
| 97 | |||
| 98 | // Trailers | ||
| 99 | if !commit.trailers.isEmpty { | ||
| 100 | sectionDivider | ||
| 101 | trailersSection(commit.trailers) | ||
| 102 | } | ||
| 103 | |||
| 104 | // Parents | ||
| 105 | if !commit.parents.isEmpty { | ||
| 106 | sectionDivider | ||
| 107 | parentsSection(commit.parents) | ||
| 108 | } | ||
| 109 | |||
| 110 | // Diff | ||
| 111 | if let diff = commit.diff, !diff.isEmpty { | ||
| 112 | sectionDivider | ||
| 113 | diffSection(diff) | ||
| 114 | } | ||
| 115 | |||
| 116 | // Tree | ||
| 117 | if let tree = commit.tree, !tree.entries.results.isEmpty { | ||
| 118 | sectionDivider | ||
| 119 | treeSection(tree.entries.results) | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | .navigationDestination(for: ParentCommit.self) { parent in | ||
| 124 | CommitDetailView( | ||
| 125 | commitSummary: CommitSummary( | ||
| 126 | id: parent.id, | ||
| 127 | shortId: parent.shortId, | ||
| 128 | author: CommitAuthor(name: parent.author.name, email: nil, time: .now), | ||
| 129 | message: "" | ||
| 130 | ), | ||
| 131 | repository: repository | ||
| 132 | ) | ||
| 133 | } | ||
| 134 | } | 89 | } |
| 135 | } | 90 | } |
| 136 | 91 | ||
| @@ -362,4 +317,54 @@ struct CommitDetailView: View { | |||
| 362 | default: return .secondary | 317 | default: return .secondary |
| 363 | } | 318 | } |
| 364 | } | 319 | } |
| 320 | |||
| 321 | @ViewBuilder | ||
| 322 | private func commitBody(_ commit: CommitDetail) -> some View { | ||
| 323 | ScrollView { | ||
| 324 | LazyVStack(alignment: .leading, spacing: 0) { | ||
| 325 | // Header | ||
| 326 | commitHeader(commit) | ||
| 327 | |||
| 328 | sectionDivider | ||
| 329 | |||
| 330 | // Message | ||
| 331 | commitMessage(commit) | ||
| 332 | |||
| 333 | // Trailers | ||
| 334 | if !commit.trailers.isEmpty { | ||
| 335 | sectionDivider | ||
| 336 | trailersSection(commit.trailers) | ||
| 337 | } | ||
| 338 | |||
| 339 | // Parents | ||
| 340 | if !commit.parents.isEmpty { | ||
| 341 | sectionDivider | ||
| 342 | parentsSection(commit.parents) | ||
| 343 | } | ||
| 344 | |||
| 345 | // Diff | ||
| 346 | if let diff = commit.diff, !diff.isEmpty { | ||
| 347 | sectionDivider | ||
| 348 | diffSection(diff) | ||
| 349 | } | ||
| 350 | |||
| 351 | // Tree | ||
| 352 | if let tree = commit.tree, !tree.entries.results.isEmpty { | ||
| 353 | sectionDivider | ||
| 354 | treeSection(tree.entries.results) | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } | ||
| 358 | .navigationDestination(for: ParentCommit.self) { parent in | ||
| 359 | CommitDetailView( | ||
| 360 | commitSummary: CommitSummary( | ||
| 361 | id: parent.id, | ||
| 362 | shortId: parent.shortId, | ||
| 363 | author: CommitAuthor(name: parent.author.name, email: nil, time: .now), | ||
| 364 | message: "" | ||
| 365 | ), | ||
| 366 | repository: repository | ||
| 367 | ) | ||
| 368 | } | ||
| 369 | } | ||
| 365 | } | 370 | } |
Hutch/Views/Repositories/FileTreeView.swift +3 −23
| @@ -321,21 +321,21 @@ private struct FileTreeContentView: View { | |||
| 321 | 321 | ||
| 322 | private func fileActionToolbar(text: String) -> some View { | 322 | private func fileActionToolbar(text: String) -> some View { |
| 323 | HStack(spacing: 0) { | 323 | HStack(spacing: 0) { |
| 324 | toolbarButton( | 324 | BottomToolbarButton( |
| 325 | title: "Share", | 325 | title: "Share", |
| 326 | systemImage: "square.and.arrow.up" | 326 | systemImage: "square.and.arrow.up" |
| 327 | ) { | 327 | ) { |
| 328 | shareFileContents(text) | 328 | shareFileContents(text) |
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | toolbarButton( | 331 | BottomToolbarButton( |
| 332 | title: didCopyFileContents ? "Copied" : "Copy All", | 332 | title: didCopyFileContents ? "Copied" : "Copy All", |
| 333 | systemImage: didCopyFileContents ? "checkmark" : "doc.on.doc" | 333 | systemImage: didCopyFileContents ? "checkmark" : "doc.on.doc" |
| 334 | ) { | 334 | ) { |
| 335 | copyFileContents(text) | 335 | copyFileContents(text) |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | toolbarButton( | 338 | BottomToolbarButton( |
| 339 | title: wrapRepositoryFileLines ? "Wrap On" : "Wrap Off", | 339 | title: wrapRepositoryFileLines ? "Wrap On" : "Wrap Off", |
| 340 | systemImage: "text.word.spacing" | 340 | systemImage: "text.word.spacing" |
| 341 | ) { | 341 | ) { |
| @@ -350,26 +350,6 @@ private struct FileTreeContentView: View { | |||
| 350 | Divider() | 350 | Divider() |
| 351 | } | 351 | } |
| 352 | } | 352 | } |
| 353 | |||
| 354 | private func toolbarButton( | ||
| 355 | title: String, | ||
| 356 | systemImage: String, | ||
| 357 | action: @escaping () -> Void | ||
| 358 | ) -> some View { | ||
| 359 | Button(action: action) { | ||
| 360 | VStack(spacing: 4) { | ||
| 361 | Image(systemName: systemImage) | ||
| 362 | .font(.system(size: 17, weight: .semibold)) | ||
| 363 | Text(title) | ||
| 364 | .font(.caption2) | ||
| 365 | .lineLimit(1) | ||
| 366 | } | ||
| 367 | .frame(maxWidth: .infinity) | ||
| 368 | .contentShape(Rectangle()) | ||
| 369 | } | ||
| 370 | .buttonStyle(.plain) | ||
| 371 | .foregroundStyle(.primary) | ||
| 372 | } | ||
| 373 | } | 353 | } |
| 374 | 354 | ||
| 375 | struct CodeFileTextView: UIViewRepresentable { | 355 | struct CodeFileTextView: UIViewRepresentable { |
Hutch/Views/Repositories/HgRepositoryDetailView.swift +4 −24
| @@ -622,7 +622,7 @@ struct HgRepositoryDetailView: View { | |||
| 622 | 622 | ||
| 623 | private func fileActionToolbar(fileContent: String, viewModel: HgRepositoryDetailViewModel) -> some View { | 623 | private func fileActionToolbar(fileContent: String, viewModel: HgRepositoryDetailViewModel) -> some View { |
| 624 | HStack(spacing: 0) { | 624 | HStack(spacing: 0) { |
| 625 | toolbarButton( | 625 | BottomToolbarButton( |
| 626 | title: "Share", | 626 | title: "Share", |
| 627 | systemImage: "square.and.arrow.up" | 627 | systemImage: "square.and.arrow.up" |
| 628 | ) { | 628 | ) { |
| @@ -633,21 +633,21 @@ struct HgRepositoryDetailView: View { | |||
| 633 | } | 633 | } |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | toolbarButton( | 636 | BottomToolbarButton( |
| 637 | title: didCopyFileContents ? "Copied" : "Copy All", | 637 | title: didCopyFileContents ? "Copied" : "Copy All", |
| 638 | systemImage: didCopyFileContents ? "checkmark" : "doc.on.doc" | 638 | systemImage: didCopyFileContents ? "checkmark" : "doc.on.doc" |
| 639 | ) { | 639 | ) { |
| 640 | copyFileContents(fileContent) | 640 | copyFileContents(fileContent) |
| 641 | } | 641 | } |
| 642 | 642 | ||
| 643 | toolbarButton( | 643 | BottomToolbarButton( |
| 644 | title: wrapRepositoryFileLines ? "Wrap On" : "Wrap Off", | 644 | title: wrapRepositoryFileLines ? "Wrap On" : "Wrap Off", |
| 645 | systemImage: "text.word.spacing" | 645 | systemImage: "text.word.spacing" |
| 646 | ) { | 646 | ) { |
| 647 | wrapRepositoryFileLines.toggle() | 647 | wrapRepositoryFileLines.toggle() |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | toolbarButton( | 650 | BottomToolbarButton( |
| 651 | title: "Back", | 651 | title: "Back", |
| 652 | systemImage: "chevron.left" | 652 | systemImage: "chevron.left" |
| 653 | ) { | 653 | ) { |
| @@ -662,26 +662,6 @@ struct HgRepositoryDetailView: View { | |||
| 662 | Divider() | 662 | Divider() |
| 663 | } | 663 | } |
| 664 | } | 664 | } |
| 665 | |||
| 666 | private func toolbarButton( | ||
| 667 | title: String, | ||
| 668 | systemImage: String, | ||
| 669 | action: @escaping () -> Void | ||
| 670 | ) -> some View { | ||
| 671 | Button(action: action) { | ||
| 672 | VStack(spacing: 4) { | ||
| 673 | Image(systemName: systemImage) | ||
| 674 | .font(.system(size: 17, weight: .semibold)) | ||
| 675 | Text(title) | ||
| 676 | .font(.caption2) | ||
| 677 | .lineLimit(1) | ||
| 678 | } | ||
| 679 | .frame(maxWidth: .infinity) | ||
| 680 | .contentShape(Rectangle()) | ||
| 681 | } | ||
| 682 | .buttonStyle(.plain) | ||
| 683 | .foregroundStyle(.primary) | ||
| 684 | } | ||
| 685 | } | 665 | } |
| 686 | 666 | ||
| 687 | private struct HgBrowseRefPickerSheet: View { | 667 | private struct HgBrowseRefPickerSheet: View { |
Hutch/Views/Repositories/HgRepositorySettingsView.swift +21 −46
| @@ -11,22 +11,7 @@ struct HgRepositorySettingsView: View { | |||
| 11 | @State private var pendingACLDeletion: HgACLEntry? | 11 | @State private var pendingACLDeletion: HgACLEntry? |
| 12 | 12 | ||
| 13 | var body: some View { | 13 | var body: some View { |
| 14 | NavigationStack { | 14 | SettingsSheet(model: viewModel) { settingsForm($0) } |
| 15 | Group { | ||
| 16 | if let viewModel { | ||
| 17 | settingsForm(viewModel) | ||
| 18 | } else { | ||
| 19 | SRHTLoadingStateView(message: "Loading settings…") | ||
| 20 | } | ||
| 21 | } | ||
| 22 | .navigationTitle("Settings") | ||
| 23 | .navigationBarTitleDisplayMode(.inline) | ||
| 24 | .toolbar { | ||
| 25 | ToolbarItem(placement: .cancellationAction) { | ||
| 26 | Button("Done") { dismiss() } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | .task { | 15 | .task { |
| 31 | if viewModel == nil { | 16 | if viewModel == nil { |
| 32 | let vm = HgRepositorySettingsViewModel(repository: repository, client: client) | 17 | let vm = HgRepositorySettingsViewModel(repository: repository, client: client) |
| @@ -38,6 +23,24 @@ struct HgRepositorySettingsView: View { | |||
| 38 | } | 23 | } |
| 39 | } | 24 | } |
| 40 | 25 | ||
| 26 | private func saveInfoButton(_ viewModel: HgRepositorySettingsViewModel) -> some View { | ||
| 27 | Button { | ||
| 28 | Task { | ||
| 29 | _ = await viewModel.saveInfo() | ||
| 30 | } | ||
| 31 | } label: { | ||
| 32 | if viewModel.isSavingInfo { | ||
| 33 | ProgressView() | ||
| 34 | .frame(maxWidth: .infinity) | ||
| 35 | } else { | ||
| 36 | Text("Save Changes") | ||
| 37 | .frame(maxWidth: .infinity) | ||
| 38 | } | ||
| 39 | } | ||
| 40 | .disabled(viewModel.isSavingInfo || !viewModel.isInfoDirty) | ||
| 41 | .themedRow() | ||
| 42 | } | ||
| 43 | |||
| 41 | @ViewBuilder | 44 | @ViewBuilder |
| 42 | private func settingsForm(_ viewModel: HgRepositorySettingsViewModel) -> some View { | 45 | private func settingsForm(_ viewModel: HgRepositorySettingsViewModel) -> some View { |
| 43 | @Bindable var vm = viewModel | 46 | @Bindable var vm = viewModel |
| @@ -127,21 +130,7 @@ struct HgRepositorySettingsView: View { | |||
| 127 | } | 130 | } |
| 128 | .themedRow() | 131 | .themedRow() |
| 129 | 132 | ||
| 130 | Button { | 133 | saveInfoButton(viewModel) |
| 131 | Task { | ||
| 132 | _ = await viewModel.saveInfo() | ||
| 133 | } | ||
| 134 | } label: { | ||
| 135 | if viewModel.isSavingInfo { | ||
| 136 | ProgressView() | ||
| 137 | .frame(maxWidth: .infinity) | ||
| 138 | } else { | ||
| 139 | Text("Save Changes") | ||
| 140 | .frame(maxWidth: .infinity) | ||
| 141 | } | ||
| 142 | } | ||
| 143 | .disabled(viewModel.isSavingInfo || !viewModel.isInfoDirty) | ||
| 144 | .themedRow() | ||
| 145 | } | 134 | } |
| 146 | } | 135 | } |
| 147 | 136 | ||
| @@ -220,21 +209,7 @@ struct HgRepositorySettingsView: View { | |||
| 220 | .foregroundStyle(.secondary) | 209 | .foregroundStyle(.secondary) |
| 221 | .themedRow() | 210 | .themedRow() |
| 222 | 211 | ||
| 223 | Button { | 212 | saveInfoButton(viewModel) |
| 224 | Task { | ||
| 225 | _ = await viewModel.saveInfo() | ||
| 226 | } | ||
| 227 | } label: { | ||
| 228 | if viewModel.isSavingInfo { | ||
| 229 | ProgressView() | ||
| 230 | .frame(maxWidth: .infinity) | ||
| 231 | } else { | ||
| 232 | Text("Save Changes") | ||
| 233 | .frame(maxWidth: .infinity) | ||
| 234 | } | ||
| 235 | } | ||
| 236 | .disabled(viewModel.isSavingInfo || !viewModel.isInfoDirty) | ||
| 237 | .themedRow() | ||
| 238 | } | 213 | } |
| 239 | } | 214 | } |
| 240 | 215 | ||
Hutch/Views/Repositories/RepositoryListView.swift +22 −21
| @@ -127,27 +127,28 @@ struct RepositoryListView: View { | |||
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | .overlay { | 129 | .overlay { |
| 130 | if viewModel.isLoading, viewModel.repositories.isEmpty { | 130 | SRHTLoadStateView( |
| 131 | SRHTLoadingStateView(message: "Loading repositories…") | 131 | isLoading: viewModel.isLoading, |
| 132 | } else if let error = viewModel.error, viewModel.repositories.isEmpty { | 132 | error: viewModel.error, |
| 133 | SRHTErrorStateView( | 133 | isEmpty: viewModel.repositories.isEmpty, |
| 134 | title: "Couldn't Load Repositories", | 134 | loadingMessage: "Loading repositories…", |
| 135 | message: error, | 135 | errorTitle: "Couldn't Load Repositories", |
| 136 | retryAction: { await viewModel.loadRepositories() } | 136 | retryAction: { await viewModel.loadRepositories() } |
| 137 | ) | 137 | ) { |
| 138 | } else if viewModel.repositories.isEmpty, viewModel.error == nil { | 138 | if viewModel.repositories.isEmpty, viewModel.error == nil { |
| 139 | if viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | 139 | if viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { |
| 140 | ContentUnavailableView( | 140 | ContentUnavailableView( |
| 141 | "No Repositories", | 141 | "No Repositories", |
| 142 | systemImage: "book.closed", | 142 | systemImage: "book.closed", |
| 143 | description: Text("You don't have any repositories yet.") | 143 | description: Text("You don't have any repositories yet.") |
| 144 | ) | 144 | ) |
| 145 | } else { | 145 | } else { |
| 146 | ContentUnavailableView( | 146 | ContentUnavailableView( |
| 147 | "No Repository Matches", | 147 | "No Repository Matches", |
| 148 | systemImage: "magnifyingglass", | 148 | systemImage: "magnifyingglass", |
| 149 | description: Text("No repositories matched “\(viewModel.searchText)”.") | 149 | description: Text("No repositories matched “\(viewModel.searchText)”.") |
| 150 | ) | 150 | ) |
| 151 | } | ||
| 151 | } | 152 | } |
| 152 | } | 153 | } |
| 153 | } | 154 | } |
Hutch/Views/Repositories/RepositoryListViewModel.swift +16 −69
| @@ -384,39 +384,6 @@ final class RepositoryListViewModel { | |||
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | private static let emptyPage = Page(results: [], cursor: nil) | 386 | private static let emptyPage = Page(results: [], cursor: nil) |
| 387 | |||
| 388 | private struct RepositoryPayload: Decodable, Sendable { | ||
| 389 | let id: Int | ||
| 390 | let rid: String | ||
| 391 | let name: String | ||
| 392 | let description: String? | ||
| 393 | let visibility: Visibility | ||
| 394 | let updated: Date | ||
| 395 | let owner: Entity | ||
| 396 | let head: Reference? | ||
| 397 | |||
| 398 | enum CodingKeys: String, CodingKey { | ||
| 399 | case id, rid, name, description, visibility, updated, owner | ||
| 400 | case head = "HEAD" | ||
| 401 | } | ||
| 402 | |||
| 403 | func repositorySummary(service: SRHTService) -> RepositorySummary { | ||
| 404 | RepositorySummary( | ||
| 405 | fields: .init( | ||
| 406 | id: id, | ||
| 407 | rid: rid, | ||
| 408 | service: service, | ||
| 409 | name: name, | ||
| 410 | description: description, | ||
| 411 | visibility: visibility, | ||
| 412 | updated: updated, | ||
| 413 | owner: owner, | ||
| 414 | head: head | ||
| 415 | ) | ||
| 416 | ) | ||
| 417 | } | ||
| 418 | } | ||
| 419 | |||
| 420 | private struct HGRepositoryPayload: Decodable, Sendable { | 387 | private struct HGRepositoryPayload: Decodable, Sendable { |
| 421 | let id: Int | 388 | let id: Int |
| 422 | let rid: String | 389 | let rid: String |
| @@ -428,18 +395,20 @@ final class RepositoryListViewModel { | |||
| 428 | let tip: HGTipReference? | 395 | let tip: HGTipReference? |
| 429 | 396 | ||
| 430 | func repositorySummary(service: SRHTService) -> RepositorySummary { | 397 | func repositorySummary(service: SRHTService) -> RepositorySummary { |
| 431 | RepositorySummary( | 398 | repositoryPayload.repositorySummary(service: service) |
| 432 | fields: .init( | 399 | } |
| 433 | id: id, | 400 | |
| 434 | rid: rid, | 401 | /// The shape the git API returns, with the tip's branch as HEAD. |
| 435 | service: service, | 402 | var repositoryPayload: RepositoryPayload { |
| 436 | name: name, | 403 | RepositoryPayload( |
| 437 | description: description, | 404 | id: id, |
| 438 | visibility: visibility, | 405 | rid: rid, |
| 439 | updated: updated, | 406 | name: name, |
| 440 | owner: owner, | 407 | description: description, |
| 441 | head: tip.map { Reference(name: $0.branch, target: nil) } | 408 | visibility: visibility, |
| 442 | ) | 409 | updated: updated, |
| 410 | owner: owner, | ||
| 411 | head: tip.map { Reference(name: $0.branch, target: nil) } | ||
| 443 | ) | 412 | ) |
| 444 | } | 413 | } |
| 445 | } | 414 | } |
| @@ -486,18 +455,7 @@ final class RepositoryListViewModel { | |||
| 486 | ) | 455 | ) |
| 487 | let result = cached.value | 456 | let result = cached.value |
| 488 | return Page( | 457 | return Page( |
| 489 | results: result.repositories?.results.map { | 458 | results: result.repositories?.results.map(\.repositoryPayload) ?? [], |
| 490 | RepositoryPayload( | ||
| 491 | id: $0.id, | ||
| 492 | rid: $0.rid, | ||
| 493 | name: $0.name, | ||
| 494 | description: $0.description, | ||
| 495 | visibility: $0.visibility, | ||
| 496 | updated: $0.updated, | ||
| 497 | owner: $0.owner, | ||
| 498 | head: $0.tip.map { Reference(name: $0.branch, target: nil) } | ||
| 499 | ) | ||
| 500 | } ?? [], | ||
| 501 | cursor: result.repositories?.cursor | 459 | cursor: result.repositories?.cursor |
| 502 | ) | 460 | ) |
| 503 | } | 461 | } |
| @@ -522,18 +480,7 @@ final class RepositoryListViewModel { | |||
| 522 | responseType: HGRepositoriesResponse.self | 480 | responseType: HGRepositoriesResponse.self |
| 523 | ) | 481 | ) |
| 524 | return Page( | 482 | return Page( |
| 525 | results: result.repositories?.results.map { | 483 | results: result.repositories?.results.map(\.repositoryPayload) ?? [], |
| 526 | RepositoryPayload( | ||
| 527 | id: $0.id, | ||
| 528 | rid: $0.rid, | ||
| 529 | name: $0.name, | ||
| 530 | description: $0.description, | ||
| 531 | visibility: $0.visibility, | ||
| 532 | updated: $0.updated, | ||
| 533 | owner: $0.owner, | ||
| 534 | head: $0.tip.map { Reference(name: $0.branch, target: nil) } | ||
| 535 | ) | ||
| 536 | } ?? [], | ||
| 537 | cursor: result.repositories?.cursor | 484 | cursor: result.repositories?.cursor |
| 538 | ) | 485 | ) |
| 539 | } | 486 | } |
Hutch/Views/Repositories/RepositorySettingsView.swift +1 −16
| @@ -13,22 +13,7 @@ struct RepositorySettingsView: View { | |||
| 13 | @State private var showDeleteConfirmation = false | 13 | @State private var showDeleteConfirmation = false |
| 14 | 14 | ||
| 15 | var body: some View { | 15 | var body: some View { |
| 16 | NavigationStack { | 16 | SettingsSheet(model: viewModel) { settingsForm($0) } |
| 17 | Group { | ||
| 18 | if let viewModel { | ||
| 19 | settingsForm(viewModel) | ||
| 20 | } else { | ||
| 21 | SRHTLoadingStateView(message: "Loading settings…") | ||
| 22 | } | ||
| 23 | } | ||
| 24 | .navigationTitle("Settings") | ||
| 25 | .navigationBarTitleDisplayMode(.inline) | ||
| 26 | .toolbar { | ||
| 27 | ToolbarItem(placement: .cancellationAction) { | ||
| 28 | Button("Done") { dismiss() } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | .task { | 17 | .task { |
| 33 | if viewModel == nil { | 18 | if viewModel == nil { |
| 34 | viewModel = RepositorySettingsViewModel( | 19 | viewModel = RepositorySettingsViewModel( |
Hutch/Views/Settings/SettingsViewModel.swift +22 −34
| @@ -19,6 +19,26 @@ private struct UpdatedUser: Decodable, Sendable { | |||
| 19 | let avatar: String? | 19 | let avatar: String? |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | private extension UserProfile { | ||
| 23 | /// This profile with the fields an update returns; the avatar is kept when the update has none. | ||
| 24 | func applying(_ updated: UpdatedUser) -> UserProfile { | ||
| 25 | UserProfile( | ||
| 26 | username: username, | ||
| 27 | canonicalName: canonicalName, | ||
| 28 | email: updated.email, | ||
| 29 | url: updated.url, | ||
| 30 | location: updated.location, | ||
| 31 | bio: updated.bio, | ||
| 32 | avatar: updated.avatar ?? avatar, | ||
| 33 | userType: userType, | ||
| 34 | sshKeys: sshKeys, | ||
| 35 | pgpKeys: pgpKeys, | ||
| 36 | paymentStatus: paymentStatus, | ||
| 37 | subscription: subscription | ||
| 38 | ) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 22 | private struct CreateSSHKeyResponse: Decodable, Sendable { | 42 | private struct CreateSSHKeyResponse: Decodable, Sendable { |
| 23 | let createSSHKey: SSHKey | 43 | let createSSHKey: SSHKey |
| 24 | } | 44 | } |
| @@ -208,23 +228,7 @@ final class SettingsViewModel { | |||
| 208 | variables: ["input": input], | 228 | variables: ["input": input], |
| 209 | responseType: UpdateUserResponse.self | 229 | responseType: UpdateUserResponse.self |
| 210 | ) | 230 | ) |
| 211 | let updated = result.updateUser | 231 | profile = profile?.applying(result.updateUser) |
| 212 | if let p = profile { | ||
| 213 | profile = UserProfile( | ||
| 214 | username: p.username, | ||
| 215 | canonicalName: p.canonicalName, | ||
| 216 | email: updated.email, | ||
| 217 | url: updated.url, | ||
| 218 | location: updated.location, | ||
| 219 | bio: updated.bio, | ||
| 220 | avatar: updated.avatar ?? p.avatar, | ||
| 221 | userType: p.userType, | ||
| 222 | sshKeys: p.sshKeys, | ||
| 223 | pgpKeys: p.pgpKeys, | ||
| 224 | paymentStatus: p.paymentStatus, | ||
| 225 | subscription: p.subscription | ||
| 226 | ) | ||
| 227 | } | ||
| 228 | isEditingProfile = false | 232 | isEditingProfile = false |
| 229 | } catch { | 233 | } catch { |
| 230 | self.error = error.userFacingMessage | 234 | self.error = error.userFacingMessage |
| @@ -256,23 +260,7 @@ final class SettingsViewModel { | |||
| 256 | ), | 260 | ), |
| 257 | responseType: UpdateUserResponse.self | 261 | responseType: UpdateUserResponse.self |
| 258 | ) | 262 | ) |
| 259 | let updated = result.updateUser | 263 | profile = profile?.applying(result.updateUser) |
| 260 | if let p = profile { | ||
| 261 | profile = UserProfile( | ||
| 262 | username: p.username, | ||
| 263 | canonicalName: p.canonicalName, | ||
| 264 | email: updated.email, | ||
| 265 | url: updated.url, | ||
| 266 | location: updated.location, | ||
| 267 | bio: updated.bio, | ||
| 268 | avatar: updated.avatar ?? p.avatar, | ||
| 269 | userType: p.userType, | ||
| 270 | sshKeys: p.sshKeys, | ||
| 271 | pgpKeys: p.pgpKeys, | ||
| 272 | paymentStatus: p.paymentStatus, | ||
| 273 | subscription: p.subscription | ||
| 274 | ) | ||
| 275 | } | ||
| 276 | } catch { | 264 | } catch { |
| 277 | self.error = error.userFacingMessage | 265 | self.error = error.userFacingMessage |
| 278 | } | 266 | } |
Hutch/Views/Shared/BottomToolbarButton.swift added +24
| @@ -0,0 +1,24 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | /// An icon over a short title, filling its share of a bottom toolbar. | ||
| 4 | struct BottomToolbarButton: View { | ||
| 5 | let title: String | ||
| 6 | let systemImage: String | ||
| 7 | let action: () -> Void | ||
| 8 | |||
| 9 | var body: some View { | ||
| 10 | Button(action: action) { | ||
| 11 | VStack(spacing: 4) { | ||
| 12 | Image(systemName: systemImage) | ||
| 13 | .font(.system(size: 17, weight: .semibold)) | ||
| 14 | Text(title) | ||
| 15 | .font(.caption2) | ||
| 16 | .lineLimit(1) | ||
| 17 | } | ||
| 18 | .frame(maxWidth: .infinity) | ||
| 19 | .contentShape(Rectangle()) | ||
| 20 | } | ||
| 21 | .buttonStyle(.plain) | ||
| 22 | .foregroundStyle(.primary) | ||
| 23 | } | ||
| 24 | } | ||
Hutch/Views/Shared/SettingsSheet.swift added +28
| @@ -0,0 +1,28 @@ | |||
| 1 | import SwiftUI | ||
| 2 | |||
| 3 | /// A settings sheet: a loading state until `model` exists, then `form` for it, with Done to dismiss. | ||
| 4 | struct SettingsSheet<Model, Form: View>: View { | ||
| 5 | let model: Model? | ||
| 6 | @ViewBuilder let form: (Model) -> Form | ||
| 7 | |||
| 8 | @Environment(\.dismiss) private var dismiss | ||
| 9 | |||
| 10 | var body: some View { | ||
| 11 | NavigationStack { | ||
| 12 | Group { | ||
| 13 | if let model { | ||
| 14 | form(model) | ||
| 15 | } else { | ||
| 16 | SRHTLoadingStateView(message: "Loading settings…") | ||
| 17 | } | ||
| 18 | } | ||
| 19 | .navigationTitle("Settings") | ||
| 20 | .navigationBarTitleDisplayMode(.inline) | ||
| 21 | .toolbar { | ||
| 22 | ToolbarItem(placement: .cancellationAction) { | ||
| 23 | Button("Done") { dismiss() } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
Hutch/Views/Tickets/TicketDetailView.swift +82 −71
| @@ -216,86 +216,58 @@ struct TicketDetailView: View { | |||
| 216 | private func detailContent(_ viewModel: TicketDetailViewModel) -> some View { | 216 | private func detailContent(_ viewModel: TicketDetailViewModel) -> some View { |
| 217 | @Bindable var vm = viewModel | 217 | @Bindable var vm = viewModel |
| 218 | 218 | ||
| 219 | if viewModel.isLoading, viewModel.ticket == nil { | 219 | SRHTLoadStateView( |
| 220 | SRHTLoadingStateView(message: "Loading ticket…") | 220 | isLoading: viewModel.isLoading, |
| 221 | } else if let error = viewModel.error, viewModel.ticket == nil { | 221 | error: viewModel.error, |
| 222 | SRHTErrorStateView( | 222 | isEmpty: viewModel.ticket == nil, |
| 223 | title: "Couldn't Load Ticket", | 223 | loadingMessage: "Loading ticket…", |
| 224 | message: error, | 224 | errorTitle: "Couldn't Load Ticket", |
| 225 | retryAction: { await reloadDetail(viewModel) } | 225 | retryAction: { await reloadDetail(viewModel) } |
| 226 | ) | 226 | ) { |
| 227 | } else if let ticket = viewModel.ticket { | 227 | if let ticket = viewModel.ticket { |
| 228 | ScrollView { | 228 | ScrollView { |
| 229 | VStack(alignment: .leading, spacing: 0) { | 229 | VStack(alignment: .leading, spacing: 0) { |
| 230 | if let cacheMetadata = viewModel.cacheMetadata { | 230 | if let cacheMetadata = viewModel.cacheMetadata { |
| 231 | StaleCacheStatusRow(metadata: cacheMetadata, isRefreshing: viewModel.isRefreshingCachedData) | 231 | StaleCacheStatusRow(metadata: cacheMetadata, isRefreshing: viewModel.isRefreshingCachedData) |
| 232 | .padding(.horizontal) | 232 | .padding(.horizontal) |
| 233 | .padding(.vertical, 8) | 233 | .padding(.vertical, 8) |
| 234 | } | 234 | } |
| 235 | |||
| 236 | // Header | ||
| 237 | ticketHeader(ticket, viewModel: viewModel) | ||
| 238 | |||
| 239 | Divider() | ||
| 240 | .padding(.vertical, 12) | ||
| 241 | 235 | ||
| 242 | // Description | 236 | // Header |
| 243 | if let description = ticket.description, !description.isEmpty { | 237 | ticketHeader(ticket, viewModel: viewModel) |
| 244 | MarkdownContentView(markdown: description) | ||
| 245 | .padding(.horizontal) | ||
| 246 | .padding(.bottom, 16) | ||
| 247 | 238 | ||
| 248 | Divider() | 239 | Divider() |
| 249 | .padding(.bottom, 12) | 240 | .padding(.vertical, 12) |
| 250 | } | ||
| 251 | 241 | ||
| 252 | // Event timeline | 242 | // Description |
| 253 | if !viewModel.events.isEmpty { | 243 | descriptionSection(ticket) |
| 254 | Text("Activity") | ||
| 255 | .font(.headline) | ||
| 256 | .padding(.horizontal) | ||
| 257 | .padding(.bottom, 8) | ||
| 258 | |||
| 259 | LazyVStack(alignment: .leading, spacing: 0) { | ||
| 260 | ForEach(viewModel.events) { event in | ||
| 261 | EventRow( | ||
| 262 | event: event, | ||
| 263 | ticketSubmitter: viewModel.ticket?.submitter.canonicalName, | ||
| 264 | ticketAssignees: viewModel.ticket?.assignees.map { $0.canonicalName } | ||
| 265 | ) | ||
| 266 | if event.id != viewModel.events.last?.id { | ||
| 267 | Divider() | ||
| 268 | .padding(.leading, 40) | ||
| 269 | } | ||
| 270 | } | ||
| 271 | } | ||
| 272 | 244 | ||
| 273 | Divider() | 245 | // Event timeline |
| 274 | .padding(.vertical, 12) | 246 | eventsSection(viewModel) |
| 275 | } | ||
| 276 | 247 | ||
| 277 | if appState.isDebugModeEnabled { | 248 | if appState.isDebugModeEnabled { |
| 278 | Divider() | 249 | Divider() |
| 279 | .padding(.vertical, 12) | 250 | .padding(.vertical, 12) |
| 280 | 251 | ||
| 281 | debugSection(viewModel: viewModel, ticket: ticket) | 252 | debugSection(viewModel: viewModel, ticket: ticket) |
| 282 | } | 253 | } |
| 283 | 254 | ||
| 284 | commentInput(viewModel) | 255 | commentInput(viewModel) |
| 256 | } | ||
| 257 | } | ||
| 258 | .task(id: ticket.id) { | ||
| 259 | RecentActivityStore.recordTicket( | ||
| 260 | ownerUsername: ownerUsername, | ||
| 261 | trackerName: trackerName, | ||
| 262 | ticketId: ticket.id, | ||
| 263 | title: ticket.title, | ||
| 264 | defaults: appState.accountDefaults | ||
| 265 | ) | ||
| 266 | } | ||
| 267 | .srhtErrorBanner(error: $vm.error) | ||
| 268 | .refreshable { | ||
| 269 | await reloadDetail(viewModel) | ||
| 285 | } | 270 | } |
| 286 | } | ||
| 287 | .task(id: ticket.id) { | ||
| 288 | RecentActivityStore.recordTicket( | ||
| 289 | ownerUsername: ownerUsername, | ||
| 290 | trackerName: trackerName, | ||
| 291 | ticketId: ticket.id, | ||
| 292 | title: ticket.title, | ||
| 293 | defaults: appState.accountDefaults | ||
| 294 | ) | ||
| 295 | } | ||
| 296 | .srhtErrorBanner(error: $vm.error) | ||
| 297 | .refreshable { | ||
| 298 | await reloadDetail(viewModel) | ||
| 299 | } | 271 | } |
| 300 | } | 272 | } |
| 301 | } | 273 | } |
| @@ -528,6 +500,45 @@ struct TicketDetailView: View { | |||
| 528 | await viewModel.loadTicket() | 500 | await viewModel.loadTicket() |
| 529 | } | 501 | } |
| 530 | } | 502 | } |
| 503 | |||
| 504 | @ViewBuilder | ||
| 505 | private func eventsSection(_ viewModel: TicketDetailViewModel) -> some View { | ||
| 506 | if !viewModel.events.isEmpty { | ||
| 507 | Text("Activity") | ||
| 508 | .font(.headline) | ||
| 509 | .padding(.horizontal) | ||
| 510 | .padding(.bottom, 8) | ||
| 511 | |||
| 512 | LazyVStack(alignment: .leading, spacing: 0) { | ||
| 513 | ForEach(viewModel.events) { event in | ||
| 514 | EventRow( | ||
| 515 | event: event, | ||
| 516 | ticketSubmitter: viewModel.ticket?.submitter.canonicalName, | ||
| 517 | ticketAssignees: viewModel.ticket?.assignees.map { $0.canonicalName } | ||
| 518 | ) | ||
| 519 | if event.id != viewModel.events.last?.id { | ||
| 520 | Divider() | ||
| 521 | .padding(.leading, 40) | ||
| 522 | } | ||
| 523 | } | ||
| 524 | } | ||
| 525 | |||
| 526 | Divider() | ||
| 527 | .padding(.vertical, 12) | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | @ViewBuilder | ||
| 532 | private func descriptionSection(_ ticket: TicketDetail) -> some View { | ||
| 533 | if let description = ticket.description, !description.isEmpty { | ||
| 534 | MarkdownContentView(markdown: description) | ||
| 535 | .padding(.horizontal) | ||
| 536 | .padding(.bottom, 16) | ||
| 537 | |||
| 538 | Divider() | ||
| 539 | .padding(.bottom, 12) | ||
| 540 | } | ||
| 541 | } | ||
| 531 | } | 542 | } |
| 532 | 543 | ||
| 533 | // MARK: - Self-Sizing Markdown Web View | 544 | // MARK: - Self-Sizing Markdown Web View |
Hutch/Views/Tickets/TicketDetailViewModel.swift +9 −26
| @@ -82,11 +82,11 @@ private struct UnassignUserResponse: Decodable, Sendable { | |||
| 82 | let unassignUser: MutationEventResponse | 82 | let unassignUser: MutationEventResponse |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | private struct LabelTicketResponse: Decodable, Sendable { | 85 | private nonisolated struct LabelTicketResponse: Decodable, Sendable { |
| 86 | let labelTicket: MutationEventResponse | 86 | let labelTicket: MutationEventResponse |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | private struct UnlabelTicketResponse: Decodable, Sendable { | 89 | private nonisolated struct UnlabelTicketResponse: Decodable, Sendable { |
| 90 | let unlabelTicket: MutationEventResponse | 90 | let unlabelTicket: MutationEventResponse |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -723,31 +723,14 @@ final class TicketDetailViewModel { | |||
| 723 | } | 723 | } |
| 724 | 724 | ||
| 725 | func labelTicket(labelId: Int) async { | 725 | func labelTicket(labelId: Int) async { |
| 726 | guard !isPerformingAction else { return } | 726 | await runLabelMutation(Self.labelTicketMutation, labelId: labelId, response: LabelTicketResponse.self) |
| 727 | isPerformingAction = true | ||
| 728 | error = nil | ||
| 729 | |||
| 730 | do { | ||
| 731 | _ = try await client.execute( | ||
| 732 | service: .todo, | ||
| 733 | query: Self.labelTicketMutation, | ||
| 734 | variables: [ | ||
| 735 | "trackerId": trackerId, | ||
| 736 | "ticketId": ticketId, | ||
| 737 | "labelId": labelId | ||
| 738 | ], | ||
| 739 | responseType: LabelTicketResponse.self | ||
| 740 | ) | ||
| 741 | await invalidateAfterMutation() | ||
| 742 | await reloadTicketPreservingDebugState() | ||
| 743 | } catch { | ||
| 744 | self.error = error.userFacingMessage | ||
| 745 | } | ||
| 746 | |||
| 747 | isPerformingAction = false | ||
| 748 | } | 727 | } |
| 749 | 728 | ||
| 750 | func unlabelTicket(labelId: Int) async { | 729 | func unlabelTicket(labelId: Int) async { |
| 730 | await runLabelMutation(Self.unlabelTicketMutation, labelId: labelId, response: UnlabelTicketResponse.self) | ||
| 731 | } | ||
| 732 | |||
| 733 | private func runLabelMutation<Response: Decodable & Sendable>(_ query: String, labelId: Int, response: Response.Type) async { | ||
| 751 | guard !isPerformingAction else { return } | 734 | guard !isPerformingAction else { return } |
| 752 | isPerformingAction = true | 735 | isPerformingAction = true |
| 753 | error = nil | 736 | error = nil |
| @@ -755,13 +738,13 @@ final class TicketDetailViewModel { | |||
| 755 | do { | 738 | do { |
| 756 | _ = try await client.execute( | 739 | _ = try await client.execute( |
| 757 | service: .todo, | 740 | service: .todo, |
| 758 | query: Self.unlabelTicketMutation, | 741 | query: query, |
| 759 | variables: [ | 742 | variables: [ |
| 760 | "trackerId": trackerId, | 743 | "trackerId": trackerId, |
| 761 | "ticketId": ticketId, | 744 | "ticketId": ticketId, |
| 762 | "labelId": labelId | 745 | "labelId": labelId |
| 763 | ], | 746 | ], |
| 764 | responseType: UnlabelTicketResponse.self | 747 | responseType: response |
| 765 | ) | 748 | ) |
| 766 | await invalidateAfterMutation() | 749 | await invalidateAfterMutation() |
| 767 | await reloadTicketPreservingDebugState() | 750 | await reloadTicketPreservingDebugState() |
Hutch/Views/Tickets/TicketListView.swift +95 −84
| @@ -283,68 +283,7 @@ struct TicketListView: View { | |||
| 283 | .listRowSeparator(.hidden) | 283 | .listRowSeparator(.hidden) |
| 284 | 284 | ||
| 285 | ForEach(viewModel.filteredTickets) { ticket in | 285 | ForEach(viewModel.filteredTickets) { ticket in |
| 286 | Group { | 286 | ticketRow(ticket, viewModel) |
| 287 | if viewModel.isSelectionMode { | ||
| 288 | Button { | ||
| 289 | viewModel.toggleTicketSelection(ticket) | ||
| 290 | } label: { | ||
| 291 | SelectableTicketRow( | ||
| 292 | ticket: ticket, | ||
| 293 | isSelected: viewModel.selectedTicketIDs.contains(ticket.id) | ||
| 294 | ) | ||
| 295 | .equatable() | ||
| 296 | } | ||
| 297 | .buttonStyle(.plain) | ||
| 298 | } else { | ||
| 299 | NavigationLink { | ||
| 300 | TicketDetailView( | ||
| 301 | ownerUsername: String(tracker.owner.canonicalName.dropFirst()), | ||
| 302 | trackerName: tracker.name, | ||
| 303 | trackerId: tracker.id, | ||
| 304 | trackerRid: tracker.rid, | ||
| 305 | ticketId: ticket.id | ||
| 306 | ) | ||
| 307 | } label: { | ||
| 308 | TicketRowView(ticket: ticket) | ||
| 309 | .equatable() | ||
| 310 | } | ||
| 311 | .contextMenu { | ||
| 312 | if let url = SRHTWebURL.ticket(ownerUsername: ownerUsername(for: tracker), trackerName: tracker.name, ticketId: ticket.id) { | ||
| 313 | Button { | ||
| 314 | openURL(url) | ||
| 315 | } label: { | ||
| 316 | Label("Open in Browser", systemImage: "safari") | ||
| 317 | } | ||
| 318 | |||
| 319 | Button { | ||
| 320 | appState.copyToPasteboard(url.absoluteString, label: "ticket URL") | ||
| 321 | } label: { | ||
| 322 | Label("Copy URL", systemImage: "doc.on.doc") | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | Button { | ||
| 327 | appState.copyToPasteboard(String(ticket.id), label: "ticket ID") | ||
| 328 | } label: { | ||
| 329 | Label("Copy Ticket ID", systemImage: "number") | ||
| 330 | } | ||
| 331 | } | ||
| 332 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 333 | if swipeActionsEnabled { | ||
| 334 | ticketAssignSwipeAction(ticket, viewModel: viewModel) | ||
| 335 | } | ||
| 336 | } | ||
| 337 | .swipeActions(edge: .trailing, allowsFullSwipe: false) { | ||
| 338 | if swipeActionsEnabled { | ||
| 339 | ticketStatusSwipeAction(ticket, viewModel: viewModel) | ||
| 340 | ticketLabelSwipeAction(ticket, viewModel: viewModel) | ||
| 341 | } | ||
| 342 | } | ||
| 343 | } | ||
| 344 | } | ||
| 345 | .task { | ||
| 346 | await viewModel.loadMoreIfNeeded(currentItem: ticket) | ||
| 347 | } | ||
| 348 | } | 287 | } |
| 349 | .themedRow() | 288 | .themedRow() |
| 350 | 289 | ||
| @@ -385,28 +324,7 @@ struct TicketListView: View { | |||
| 385 | viewModel.recordRecentSearch(query) | 324 | viewModel.recordRecentSearch(query) |
| 386 | } | 325 | } |
| 387 | .overlay { | 326 | .overlay { |
| 388 | if viewModel.isLoading, viewModel.tickets.isEmpty { | 327 | emptyState(viewModel) |
| 389 | SRHTLoadingStateView(message: "Loading tickets…") | ||
| 390 | } else if let error = viewModel.error, viewModel.tickets.isEmpty { | ||
| 391 | SRHTErrorStateView( | ||
| 392 | title: "Couldn't Load Tickets", | ||
| 393 | message: error, | ||
| 394 | retryAction: { await viewModel.loadTickets() } | ||
| 395 | ) | ||
| 396 | } else if !viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, | ||
| 397 | viewModel.filteredTickets.isEmpty { | ||
| 398 | ContentUnavailableView( | ||
| 399 | "No Ticket Matches", | ||
| 400 | systemImage: "magnifyingglass", | ||
| 401 | description: Text("No tickets in \(tracker.name) matched “\(viewModel.searchText)”.") | ||
| 402 | ) | ||
| 403 | } else if viewModel.filteredTickets.isEmpty, viewModel.error == nil { | ||
| 404 | ContentUnavailableView( | ||
| 405 | "No Tickets", | ||
| 406 | systemImage: "ticket", | ||
| 407 | description: Text(emptyStateDescription(for: viewModel)) | ||
| 408 | ) | ||
| 409 | } | ||
| 410 | } | 328 | } |
| 411 | .connectivityOverlay(hasContent: !viewModel.filteredTickets.isEmpty) { | 329 | .connectivityOverlay(hasContent: !viewModel.filteredTickets.isEmpty) { |
| 412 | await viewModel.loadTickets() | 330 | await viewModel.loadTickets() |
| @@ -636,6 +554,99 @@ struct TicketListView: View { | |||
| 636 | let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines) | 554 | let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines) |
| 637 | return trimmed.hasPrefix("~") ? String(trimmed.dropFirst()) : trimmed | 555 | return trimmed.hasPrefix("~") ? String(trimmed.dropFirst()) : trimmed |
| 638 | } | 556 | } |
| 557 | |||
| 558 | @ViewBuilder | ||
| 559 | private func emptyState(_ viewModel: TicketListViewModel) -> some View { | ||
| 560 | SRHTLoadStateView( | ||
| 561 | isLoading: viewModel.isLoading, | ||
| 562 | error: viewModel.error, | ||
| 563 | isEmpty: viewModel.tickets.isEmpty, | ||
| 564 | loadingMessage: "Loading tickets…", | ||
| 565 | errorTitle: "Couldn't Load Tickets", | ||
| 566 | retryAction: { await viewModel.loadTickets() } | ||
| 567 | ) { | ||
| 568 | if !viewModel.searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty, | ||
| 569 | viewModel.filteredTickets.isEmpty { | ||
| 570 | ContentUnavailableView( | ||
| 571 | "No Ticket Matches", | ||
| 572 | systemImage: "magnifyingglass", | ||
| 573 | description: Text("No tickets in \(tracker.name) matched “\(viewModel.searchText)”.") | ||
| 574 | ) | ||
| 575 | } else if viewModel.filteredTickets.isEmpty, viewModel.error == nil { | ||
| 576 | ContentUnavailableView( | ||
| 577 | "No Tickets", | ||
| 578 | systemImage: "ticket", | ||
| 579 | description: Text(emptyStateDescription(for: viewModel)) | ||
| 580 | ) | ||
| 581 | } | ||
| 582 | } | ||
| 583 | } | ||
| 584 | |||
| 585 | @ViewBuilder | ||
| 586 | private func ticketRow(_ ticket: TicketSummary, _ viewModel: TicketListViewModel) -> some View { | ||
| 587 | Group { | ||
| 588 | if viewModel.isSelectionMode { | ||
| 589 | Button { | ||
| 590 | viewModel.toggleTicketSelection(ticket) | ||
| 591 | } label: { | ||
| 592 | SelectableTicketRow( | ||
| 593 | ticket: ticket, | ||
| 594 | isSelected: viewModel.selectedTicketIDs.contains(ticket.id) | ||
| 595 | ) | ||
| 596 | .equatable() | ||
| 597 | } | ||
| 598 | .buttonStyle(.plain) | ||
| 599 | } else { | ||
| 600 | NavigationLink { | ||
| 601 | TicketDetailView( | ||
| 602 | ownerUsername: String(tracker.owner.canonicalName.dropFirst()), | ||
| 603 | trackerName: tracker.name, | ||
| 604 | trackerId: tracker.id, | ||
| 605 | trackerRid: tracker.rid, | ||
| 606 | ticketId: ticket.id | ||
| 607 | ) | ||
| 608 | } label: { | ||
| 609 | TicketRowView(ticket: ticket) | ||
| 610 | .equatable() | ||
| 611 | } | ||
| 612 | .contextMenu { | ||
| 613 | if let url = SRHTWebURL.ticket(ownerUsername: ownerUsername(for: tracker), trackerName: tracker.name, ticketId: ticket.id) { | ||
| 614 | Button { | ||
| 615 | openURL(url) | ||
| 616 | } label: { | ||
| 617 | Label("Open in Browser", systemImage: "safari") | ||
| 618 | } | ||
| 619 | |||
| 620 | Button { | ||
| 621 | appState.copyToPasteboard(url.absoluteString, label: "ticket URL") | ||
| 622 | } label: { | ||
| 623 | Label("Copy URL", systemImage: "doc.on.doc") | ||
| 624 | } | ||
| 625 | } | ||
| 626 | |||
| 627 | Button { | ||
| 628 | appState.copyToPasteboard(String(ticket.id), label: "ticket ID") | ||
| 629 | } label: { | ||
| 630 | Label("Copy Ticket ID", systemImage: "number") | ||
| 631 | } | ||
| 632 | } | ||
| 633 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 634 | if swipeActionsEnabled { | ||
| 635 | ticketAssignSwipeAction(ticket, viewModel: viewModel) | ||
| 636 | } | ||
| 637 | } | ||
| 638 | .swipeActions(edge: .trailing, allowsFullSwipe: false) { | ||
| 639 | if swipeActionsEnabled { | ||
| 640 | ticketStatusSwipeAction(ticket, viewModel: viewModel) | ||
| 641 | ticketLabelSwipeAction(ticket, viewModel: viewModel) | ||
| 642 | } | ||
| 643 | } | ||
| 644 | } | ||
| 645 | } | ||
| 646 | .task { | ||
| 647 | await viewModel.loadMoreIfNeeded(currentItem: ticket) | ||
| 648 | } | ||
| 649 | } | ||
| 639 | } | 650 | } |
| 640 | 651 | ||
| 641 | private struct LabelEditorTicket: Identifiable { | 652 | private struct LabelEditorTicket: Identifiable { |
Hutch/Views/Tickets/TicketListViewModel.swift +26 −66
| @@ -15,7 +15,7 @@ private struct TicketsPage: Decodable, Sendable { | |||
| 15 | let cursor: String? | 15 | let cursor: String? |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | private struct AssignmentMutationResponse: Decodable, Sendable { | 18 | private nonisolated struct AssignmentMutationResponse: Decodable, Sendable { |
| 19 | struct EventRef: Decodable, Sendable { | 19 | struct EventRef: Decodable, Sendable { |
| 20 | let id: Int | 20 | let id: Int |
| 21 | } | 21 | } |
| @@ -24,7 +24,7 @@ private struct AssignmentMutationResponse: Decodable, Sendable { | |||
| 24 | let unassignUser: EventRef? | 24 | let unassignUser: EventRef? |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | private struct LabelMutationResponse: Decodable, Sendable { | 27 | private nonisolated struct LabelMutationResponse: Decodable, Sendable { |
| 28 | struct EventRef: Decodable, Sendable { | 28 | struct EventRef: Decodable, Sendable { |
| 29 | let id: Int | 29 | let id: Int |
| 30 | } | 30 | } |
| @@ -499,22 +499,7 @@ final class TicketListViewModel { | |||
| 499 | tickets[index] = updated | 499 | tickets[index] = updated |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | do { | 502 | await commitTicketMutation(Self.assignUserMutation, ticketID: ticket.id, subject: ["userId": user.id], response: AssignmentMutationResponse.self, original: original) |
| 503 | _ = try await client.execute( | ||
| 504 | service: .todo, | ||
| 505 | query: Self.assignUserMutation, | ||
| 506 | variables: [ | ||
| 507 | "trackerId": trackerId, | ||
| 508 | "ticketId": ticket.id, | ||
| 509 | "userId": user.id | ||
| 510 | ], | ||
| 511 | responseType: AssignmentMutationResponse.self | ||
| 512 | ) | ||
| 513 | await invalidateTicketCaches() | ||
| 514 | } catch { | ||
| 515 | tickets = original | ||
| 516 | self.error = error.userFacingMessage | ||
| 517 | } | ||
| 518 | 503 | ||
| 519 | isPerformingAction = false | 504 | isPerformingAction = false |
| 520 | } | 505 | } |
| @@ -542,22 +527,7 @@ final class TicketListViewModel { | |||
| 542 | tickets[index] = updated | 527 | tickets[index] = updated |
| 543 | } | 528 | } |
| 544 | 529 | ||
| 545 | do { | 530 | await commitTicketMutation(Self.unassignUserMutation, ticketID: ticket.id, subject: ["userId": user.id], response: AssignmentMutationResponse.self, original: original) |
| 546 | _ = try await client.execute( | ||
| 547 | service: .todo, | ||
| 548 | query: Self.unassignUserMutation, | ||
| 549 | variables: [ | ||
| 550 | "trackerId": trackerId, | ||
| 551 | "ticketId": ticket.id, | ||
| 552 | "userId": user.id | ||
| 553 | ], | ||
| 554 | responseType: AssignmentMutationResponse.self | ||
| 555 | ) | ||
| 556 | await invalidateTicketCaches() | ||
| 557 | } catch { | ||
| 558 | tickets = original | ||
| 559 | self.error = error.userFacingMessage | ||
| 560 | } | ||
| 561 | 531 | ||
| 562 | isPerformingAction = false | 532 | isPerformingAction = false |
| 563 | } | 533 | } |
| @@ -743,22 +713,7 @@ final class TicketListViewModel { | |||
| 743 | tickets[index] = updated | 713 | tickets[index] = updated |
| 744 | } | 714 | } |
| 745 | 715 | ||
| 746 | do { | 716 | await commitTicketMutation(Self.labelTicketMutation, ticketID: ticket.id, subject: ["labelId": label.id], response: LabelMutationResponse.self, original: original) |
| 747 | _ = try await client.execute( | ||
| 748 | service: .todo, | ||
| 749 | query: Self.labelTicketMutation, | ||
| 750 | variables: [ | ||
| 751 | "trackerId": trackerId, | ||
| 752 | "ticketId": ticket.id, | ||
| 753 | "labelId": label.id | ||
| 754 | ], | ||
| 755 | responseType: LabelMutationResponse.self | ||
| 756 | ) | ||
| 757 | await invalidateTicketCaches() | ||
| 758 | } catch { | ||
| 759 | tickets = original | ||
| 760 | self.error = error.userFacingMessage | ||
| 761 | } | ||
| 762 | 717 | ||
| 763 | isPerformingAction = false | 718 | isPerformingAction = false |
| 764 | } | 719 | } |
| @@ -784,22 +739,7 @@ final class TicketListViewModel { | |||
| 784 | tickets[index] = updated | 739 | tickets[index] = updated |
| 785 | } | 740 | } |
| 786 | 741 | ||
| 787 | do { | 742 | await commitTicketMutation(Self.unlabelTicketMutation, ticketID: ticket.id, subject: ["labelId": label.id], response: LabelMutationResponse.self, original: original) |
| 788 | _ = try await client.execute( | ||
| 789 | service: .todo, | ||
| 790 | query: Self.unlabelTicketMutation, | ||
| 791 | variables: [ | ||
| 792 | "trackerId": trackerId, | ||
| 793 | "ticketId": ticket.id, | ||
| 794 | "labelId": label.id | ||
| 795 | ], | ||
| 796 | responseType: LabelMutationResponse.self | ||
| 797 | ) | ||
| 798 | await invalidateTicketCaches() | ||
| 799 | } catch { | ||
| 800 | tickets = original | ||
| 801 | self.error = error.userFacingMessage | ||
| 802 | } | ||
| 803 | 743 | ||
| 804 | isPerformingAction = false | 744 | isPerformingAction = false |
| 805 | } | 745 | } |
| @@ -1070,6 +1010,26 @@ final class TicketListViewModel { | |||
| 1070 | ) | 1010 | ) |
| 1071 | } | 1011 | } |
| 1072 | 1012 | ||
| 1013 | /// Sends an assignment or label mutation for one ticket, restoring `original` | ||
| 1014 | /// if it fails. `subject` is the user or label added or removed, e.g. `["userId": 7]`. | ||
| 1015 | private func commitTicketMutation<Response: Decodable & Sendable>( | ||
| 1016 | _ query: String, | ||
| 1017 | ticketID: Int, | ||
| 1018 | subject: [String: Int], | ||
| 1019 | response: Response.Type, | ||
| 1020 | original: [TicketSummary] | ||
| 1021 | ) async { | ||
| 1022 | var variables: [String: any Sendable] = ["trackerId": trackerId, "ticketId": ticketID] | ||
| 1023 | for (key, id) in subject { variables[key] = id } | ||
| 1024 | do { | ||
| 1025 | _ = try await client.execute(service: .todo, query: query, variables: variables, responseType: response) | ||
| 1026 | await invalidateTicketCaches() | ||
| 1027 | } catch { | ||
| 1028 | tickets = original | ||
| 1029 | self.error = error.userFacingMessage | ||
| 1030 | } | ||
| 1031 | } | ||
| 1032 | |||
| 1073 | private func invalidateTicketCaches() async { | 1033 | private func invalidateTicketCaches() async { |
| 1074 | await client.invalidateCache(prefix: APICacheKeys.prefix(SRHTService.todo.rawValue, "tickets")) | 1034 | await client.invalidateCache(prefix: APICacheKeys.prefix(SRHTService.todo.rawValue, "tickets")) |
| 1075 | await client.invalidateCache(prefix: APICacheKeys.prefix(SRHTService.todo.rawValue, "ticket")) | 1035 | await client.invalidateCache(prefix: APICacheKeys.prefix(SRHTService.todo.rawValue, "ticket")) |
Hutch/Views/Tickets/TrackerListView.swift +18 −44
| @@ -184,22 +184,23 @@ struct TrackerListView: View { | |||
| 184 | prompt: "Search trackers" | 184 | prompt: "Search trackers" |
| 185 | ) | 185 | ) |
| 186 | .overlay { | 186 | .overlay { |
| 187 | if viewModel.isLoading, viewModel.trackers.isEmpty { | 187 | SRHTLoadStateView( |
| 188 | SRHTLoadingStateView(message: "Loading trackers…") | 188 | isLoading: viewModel.isLoading, |
| 189 | } else if let error = viewModel.error, viewModel.trackers.isEmpty { | 189 | error: viewModel.error, |
| 190 | SRHTErrorStateView( | 190 | isEmpty: viewModel.trackers.isEmpty, |
| 191 | title: "Couldn't Load Trackers", | 191 | loadingMessage: "Loading trackers…", |
| 192 | message: error, | 192 | errorTitle: "Couldn't Load Trackers", |
| 193 | retryAction: { await viewModel.loadTrackers() } | 193 | retryAction: { await viewModel.loadTrackers() } |
| 194 | ) | 194 | ) { |
| 195 | } else if !viewModel.trackers.isEmpty, viewModel.filteredTrackers.isEmpty { | 195 | if !viewModel.trackers.isEmpty, viewModel.filteredTrackers.isEmpty { |
| 196 | ContentUnavailableView.search(text: viewModel.searchText) | 196 | ContentUnavailableView.search(text: viewModel.searchText) |
| 197 | } else if viewModel.trackers.isEmpty, viewModel.error == nil { | 197 | } else if viewModel.trackers.isEmpty, viewModel.error == nil { |
| 198 | ContentUnavailableView( | 198 | ContentUnavailableView( |
| 199 | "No Trackers", | 199 | "No Trackers", |
| 200 | systemImage: "checklist", | 200 | systemImage: "checklist", |
| 201 | description: Text("Your bug trackers will appear here.") | 201 | description: Text("Your bug trackers will appear here.") |
| 202 | ) | 202 | ) |
| 203 | } | ||
| 203 | } | 204 | } |
| 204 | } | 205 | } |
| 205 | .connectivityOverlay(hasContent: !viewModel.trackers.isEmpty) { | 206 | .connectivityOverlay(hasContent: !viewModel.trackers.isEmpty) { |
| @@ -235,34 +236,7 @@ private struct TrackerRowView: View { | |||
| 235 | let tracker: TrackerSummary | 236 | let tracker: TrackerSummary |
| 236 | 237 | ||
| 237 | var body: some View { | 238 | var body: some View { |
| 238 | VStack(alignment: .leading, spacing: 4) { | 239 | TrackerSummaryRow(tracker: tracker) |
| 239 | HStack { | ||
| 240 | Text(tracker.name) | ||
| 241 | .font(.subheadline.weight(.medium)) | ||
| 242 | |||
| 243 | Spacer() | ||
| 244 | |||
| 245 | VisibilityBadge(visibility: tracker.visibility) | ||
| 246 | } | ||
| 247 | |||
| 248 | if let owner = tracker.owner.canonicalName.split(separator: "~").last { | ||
| 249 | Text("~\(owner)") | ||
| 250 | .font(.caption) | ||
| 251 | .foregroundStyle(.secondary) | ||
| 252 | } | ||
| 253 | |||
| 254 | if let description = tracker.description, !description.isEmpty { | ||
| 255 | Text(description) | ||
| 256 | .font(.caption) | ||
| 257 | .foregroundStyle(.secondary) | ||
| 258 | .lineLimit(2) | ||
| 259 | } | ||
| 260 | |||
| 261 | Text(tracker.updated.relativeDescription) | ||
| 262 | .font(.caption2) | ||
| 263 | .foregroundStyle(.tertiary) | ||
| 264 | } | ||
| 265 | .padding(.vertical, 2) | ||
| 266 | .contextMenu { | 240 | .contextMenu { |
| 267 | if let url = SRHTWebURL.tracker(tracker) { | 241 | if let url = SRHTWebURL.tracker(tracker) { |
| 268 | Button { | 242 | Button { |
Hutch/Views/Work/WorkView.swift +46 −47
| @@ -183,46 +183,7 @@ struct WorkView: View { | |||
| 183 | .themedRow() | 183 | .themedRow() |
| 184 | } else { | 184 | } else { |
| 185 | ForEach(viewModel.assignedTickets) { ticket in | 185 | ForEach(viewModel.assignedTickets) { ticket in |
| 186 | NavigationLink { | 186 | assignedTicketRow(ticket, viewModel) |
| 187 | TicketDetailView( | ||
| 188 | ownerUsername: ticket.ownerUsername, | ||
| 189 | trackerName: ticket.trackerName, | ||
| 190 | trackerId: ticket.trackerId, | ||
| 191 | trackerRid: ticket.trackerRid, | ||
| 192 | ticketId: ticket.ticket.id | ||
| 193 | ) | ||
| 194 | } label: { | ||
| 195 | WorkAssignedTicketRow(ticket: ticket) | ||
| 196 | } | ||
| 197 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 198 | if swipeActionsEnabled { | ||
| 199 | if ticket.ticket.status.isOpen { | ||
| 200 | Button { | ||
| 201 | Task { await viewModel.resolveTicket(ticket) } | ||
| 202 | } label: { | ||
| 203 | Label("Resolve", systemImage: "checkmark.circle") | ||
| 204 | } | ||
| 205 | .tint(.green) | ||
| 206 | } else { | ||
| 207 | Button { | ||
| 208 | Task { await viewModel.reopenTicket(ticket) } | ||
| 209 | } label: { | ||
| 210 | Label("Reopen", systemImage: "arrow.uturn.backward") | ||
| 211 | } | ||
| 212 | .tint(.blue) | ||
| 213 | } | ||
| 214 | } | ||
| 215 | } | ||
| 216 | .swipeActions(edge: .trailing, allowsFullSwipe: false) { | ||
| 217 | if swipeActionsEnabled { | ||
| 218 | Button { | ||
| 219 | Task { await viewModel.unassignFromMe(ticket) } | ||
| 220 | } label: { | ||
| 221 | Label("Unassign", systemImage: "person.badge.minus") | ||
| 222 | } | ||
| 223 | .tint(.orange) | ||
| 224 | } | ||
| 225 | } | ||
| 226 | } | 187 | } |
| 227 | .themedRow() | 188 | .themedRow() |
| 228 | } | 189 | } |
| @@ -272,16 +233,54 @@ struct WorkView: View { | |||
| 272 | return viewModel | 233 | return viewModel |
| 273 | } | 234 | } |
| 274 | 235 | ||
| 275 | let newViewModel = HomeViewModel( | 236 | let newViewModel = HomeViewModel(currentUser: currentUser, appState: appState) |
| 276 | currentUser: currentUser, | ||
| 277 | client: appState.client, | ||
| 278 | systemStatusRepository: appState.systemStatusRepository, | ||
| 279 | defaults: appState.accountDefaults, | ||
| 280 | accountID: appState.activeAccountID | ||
| 281 | ) | ||
| 282 | viewModel = newViewModel | 237 | viewModel = newViewModel |
| 283 | return newViewModel | 238 | return newViewModel |
| 284 | } | 239 | } |
| 240 | |||
| 241 | @ViewBuilder | ||
| 242 | private func assignedTicketRow(_ ticket: HomeAssignedTicket, _ viewModel: HomeViewModel) -> some View { | ||
| 243 | NavigationLink { | ||
| 244 | TicketDetailView( | ||
| 245 | ownerUsername: ticket.ownerUsername, | ||
| 246 | trackerName: ticket.trackerName, | ||
| 247 | trackerId: ticket.trackerId, | ||
| 248 | trackerRid: ticket.trackerRid, | ||
| 249 | ticketId: ticket.ticket.id | ||
| 250 | ) | ||
| 251 | } label: { | ||
| 252 | WorkAssignedTicketRow(ticket: ticket) | ||
| 253 | } | ||
| 254 | .swipeActions(edge: .leading, allowsFullSwipe: true) { | ||
| 255 | if swipeActionsEnabled { | ||
| 256 | if ticket.ticket.status.isOpen { | ||
| 257 | Button { | ||
| 258 | Task { await viewModel.resolveTicket(ticket) } | ||
| 259 | } label: { | ||
| 260 | Label("Resolve", systemImage: "checkmark.circle") | ||
| 261 | } | ||
| 262 | .tint(.green) | ||
| 263 | } else { | ||
| 264 | Button { | ||
| 265 | Task { await viewModel.reopenTicket(ticket) } | ||
| 266 | } label: { | ||
| 267 | Label("Reopen", systemImage: "arrow.uturn.backward") | ||
| 268 | } | ||
| 269 | .tint(.blue) | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } | ||
| 273 | .swipeActions(edge: .trailing, allowsFullSwipe: false) { | ||
| 274 | if swipeActionsEnabled { | ||
| 275 | Button { | ||
| 276 | Task { await viewModel.unassignFromMe(ticket) } | ||
| 277 | } label: { | ||
| 278 | Label("Unassign", systemImage: "person.badge.minus") | ||
| 279 | } | ||
| 280 | .tint(.orange) | ||
| 281 | } | ||
| 282 | } | ||
| 283 | } | ||
| 285 | } | 284 | } |
| 286 | 285 | ||
| 287 | private struct WorkThreadRow: View { | 286 | private struct WorkThreadRow: View { |
HutchTests/OrgNativeRenderingTests.swift +1
| @@ -1,5 +1,6 @@ | |||
| 1 | import Foundation | 1 | import Foundation |
| 2 | import OrgSwiftUI | 2 | import OrgSwiftUI |
| 3 | import SwiftUI | ||
| 3 | import Testing | 4 | import Testing |
| 4 | @testable import Hutch | 5 | @testable import Hutch |
| 5 | 6 | ||