On launch, either restore lastDraft or go to new blank post

This commit is contained in:
Angelo Stavrow 2020-09-23 16:15:08 -04:00
parent 9daf553391
commit bc77fa14af
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 28 additions and 2 deletions

View File

@ -57,6 +57,32 @@ class WriteFreelyModel: ObservableObject {
self.fetchUserCollections()
self.fetchUserPosts()
}
if let lastDraft = self.editor.fetchLastDraft() {
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

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>