fix: show graceful empty state when repository has pull requests turned off

This commit is contained in:
Stefan Hausotte 2026-06-13 14:12:03 +02:00
parent 617e687e7b
commit ad2f428baf

View file

@ -38,6 +38,12 @@ struct PullRequestListView: View {
List {
if pagination.isLoading, pagination.items.isEmpty {
LoadingListSection()
} else if pagination.notFound {
ContentUnavailableView {
Label("Pull Requests Unavailable", systemImage: "exclamationmark.circle")
} description: {
Text("Pull requests are not available for this repository.")
}
} else if pagination.items.isEmpty {
ContentUnavailableView {
Label(
@ -116,13 +122,18 @@ struct PullRequestListView: View {
private func reloadPullRequests(clearItems: Bool = false) -> Task<Void, Never> {
guard let prService else { return Task {} }
return pagination.reload(clearItems: clearItems) { [self] page, limit in
try await prService.fetchPullRequests(
owner: owner,
repo: repo,
state: stateFilter.rawValue,
page: page,
limit: limit,
)
do {
return try await prService.fetchPullRequests(
owner: owner,
repo: repo,
state: stateFilter.rawValue,
page: page,
limit: limit,
)
} catch let error as ServiceError where error.httpStatusCode == 404 {
pagination.notFound = true
return []
}
}
}
@ -140,11 +151,12 @@ struct PullRequestListView: View {
}
#if DEBUG
init(preview _: Void, repository: Repository, authService: AuthenticationService, pullRequests: [PullRequest]) {
init(preview _: Void, repository: Repository, authService: AuthenticationService, pullRequests: [PullRequest],
notFound: Bool = false) {
self.repository = repository
self.authService = authService
prService = nil
_pagination = State(initialValue: PaginationState(items: pullRequests))
_pagination = State(initialValue: PaginationState(items: pullRequests, notFound: notFound))
}
#endif
}
@ -160,6 +172,18 @@ struct PullRequestListView: View {
)
}
}
#Preview("Pull Requests Unavailable") {
NavigationStack {
PullRequestListView(
preview: (),
repository: .preview,
authService: .previewDefault,
pullRequests: [],
notFound: true,
)
}
}
#endif
struct PullRequestRow: View {