mirror of
https://codeberg.org/secana/Forji.git
synced 2026-06-16 05:13:55 -07:00
fix: show graceful empty state when repository has pull requests turned off
This commit is contained in:
parent
617e687e7b
commit
ad2f428baf
1 changed files with 33 additions and 9 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue