Change to only resort when sort parameters change
This commit is contained in:
parent
1a74701052
commit
4bb88363e7
|
@ -55,12 +55,19 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||||
return _idToArticleDictionary
|
return _idToArticleDictionary
|
||||||
}
|
}
|
||||||
|
|
||||||
private var sortDirection: Bool {
|
private var sortDirection = AppDefaults.shared.timelineSortDirection {
|
||||||
AppDefaults.shared.timelineSortDirection
|
didSet {
|
||||||
|
if sortDirection != oldValue {
|
||||||
|
sortParametersDidChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var groupByFeed = AppDefaults.shared.timelineGroupByFeed {
|
||||||
|
didSet {
|
||||||
|
if groupByFeed != oldValue {
|
||||||
|
sortParametersDidChange()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var groupByFeed: Bool {
|
|
||||||
AppDefaults.shared.timelineGroupByFeed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -207,10 +214,8 @@ private extension TimelineModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func userDefaultsDidChange(_ note: Notification) {
|
@objc func userDefaultsDidChange(_ note: Notification) {
|
||||||
performBlockAndRestoreSelection {
|
sortDirection = AppDefaults.shared.timelineSortDirection
|
||||||
articles = articles.sortedByDate(sortDirection ? .orderedDescending : .orderedAscending, groupByFeed: groupByFeed)
|
groupByFeed = AppDefaults.shared.timelineGroupByFeed
|
||||||
rebuildTimelineItems()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Timeline Management
|
// MARK: Timeline Management
|
||||||
|
@ -233,6 +238,13 @@ private extension TimelineModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortParametersDidChange() {
|
||||||
|
performBlockAndRestoreSelection {
|
||||||
|
articles = articles.sortedByDate(sortDirection ? .orderedDescending : .orderedAscending, groupByFeed: groupByFeed)
|
||||||
|
rebuildTimelineItems()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func performBlockAndRestoreSelection(_ block: (() -> Void)) {
|
func performBlockAndRestoreSelection(_ block: (() -> Void)) {
|
||||||
// let savedSelection = selectedArticleIDs()
|
// let savedSelection = selectedArticleIDs()
|
||||||
block()
|
block()
|
||||||
|
|
Loading…
Reference in New Issue