mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Fix race condition in creating new post
This commit is contained in:
parent
3b6c7748e8
commit
9b06eb34a8
@ -20,8 +20,14 @@ struct ContentView: View {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
withAnimation {
|
||||
// Un-set the currently selected post
|
||||
self.model.selectedPost = nil
|
||||
|
||||
// Navigate to the Drafts list
|
||||
self.model.showAllPosts = false
|
||||
self.model.selectedCollection = nil
|
||||
}
|
||||
// Create the new-post managed object
|
||||
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
|
||||
managedPost.createdDate = Date()
|
||||
managedPost.title = ""
|
||||
@ -40,10 +46,10 @@ struct ContentView: View {
|
||||
managedPost.language = languageCode
|
||||
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
|
||||
}
|
||||
|
||||
withAnimation {
|
||||
DispatchQueue.main.async {
|
||||
self.model.showAllPosts = false
|
||||
self.model.selectedCollection = nil
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
// Load the new post in the editor
|
||||
self.model.selectedPost = managedPost
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +114,14 @@ struct WriteFreely_MultiPlatformApp: App {
|
||||
|
||||
private func createNewLocalPost() {
|
||||
withAnimation {
|
||||
// Un-set the currently selected post
|
||||
self.model.selectedPost = nil
|
||||
|
||||
// Navigate to the Drafts list
|
||||
self.model.showAllPosts = false
|
||||
self.model.selectedCollection = nil
|
||||
}
|
||||
// Create the new-post managed object
|
||||
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
|
||||
managedPost.createdDate = Date()
|
||||
managedPost.title = ""
|
||||
@ -135,7 +141,9 @@ struct WriteFreely_MultiPlatformApp: App {
|
||||
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
|
||||
}
|
||||
withAnimation {
|
||||
self.model.selectedPost = managedPost
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
self.model.selectedPost = managedPost
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user