diff --git a/Tusker/Screens/Utilities/DiffableTimelineLikeTableViewController.swift b/Tusker/Screens/Utilities/DiffableTimelineLikeTableViewController.swift index 4bff8236..36706b8c 100644 --- a/Tusker/Screens/Utilities/DiffableTimelineLikeTableViewController.swift +++ b/Tusker/Screens/Utilities/DiffableTimelineLikeTableViewController.swift @@ -25,6 +25,7 @@ class DiffableTimelineLikeTableViewController! @@ -113,13 +114,24 @@ class DiffableTimelineLikeTableViewController DispatchWorkItem { + currentLoadingIndicatorWorkItem?.cancel() let workItem = DispatchWorkItem { [weak self] in guard let self = self else { return } var snapshot = self.dataSource.snapshot() - snapshot.appendSections([.loadingIndicator]) - snapshot.appendItems([.loadingIndicator]) - self.dataSource.apply(snapshot, animatingDifferences: false) + var changed = false + if !snapshot.sectionIdentifiers.contains(.loadingIndicator) { + snapshot.appendSections([.loadingIndicator]) + changed = true + } + if changed || !snapshot.itemIdentifiers(inSection: .loadingIndicator).contains(.loadingIndicator) { + snapshot.appendItems([.loadingIndicator], toSection: .loadingIndicator) + changed = true + } + if changed { + self.dataSource.apply(snapshot, animatingDifferences: false) + } } + currentLoadingIndicatorWorkItem = workItem DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(250), execute: workItem) return workItem }