From de5cb025b8fc7b4f976955e64cc5df4852066d87 Mon Sep 17 00:00:00 2001 From: Stefan Hausotte Date: Sat, 13 Jun 2026 14:12:38 +0200 Subject: [PATCH] fix: show graceful empty state when repository has pull requests turned off (#77) Reviewed-on: https://codeberg.org/secana/Forji/pulls/77 --- Forji/Forji/Views/PullRequestListView.swift | 42 ++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Forji/Forji/Views/PullRequestListView.swift b/Forji/Forji/Views/PullRequestListView.swift index af679f7..bdd5885 100644 --- a/Forji/Forji/Views/PullRequestListView.swift +++ b/Forji/Forji/Views/PullRequestListView.swift @@ -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 { 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 {