Page MenuHomeMusing Studio

No OneTemporary

diff --git a/Shared/PostEditor/PostEditorModel.swift b/Shared/PostEditor/PostEditorModel.swift
index d8a5683..ae08d75 100644
--- a/Shared/PostEditor/PostEditorModel.swift
+++ b/Shared/PostEditor/PostEditorModel.swift
@@ -1,12 +1,32 @@
-import Foundation
+import SwiftUI
import CoreData
enum PostAppearance: String {
case sans = "OpenSans-Regular"
case mono = "Hack"
case serif = "Lora"
}
struct PostEditorModel {
+ @AppStorage("lastDraftURL") private var lastDraftURL: URL?
+ func saveLastDraft(_ post: WFAPost) {
+ self.lastDraftURL = post.status != PostStatus.published.rawValue ? post.objectID.uriRepresentation() : nil
+ }
+
+ func clearLastDraft() {
+ self.lastDraftURL = nil
+ }
+
+ func fetchLastDraftFromUserDefaults() -> WFAPost? {
+ guard let postURL = lastDraftURL else { return nil }
+
+ let coordinator = LocalStorageManager.persistentContainer.persistentStoreCoordinator
+ guard let postManagedObjectID = coordinator.managedObjectID(forURIRepresentation: postURL) else { return nil }
+ guard let post = LocalStorageManager.persistentContainer.viewContext.object(
+ with: postManagedObjectID
+ ) as? WFAPost else { return nil }
+
+ return post
+ }
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Jan 31, 2:59 PM (16 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3145839

Event Timeline