aboutsummaryrefslogtreecommitdiff
path: root/foray/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'foray/Scenes')
-rw-r--r--foray/Scenes/ForayTableViewController.swift40
1 files changed, 18 insertions, 22 deletions
diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift
index 37ac2e5..ed44139 100644
--- a/foray/Scenes/ForayTableViewController.swift
+++ b/foray/Scenes/ForayTableViewController.swift
@@ -7,8 +7,14 @@
import UIKit
+struct YearSection {
+ var year: Int
+ var items: [PenguinItemViewModel]
+}
+
class ForayTableViewController: UITableViewController, ForayCoordinated {
+ let presenter: PenguinItemPresenter = PenguinItemPresenter()
var coordinator: ForayCoordinator?
// MARK: - Static data TEMP
@@ -39,28 +45,18 @@ class ForayTableViewController: UITableViewController, ForayCoordinated {
}
func reloadApiData() {
- ForayNetworkManager.shared.get(
- url: "https://users.windblume.net/~nick/upload/dummy.json",
- onComplete: { (apiItems: [PenguinItem]) in
- var items = apiItems
-
- // Show items in chronological order within sections
- items.sort { (lhs, rhs) in lhs.releaseDate < rhs.releaseDate }
-
- // Group by year sections
- let groups = Dictionary(grouping: apiItems) { (item) in
- return Calendar.current.component(.year, from: item.releaseDate)
- }
- self.sections = groups.map { (key, values) in
- return YearSection(year: key, items: values)
- }
- // Sort the sections from oldest year to newest
- self.sections.sort { (lhs, rhs) in lhs.year < rhs.year }
-
- self.tableView.reloadData()
- self.refreshControl?.endRefreshing()
- self.coordinator?.hideLoading()
- })
+ presenter.getData(onComplete: { (data: [PenguinItemViewModel]) in
+ let groups = Dictionary(grouping: data) { $0.year }
+ self.sections = groups.map { (key, values) in
+ return YearSection(year: key, items: values)
+ }
+ // Sort the sections from oldest year to newest
+ self.sections.sort { (lhs, rhs) in lhs.year < rhs.year }
+
+ self.tableView.reloadData()
+ self.refreshControl?.endRefreshing()
+ self.coordinator?.hideLoading()
+ })
}
// MARK: - Table view data source