aboutsummaryrefslogtreecommitdiff
path: root/foray/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'foray/Scenes')
-rw-r--r--foray/Scenes/ForayTableViewController.swift16
1 files changed, 10 insertions, 6 deletions
diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift
index a29088c..849553c 100644
--- a/foray/Scenes/ForayTableViewController.swift
+++ b/foray/Scenes/ForayTableViewController.swift
@@ -42,21 +42,25 @@ class ForayTableViewController: UITableViewController, Coordinated {
self.refreshControl?.addTarget(self, action: #selector(doRefresh), for: UIControl.Event.valueChanged)
}
- @objc func doRefresh(sender: AnyObject) {
+ @objc
+ func doRefresh(sender: AnyObject) {
reloadApiData()
}
func reloadApiData() {
- presenter.fetch { [weak self] (data: [PenguinItemViewModel]) in
- guard let self = self else { return }
-
- let groups = Dictionary(grouping: data) { $0.year }
+ Task(priority: .medium) { [weak self] in
+ let models = await self?.presenter.fetch()
+
+ guard let self = self,
+ let models = models else { return }
+
+ let groups = Dictionary(grouping: models) { $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()