mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Move lastDraft-setting logic to ContentView.onAppear handler
This commit is contained in:
parent
44fd09aa33
commit
ce409486d4
@ -61,34 +61,6 @@ class WriteFreelyModel: ObservableObject {
|
||||
self.fetchUserCollections()
|
||||
self.fetchUserPosts()
|
||||
}
|
||||
|
||||
if let lastDraft = self.editor.fetchLastDraft() {
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPost = lastDraft
|
||||
}
|
||||
} else {
|
||||
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
|
||||
managedPost.createdDate = Date()
|
||||
managedPost.title = ""
|
||||
managedPost.body = ""
|
||||
managedPost.status = PostStatus.local.rawValue
|
||||
switch self.preferences.font {
|
||||
case 1:
|
||||
managedPost.appearance = "sans"
|
||||
case 2:
|
||||
managedPost.appearance = "wrap"
|
||||
default:
|
||||
managedPost.appearance = "serif"
|
||||
}
|
||||
if let languageCode = Locale.current.languageCode {
|
||||
managedPost.language = languageCode
|
||||
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
LocalStorageManager().saveContext()
|
||||
self.selectedPost = managedPost
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
monitor.pathUpdateHandler = { path in
|
||||
|
@ -12,6 +12,30 @@ struct ContentView: View {
|
||||
Text("Select a post, or create a new local draft.")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.onAppear(perform: {
|
||||
if let lastDraft = self.model.editor.fetchLastDraft() {
|
||||
model.selectedPost = lastDraft
|
||||
} else {
|
||||
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
|
||||
managedPost.createdDate = Date()
|
||||
managedPost.title = ""
|
||||
managedPost.body = ""
|
||||
managedPost.status = PostStatus.local.rawValue
|
||||
switch self.model.preferences.font {
|
||||
case 1:
|
||||
managedPost.appearance = "sans"
|
||||
case 2:
|
||||
managedPost.appearance = "wrap"
|
||||
default:
|
||||
managedPost.appearance = "serif"
|
||||
}
|
||||
if let languageCode = Locale.current.languageCode {
|
||||
managedPost.language = languageCode
|
||||
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
|
||||
}
|
||||
model.selectedPost = managedPost
|
||||
}
|
||||
})
|
||||
.environmentObject(model)
|
||||
.alert(isPresented: $model.isPresentingDeleteAlert) {
|
||||
Alert(
|
||||
|
Loading…
Reference in New Issue
Block a user