get PRs working again (needs cleanup)

This commit is contained in:
Ryan Nystrom
2017-06-02 23:28:51 -04:00
parent 2498e1e76d
commit b392a4159e
5 changed files with 48 additions and 11 deletions

View File

@@ -19,14 +19,27 @@ extension GithubClient {
width: CGFloat,
completion: @escaping ([IGListDiffable]) -> ()
) {
let query = IssueQuery(owner: owner, repo: repo, number: number)
apollo.fetch(query: query) { (result, error) in
if let issue = result?.data?.repository?.issue {
createViewModels(issue: issue, width: width) { results in
completion(results)
if pullRequest {
let query = PullRequestQuery(owner: owner, repo: repo, number: number)
apollo.fetch(query: query) { (result, error) in
if let pullRequest = result?.data?.repository?.pullRequest {
createViewModels(pullRequest: pullRequest, width: width) { results in
completion(results)
}
} else {
completion([])
}
}
} else {
let query = IssueQuery(owner: owner, repo: repo, number: number)
apollo.fetch(query: query) { (result, error) in
if let issue = result?.data?.repository?.issue {
createViewModels(issue: issue, width: width) { results in
completion(results)
}
} else {
completion([])
}
} else {
completion([])
}
}
}

View File

@@ -55,6 +55,26 @@ func createViewModels(
}
}
func createViewModels(
pullRequest: PullRequestQuery.Data.Repository.PullRequest,
width: CGFloat,
completion: @escaping ([IGListDiffable]) -> ()
) {
DispatchQueue.global().async {
let result = createViewModels(
number: pullRequest.number,
title: pullRequest.title,
labelableFields: pullRequest.fragments.labelableFields,
commentFields: pullRequest.fragments.commentFields,
reactionFields: pullRequest.fragments.reactionFields,
width: width
)
DispatchQueue.main.async {
completion(result)
}
}
}
func titleStringSizing(title: String, width: CGFloat) -> NSAttributedStringSizing {
let attributedString = NSAttributedString(
string: title,

View File

@@ -15,6 +15,7 @@ final class IssuesViewController: UIViewController, IGListAdapterDataSource, Fee
fileprivate let owner: String
fileprivate let repo: String
fileprivate let number: Int
fileprivate let pullRequest: Bool
fileprivate var issue: IssueQuery.Data.Repository.Issue?
fileprivate var models = [IGListDiffable]()
lazy fileprivate var feed: Feed = { Feed(viewController: self, delegate: self) }()
@@ -23,12 +24,14 @@ final class IssuesViewController: UIViewController, IGListAdapterDataSource, Fee
client: GithubClient,
owner: String,
repo: String,
number: Int
number: Int,
pullRequest: Bool
) {
self.client = client
self.owner = owner
self.repo = repo
self.number = number
self.pullRequest = pullRequest
super.init(nibName: nil, bundle: nil)
title = "\(owner)/\(repo)#\(number)"
}
@@ -70,7 +73,7 @@ final class IssuesViewController: UIViewController, IGListAdapterDataSource, Fee
owner: owner,
repo: repo,
number: number,
pullRequest: false,
pullRequest: pullRequest,
width: view.bounds.width
) { results in
self.models = results

View File

@@ -40,7 +40,8 @@ final class RepoNotificationsSectionController: IGListGenericSectionController<N
client: client,
owner: object.owner,
repo: object.repo,
number: object.number
number: object.number,
pullRequest: object.type == .pullRequest
)
viewController?.navigationController?.pushViewController(controller, animated: true)
}

View File

@@ -313,10 +313,10 @@
isa = PBXGroup;
children = (
292FCAC81EDFCC510026635E /* Comments */,
2963A9381EE258C20066509C /* GithubClient+Issues.swift */,
292FCAE61EDFCC510026635E /* IssueEvent.swift */,
292FCAE81EDFCC510026635E /* IssueState.swift */,
292FCAE91EDFCC510026635E /* IssuesViewController.swift */,
2963A9381EE258C20066509C /* GithubClient+Issues.swift */,
292FCAEA1EDFCC510026635E /* IssueViewModels.swift */,
292FCAEC1EDFCC510026635E /* Labels */,
292FCAF31EDFCC510026635E /* Title */,