diff --git a/Classes/Repository/RepositoryClient.swift b/Classes/Repository/RepositoryClient.swift index de7edda0..0ea8cd18 100644 --- a/Classes/Repository/RepositoryClient.swift +++ b/Classes/Repository/RepositoryClient.swift @@ -11,6 +11,7 @@ import Apollo protocol RepositoryLoadable { var owner: String { get } var name: String { get } + var hasIssuesEnabled: Bool { get } } extension RepositoryLoadable { @@ -101,6 +102,8 @@ final class RepositoryClient { } func loadMoreIssues(containerWidth: CGFloat, completion: @escaping () -> ()) { + guard repo.hasIssuesEnabled else { return } + load(queryType: RepoIssuesQuery.self, repo: repo, after: issuesNextPage, containerWidth: containerWidth) { result in switch result { case .error: @@ -133,13 +136,12 @@ final class RepositoryClient { } func load(containerWidth: CGFloat, completion: @escaping () -> ()) { - var responseCount = 0 - + var expectedResponseCount = repo.hasIssuesEnabled ? 2 : 1 + let checkResponses = { - responseCount += 1 + expectedResponseCount -= 1 - // Wait until we've had two responses (issues & pull requests) - guard responseCount == 2 else { return } + guard expectedResponseCount == 0 else { return } completion() } diff --git a/Classes/Repository/RepositoryViewController.swift b/Classes/Repository/RepositoryViewController.swift index c193f691..65deaa79 100644 --- a/Classes/Repository/RepositoryViewController.swift +++ b/Classes/Repository/RepositoryViewController.swift @@ -17,11 +17,12 @@ class RepositoryViewController: UIViewController, private let client: RepositoryClient private lazy var feed: Feed = { Feed(viewController: self, delegate: self) }() - private let selection = SegmentedControlModel.forRepository() + private let selection: SegmentedControlModel private let loadMore = "loadMore" as ListDiffable init(client: GithubClient, repo: RepositoryLoadable) { self.client = RepositoryClient(githubClient: client, repo: repo) + self.selection = SegmentedControlModel.forRepository(repo) super.init(nibName: nil, bundle: nil) } @@ -79,7 +80,11 @@ class RepositoryViewController: UIViewController, // MARK: ListAdapterDataSource func objects(for listAdapter: ListAdapter) -> [ListDiffable] { - var builder: [ListDiffable] = [selection] + var builder = [ListDiffable]() + + if client.repo.hasIssuesEnabled { + builder.append(selection) + } if client.issues.count > 0, selection.issuesSelected { builder += client.issues as [ListDiffable] diff --git a/Classes/Repository/SegmentedControlModel+Repository.swift b/Classes/Repository/SegmentedControlModel+Repository.swift index 4e5cb332..f0ce5755 100644 --- a/Classes/Repository/SegmentedControlModel+Repository.swift +++ b/Classes/Repository/SegmentedControlModel+Repository.swift @@ -10,8 +10,14 @@ import Foundation extension SegmentedControlModel { - static func forRepository() -> SegmentedControlModel { - return SegmentedControlModel(items: ["Issues", "Pull Requests"]) + static func forRepository(_ repo: RepositoryLoadable) -> SegmentedControlModel { + var items = [NSLocalizedString("Pull Requests", comment: "")] + + if repo.hasIssuesEnabled { + items.insert(NSLocalizedString("Issues", comment: ""), at: 0) + } + + return SegmentedControlModel(items: items) } var issuesSelected: Bool { diff --git a/Classes/Search/SearchResult.swift b/Classes/Search/SearchResult.swift index 16cd9d99..e6b6dc0f 100644 --- a/Classes/Search/SearchResult.swift +++ b/Classes/Search/SearchResult.swift @@ -18,12 +18,14 @@ class SearchResult: ListDiffable, RepositoryLoadable { let stars: Int let pushedAt: Date? let primaryLanguage: GithubLanguage? + let hasIssuesEnabled: Bool init(repo: SearchReposQuery.Data.Search.Node.AsRepository, containerWidth: CGFloat) { self.id = repo.id self.name = repo.name self.owner = repo.owner.login self.stars = repo.stargazers.totalCount + self.hasIssuesEnabled = repo.hasIssuesEnabled if let description = repo.description { let attributes = [ diff --git a/Freetime.xcodeproj/project.pbxproj b/Freetime.xcodeproj/project.pbxproj index 8b7eaba4..0c1f58aa 100644 --- a/Freetime.xcodeproj/project.pbxproj +++ b/Freetime.xcodeproj/project.pbxproj @@ -1212,16 +1212,16 @@ isa = PBXGroup; children = ( 986B87181F2B875800AAB55C /* GithubClient+Search.swift */, - 986B871A1F2B87DD00AAB55C /* SearchResult.swift */, - 986B871C1F2B8FCD00AAB55C /* SearchViewController.swift */, - 986B871E1F2B96E300AAB55C /* SearchLoadMoreSectionController.swift */, - 986B87201F2B979200AAB55C /* SearchLoadMoreCell.swift */, - 986B87221F2B98AD00AAB55C /* SearchResultSectionController.swift */, - 986B87241F2B990A00AAB55C /* SearchResultCell.swift */, - 986B87261F2BB5EE00AAB55C /* SearchBarSectionController.swift */, 986B87281F2BB68300AAB55C /* SearchBarCell.swift */, - 986B872A1F2C842000AAB55C /* SearchNoResultsSectionController.swift */, + 986B87261F2BB5EE00AAB55C /* SearchBarSectionController.swift */, + 986B87201F2B979200AAB55C /* SearchLoadMoreCell.swift */, + 986B871E1F2B96E300AAB55C /* SearchLoadMoreSectionController.swift */, 986B872C1F2C846700AAB55C /* SearchNoResultsCell.swift */, + 986B872A1F2C842000AAB55C /* SearchNoResultsSectionController.swift */, + 986B871A1F2B87DD00AAB55C /* SearchResult.swift */, + 986B87241F2B990A00AAB55C /* SearchResultCell.swift */, + 986B87221F2B98AD00AAB55C /* SearchResultSectionController.swift */, + 986B871C1F2B8FCD00AAB55C /* SearchViewController.swift */, ); path = Search; sourceTree = ""; @@ -1229,13 +1229,13 @@ 986B872E1F2CA8E800AAB55C /* Repository */ = { isa = PBXGroup; children = ( - 986B872F1F2CA90400AAB55C /* RepositoryViewController.swift */, - 986B87331F2CAE9800AAB55C /* IssueSummaryType.swift */, - 986B87351F2CB28C00AAB55C /* RepositorySummarySectionController.swift */, - 986B87371F2CB29700AAB55C /* RepositorySummaryCell.swift */, - 986B87391F2CE44F00AAB55C /* SegmentedControlModel+Repository.swift */, 986B873B1F2CEB1500AAB55C /* GQL+IssueSummaryType.swift */, + 986B87331F2CAE9800AAB55C /* IssueSummaryType.swift */, 986B873D1F2E1CE400AAB55C /* RepositoryClient.swift */, + 986B87371F2CB29700AAB55C /* RepositorySummaryCell.swift */, + 986B87351F2CB28C00AAB55C /* RepositorySummarySectionController.swift */, + 986B872F1F2CA90400AAB55C /* RepositoryViewController.swift */, + 986B87391F2CE44F00AAB55C /* SegmentedControlModel+Repository.swift */, ); path = Repository; sourceTree = ""; diff --git a/Resources/Info.plist b/Resources/Info.plist index d06a0b76..f5691bba 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -32,7 +32,7 @@ CFBundleVersion - 1191 + 1193 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/gql/API.swift b/gql/API.swift index 8520ab57..d807bb42 100644 --- a/gql/API.swift +++ b/gql/API.swift @@ -2993,6 +2993,7 @@ public final class SearchReposQuery: GraphQLQuery { " __typename" + " id" + " name" + + " hasIssuesEnabled" + " owner {" + " __typename" + " login" + @@ -3073,6 +3074,8 @@ public final class SearchReposQuery: GraphQLQuery { public let id: GraphQLID /// The name of the repository. public let name: String + /// Indicates if the repository has issues feature enabled. + public let hasIssuesEnabled: Bool /// The User owner of the repository. public let owner: Owner /// The description of the repository. @@ -3088,6 +3091,7 @@ public final class SearchReposQuery: GraphQLQuery { __typename = try reader.value(for: Field(responseName: "__typename")) id = try reader.value(for: Field(responseName: "id")) name = try reader.value(for: Field(responseName: "name")) + hasIssuesEnabled = try reader.value(for: Field(responseName: "hasIssuesEnabled")) owner = try reader.value(for: Field(responseName: "owner")) description = try reader.optionalValue(for: Field(responseName: "description")) pushedAt = try reader.optionalValue(for: Field(responseName: "pushedAt")) diff --git a/gql/SearchRepos.graphql b/gql/SearchRepos.graphql index 7731e541..cec575cc 100644 --- a/gql/SearchRepos.graphql +++ b/gql/SearchRepos.graphql @@ -5,6 +5,7 @@ query SearchRepos($search: String!, $before: String) { ... on Repository { id name + hasIssuesEnabled owner { login }