Skip to content

Commit

Permalink
Fix crash in discussions (#264)
Browse files Browse the repository at this point in the history
* Make step field in DiscussionsViewController optional

* Update comment view in VideoStepViewController

* Edit comment
  • Loading branch information
kvld authored Apr 4, 2018
1 parent e12221b commit cd18774
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Stepic/DiscussionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class DiscussionsViewController: UIViewController {

var discussionProxyId: String!
var target: Int!
var step: Step!

// This var is used only for incrementing discussions count
var step: Step?

@IBOutlet weak var tableView: UITableView!

Expand Down Expand Up @@ -725,7 +727,7 @@ extension DiscussionsViewController : WriteCommentDelegate {
discussionIds.loaded.insert(comment.id, at: 0)
discussions.insert(comment, at: 0)
reloadTableData()
step.discussionsCount? += 1
step?.discussionsCount? += 1
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Stepic/VideoStepViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class VideoStepViewController: UIViewController {
let downloadItem = UIBarButtonItem(customView: itemView)
let shareBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(VideoStepViewController.sharePressed(_:)))
nItem.rightBarButtonItems = [shareBarButtonItem, downloadItem]

if let discussionCount = step.discussionsCount {
discussionCountView.commentsCount = discussionCount
}
}

override func didReceiveMemoryWarning() {
Expand Down Expand Up @@ -253,6 +257,7 @@ class VideoStepViewController: UIViewController {
let vc = DiscussionsViewController(nibName: "DiscussionsViewController", bundle: nil)
vc.discussionProxyId = discussionProxyId
vc.target = self.step.id
vc.step = self.step
nController?.pushViewController(vc, animated: true)
} else {
//TODO: Load comments here
Expand Down

0 comments on commit cd18774

Please sign in to comment.