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 (#77)
Reviewed-on: https://codeberg.org/secana/Forji/pulls/77
This commit is contained in:
parent
100d7c412c
commit
de5cb025b8
1 changed files with 33 additions and 9 deletions
|
|
@ -38,6 +38,12 @@ struct PullRequestListView: View {
|
||||||
List {
|
List {
|
||||||
if pagination.isLoading, pagination.items.isEmpty {
|
if pagination.isLoading, pagination.items.isEmpty {
|
||||||
LoadingListSection()
|
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 {
|
} else if pagination.items.isEmpty {
|
||||||
ContentUnavailableView {
|
ContentUnavailableView {
|
||||||
Label(
|
Label(
|
||||||
|
|
@ -116,13 +122,18 @@ struct PullRequestListView: View {
|
||||||
private func reloadPullRequests(clearItems: Bool = false) -> Task<Void, Never> {
|
private func reloadPullRequests(clearItems: Bool = false) -> Task<Void, Never> {
|
||||||
guard let prService else { return Task {} }
|
guard let prService else { return Task {} }
|
||||||
return pagination.reload(clearItems: clearItems) { [self] page, limit in
|
return pagination.reload(clearItems: clearItems) { [self] page, limit in
|
||||||
try await prService.fetchPullRequests(
|
do {
|
||||||
owner: owner,
|
return try await prService.fetchPullRequests(
|
||||||
repo: repo,
|
owner: owner,
|
||||||
state: stateFilter.rawValue,
|
repo: repo,
|
||||||
page: page,
|
state: stateFilter.rawValue,
|
||||||
limit: limit,
|
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
|
#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.repository = repository
|
||||||
self.authService = authService
|
self.authService = authService
|
||||||
prService = nil
|
prService = nil
|
||||||
_pagination = State(initialValue: PaginationState(items: pullRequests))
|
_pagination = State(initialValue: PaginationState(items: pullRequests, notFound: notFound))
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -160,6 +172,18 @@ struct PullRequestListView: View {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Preview("Pull Requests Unavailable") {
|
||||||
|
NavigationStack {
|
||||||
|
PullRequestListView(
|
||||||
|
preview: (),
|
||||||
|
repository: .preview,
|
||||||
|
authService: .previewDefault,
|
||||||
|
pullRequests: [],
|
||||||
|
notFound: true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct PullRequestRow: View {
|
struct PullRequestRow: View {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue