From e1c5823cd6cdc9ec5c407c2768ac2cddbbfde67c Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Mon, 25 Jan 2021 11:53:16 -0500 Subject: [PATCH] Move new-post generation for Mac app to PostEditorModel --- Shared/Navigation/ContentView.swift | 20 +------------------- Shared/PostEditor/PostEditorModel.swift | 2 +- Shared/WriteFreely_MultiPlatformApp.swift | 2 +- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index 17f45ad..09d389f 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -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 diff --git a/Shared/PostEditor/PostEditorModel.swift b/Shared/PostEditor/PostEditorModel.swift index 316ed5b..c07c703 100644 --- a/Shared/PostEditor/PostEditorModel.swift +++ b/Shared/PostEditor/PostEditorModel.swift @@ -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 = "" diff --git a/Shared/WriteFreely_MultiPlatformApp.swift b/Shared/WriteFreely_MultiPlatformApp.swift index 23022a9..25dfe78 100644 --- a/Shared/WriteFreely_MultiPlatformApp.swift +++ b/Shared/WriteFreely_MultiPlatformApp.swift @@ -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()) {