Make network requests in viewWillAppear instead of viewDidLoad
This commit is contained in:
parent
6b7904ed52
commit
36326e4469
|
@ -15,6 +15,8 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
||||||
|
|
||||||
let mastodonController: MastodonController
|
let mastodonController: MastodonController
|
||||||
|
|
||||||
|
private var loaded = false
|
||||||
|
|
||||||
var statuses: [(id: String, state: StatusState)] = []
|
var statuses: [(id: String, state: StatusState)] = []
|
||||||
|
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
|
@ -42,6 +44,15 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
||||||
|
|
||||||
tableView.prefetchDataSource = self
|
tableView.prefetchDataSource = self
|
||||||
|
|
||||||
|
userActivity = UserActivityManager.bookmarksActivity()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
|
if !loaded {
|
||||||
|
loaded = true
|
||||||
|
|
||||||
let request = Client.getBookmarks()
|
let request = Client.getBookmarks()
|
||||||
mastodonController.run(request) { (response) in
|
mastodonController.run(request) { (response) in
|
||||||
guard case let .success(statuses, pagination) = response else { fatalError() }
|
guard case let .success(statuses, pagination) = response else { fatalError() }
|
||||||
|
@ -55,8 +66,7 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
userActivity = UserActivityManager.bookmarksActivity()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Table view data source
|
// MARK: - Table view data source
|
||||||
|
|
|
@ -22,6 +22,8 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
||||||
let excludedTypes: [Pachyderm.Notification.Kind]
|
let excludedTypes: [Pachyderm.Notification.Kind]
|
||||||
let groupTypes = [Notification.Kind.favourite, .reblog, .follow]
|
let groupTypes = [Notification.Kind.favourite, .reblog, .follow]
|
||||||
|
|
||||||
|
private var loaded = false
|
||||||
|
|
||||||
var groups: [NotificationGroup] = []
|
var groups: [NotificationGroup] = []
|
||||||
|
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
|
@ -54,6 +56,13 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
||||||
tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: unknownCell)
|
tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: unknownCell)
|
||||||
|
|
||||||
tableView.prefetchDataSource = self
|
tableView.prefetchDataSource = self
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
|
if !loaded {
|
||||||
|
loaded = true
|
||||||
|
|
||||||
let request = Client.getNotifications(excludeTypes: excludedTypes)
|
let request = Client.getNotifications(excludeTypes: excludedTypes)
|
||||||
mastodonController.run(request) { result in
|
mastodonController.run(request) { result in
|
||||||
|
@ -73,6 +82,7 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Table view data source
|
// MARK: - Table view data source
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,7 @@ class ProfileTableViewController: EnhancedTableViewController {
|
||||||
|
|
||||||
weak var mastodonController: MastodonController!
|
weak var mastodonController: MastodonController!
|
||||||
|
|
||||||
var accountID: String! {
|
var accountID: String!
|
||||||
didSet {
|
|
||||||
if shouldLoadOnAccountIDSet {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.updateAccountUI()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var pinnedStatuses: [(id: String, state: StatusState)] = [] {
|
var pinnedStatuses: [(id: String, state: StatusState)] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -42,8 +34,8 @@ class ProfileTableViewController: EnhancedTableViewController {
|
||||||
var older: RequestRange?
|
var older: RequestRange?
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
|
|
||||||
var shouldLoadOnAccountIDSet = false
|
private var loadingVC: LoadingViewController? = nil
|
||||||
var loadingVC: LoadingViewController? = nil
|
private var loaded = false
|
||||||
|
|
||||||
init(accountID: String?, mastodonController: MastodonController) {
|
init(accountID: String?, mastodonController: MastodonController) {
|
||||||
self.mastodonController = mastodonController
|
self.mastodonController = mastodonController
|
||||||
|
@ -80,7 +72,22 @@ class ProfileTableViewController: EnhancedTableViewController {
|
||||||
|
|
||||||
tableView.prefetchDataSource = self
|
tableView.prefetchDataSource = self
|
||||||
|
|
||||||
if let accountID = accountID {
|
if accountID == nil {
|
||||||
|
loadingVC = LoadingViewController()
|
||||||
|
embedChild(loadingVC!)
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
|
if !loaded, let accountID = accountID {
|
||||||
|
loaded = true
|
||||||
|
loadingVC?.removeViewAndController()
|
||||||
|
loadingVC = nil
|
||||||
|
|
||||||
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
||||||
updateAccountUI()
|
updateAccountUI()
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,18 +113,10 @@ class ProfileTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
loadingVC = LoadingViewController()
|
|
||||||
embedChild(loadingVC!)
|
|
||||||
shouldLoadOnAccountIDSet = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAccountUI() {
|
func updateAccountUI() {
|
||||||
loadingVC?.removeViewAndController()
|
|
||||||
|
|
||||||
updateUIForPreferences()
|
updateUIForPreferences()
|
||||||
|
|
||||||
getStatuses(onlyPinned: true) { (response) in
|
getStatuses(onlyPinned: true) { (response) in
|
||||||
|
|
|
@ -14,6 +14,8 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
var timeline: Timeline!
|
var timeline: Timeline!
|
||||||
weak var mastodonController: MastodonController!
|
weak var mastodonController: MastodonController!
|
||||||
|
|
||||||
|
private var loaded = false
|
||||||
|
|
||||||
var timelineSegments: [[(id: String, state: StatusState)]] = []
|
var timelineSegments: [[(id: String, state: StatusState)]] = []
|
||||||
|
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
|
@ -63,11 +65,18 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
tableView.register(UINib(nibName: "TimelineStatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell")
|
tableView.register(UINib(nibName: "TimelineStatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell")
|
||||||
|
|
||||||
tableView.prefetchDataSource = self
|
tableView.prefetchDataSource = self
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
|
||||||
loadInitialStatuses()
|
loadInitialStatuses()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadInitialStatuses() {
|
func loadInitialStatuses() {
|
||||||
|
guard !loaded else { return }
|
||||||
|
loaded = true
|
||||||
|
|
||||||
let request = Client.getStatuses(timeline: timeline)
|
let request = Client.getStatuses(timeline: timeline)
|
||||||
mastodonController.run(request) { response in
|
mastodonController.run(request) { response in
|
||||||
guard case let .success(statuses, pagination) = response else { fatalError() }
|
guard case let .success(statuses, pagination) = response else { fatalError() }
|
||||||
|
|
Loading…
Reference in New Issue