Fix repo blob loading bug (#1136)

This commit is contained in:
Ryan Nystrom
2017-12-02 19:15:40 -05:00
committed by GitHub
parent ab9e0cb9de
commit bd55b07aa8
2 changed files with 25 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ final class RepositoryCodeBlobViewController: UIViewController {
private let client: GithubClient
private let branch: String
private let path: String
private let filename: String
private let repo: RepositoryDetails
private let codeView = CodeView()
private let feedRefresh = FeedRefresh()
@@ -28,13 +29,19 @@ final class RepositoryCodeBlobViewController: UIViewController {
return barButtonItem
}()
init(client: GithubClient, repo: RepositoryDetails, branch: String, path: String) {
init(
client: GithubClient,
repo: RepositoryDetails,
branch: String,
path: String,
filename: String
) {
self.client = client
self.repo = repo
self.branch = branch
self.path = path
self.filename = filename
super.init(nibName: nil, bundle: nil)
self.title = path
}
required init?(coder aDecoder: NSCoder) {
@@ -44,6 +51,8 @@ final class RepositoryCodeBlobViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.configure(title: filename, subtitle: path)
view.backgroundColor = .white
emptyView.isHidden = true
@@ -52,7 +61,7 @@ final class RepositoryCodeBlobViewController: UIViewController {
view.addSubview(codeView)
codeView.refreshControl = feedRefresh.refreshControl
feedRefresh.refreshControl.addTarget(self, action: #selector(RepositoryCodeBlobViewController.onRefresh), for: .valueChanged)
feedRefresh.refreshControl.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
navigationItem.rightBarButtonItem = sharingButton
@@ -87,7 +96,12 @@ final class RepositoryCodeBlobViewController: UIViewController {
}
func fetch() {
client.fetchFile(owner: repo.owner, repo: repo.name, branch: branch, path: path) { [weak self] (result) in
client.fetchFile(
owner: repo.owner,
repo: repo.name,
branch: branch,
path: "\(path)/\(filename)"
) { [weak self] (result) in
self?.feedRefresh.endRefreshing()
switch result {
case .success(let text):

View File

@@ -140,7 +140,13 @@ ListSingleSectionControllerDelegate {
isRoot: false
)
} else {
controller = RepositoryCodeBlobViewController(client: client, repo: repo, branch: branch, path: fullPath)
controller = RepositoryCodeBlobViewController(
client: client,
repo: repo,
branch: branch,
path: fullPath,
filename: file.name
)
}
navigationController?.pushViewController(controller, animated: true)
}