mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Prevent AppStorage updates if there's no change
This commit is contained in:
parent
083d69d143
commit
6beee8cf32
@ -78,14 +78,28 @@ struct CollectionListView: View {
|
||||
)
|
||||
.listStyle(SidebarListStyle())
|
||||
.onChange(of: model.selectedCollection) { collection in
|
||||
if collection != fetchSelectedCollectionFromAppStorage() {
|
||||
self.selectedCollectionURL = collection?.objectID.uriRepresentation()
|
||||
}
|
||||
}
|
||||
.onChange(of: model.showAllPosts) { value in
|
||||
if value != showAllPostsFlag {
|
||||
self.showAllPostsFlag = model.showAllPosts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchSelectedCollectionFromAppStorage() -> WFACollection? {
|
||||
guard let objectURL = selectedCollectionURL else { return nil }
|
||||
let coordinator = LocalStorageManager.persistentContainer.persistentStoreCoordinator
|
||||
guard let managedObjectID = coordinator.managedObjectID(forURIRepresentation: objectURL) else { return nil }
|
||||
guard let object = LocalStorageManager.persistentContainer.viewContext.object(
|
||||
with: managedObjectID
|
||||
) as? WFACollection else { return nil }
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
struct CollectionListView_LoggedOutPreviews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let context = LocalStorageManager.persistentContainer.viewContext
|
||||
|
Loading…
Reference in New Issue
Block a user