mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-24 04:05:16 +08:00
Fix repo blob loading bug (#1136)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user