Move new-post generation for Mac app to PostEditorModel

This commit is contained in:
Angelo Stavrow 2021-01-25 11:53:16 -05:00
parent 20f12fa7cc
commit e1c5823cd6
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 3 additions and 21 deletions

View File

@ -28,25 +28,7 @@ struct ContentView: View {
self.model.selectedCollection = nil
}
// Create the new-post managed object
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
managedPost.createdDate = Date()
managedPost.title = ""
managedPost.body = ""
managedPost.status = PostStatus.local.rawValue
managedPost.collectionAlias = nil
switch 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
}
let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font)
withAnimation {
DispatchQueue.main.asyncAfter(deadline: .now()) {
// Load the new post in the editor

View File

@ -33,7 +33,7 @@ struct PostEditorModel {
return post
}
func generateNewLocalPost(withAppearance appearance: Int) -> WFAPost {
func generateNewLocalPost(withFont appearance: Int) -> WFAPost {
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
managedPost.createdDate = Date()
managedPost.title = ""

View File

@ -133,7 +133,7 @@ struct WriteFreely_MultiPlatformApp: App {
self.model.selectedCollection = nil
}
// Create the new-post managed object
let managedPost = model.editor.generateNewLocalPost(withAppearance: model.preferences.font)
let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font)
withAnimation {
// Set it as the selectedPost
DispatchQueue.main.asyncAfter(deadline: .now()) {