Skip to content

Commit

Permalink
NodesEditor: Loading default nodes fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBonus committed Jul 3, 2018
1 parent d362571 commit 45b2020
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Adamant/Stories/NodesEditor/NodesListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class NodesListViewController: FormViewController {
// Properties

private var nodes = [Node]()
private var didResetNodesOnDissapear = false


// MARK: - Lifecycle
Expand Down Expand Up @@ -143,12 +144,17 @@ class NodesListViewController: FormViewController {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

// Top, not presented, and no nodes - reset to default and show alert
if let top = navigationController?.topViewController, top == self && presentedViewController == nil && nodes.count == 0 {
let nodes = nodesSource.defaultNodes
nodesSource.nodes = nodes
nodesSource.saveNodes()
dialogService.showSuccess(withMessage: String.adamantLocalized.nodesList.defaultNodesWasLoaded)
didResetNodesOnDissapear = true
loadDefaultNodes(showAlert: true)
}
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

if navigationController == nil && nodes.count == 0 && !didResetNodesOnDissapear {
loadDefaultNodes(showAlert: true)
}
}

Expand Down Expand Up @@ -298,6 +304,16 @@ extension NodesListViewController {
nodesSource.nodes = nodes
nodesSource.saveNodes()
}

func loadDefaultNodes(showAlert: Bool) {
let nodes = nodesSource.defaultNodes
nodesSource.nodes = nodes
nodesSource.saveNodes()

if showAlert {
dialogService.showSuccess(withMessage: String.adamantLocalized.nodesList.defaultNodesWasLoaded)
}
}
}


Expand Down

0 comments on commit 45b2020

Please sign in to comment.