From bd695b23e614e9fb04954ac8f933eb7792de8429 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Thu, 29 Oct 2020 12:03:31 -0400 Subject: [PATCH] Remove anything that attempts to set selected post or last draft --- Shared/Models/WriteFreelyModel.swift | 14 +------------ Shared/Navigation/ContentView.swift | 24 ----------------------- Shared/PostEditor/PostEditorModel.swift | 26 ------------------------- iOS/PostEditor/PostEditorView.swift | 11 ----------- macOS/PostEditor/PostEditorView.swift | 11 ----------- 5 files changed, 1 insertion(+), 85 deletions(-) diff --git a/Shared/Models/WriteFreelyModel.swift b/Shared/Models/WriteFreelyModel.swift index ca3764b..89cffea 100644 --- a/Shared/Models/WriteFreelyModel.swift +++ b/Shared/Models/WriteFreelyModel.swift @@ -13,19 +13,7 @@ class WriteFreelyModel: ObservableObject { @Published var isLoggingIn: Bool = false @Published var isProcessingRequest: Bool = false @Published var hasNetworkConnection: Bool = true - @Published var selectedPost: WFAPost? { - didSet { - if let post = selectedPost { - if post.status != PostStatus.published.rawValue { - editor.setLastDraft(post) - } else { - editor.clearLastDraft() - } - } else { - editor.clearLastDraft() - } - } - } + @Published var selectedPost: WFAPost? @Published var isPresentingDeleteAlert: Bool = false @Published var isPresentingLoginErrorAlert: Bool = false @Published var isPresentingNetworkErrorAlert: Bool = false diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index ee33945..bdd6d3e 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -12,30 +12,6 @@ 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( diff --git a/Shared/PostEditor/PostEditorModel.swift b/Shared/PostEditor/PostEditorModel.swift index ca8959f..d8a5683 100644 --- a/Shared/PostEditor/PostEditorModel.swift +++ b/Shared/PostEditor/PostEditorModel.swift @@ -8,31 +8,5 @@ enum PostAppearance: String { } struct PostEditorModel { - let lastDraftObjectURLKey = "lastDraftObjectURLKey" - private(set) var lastDraft: WFAPost? - mutating func setLastDraft(_ post: WFAPost) { - lastDraft = post - UserDefaults.standard.set(post.objectID.uriRepresentation(), forKey: lastDraftObjectURLKey) - } - - mutating func fetchLastDraft() -> WFAPost? { - let coordinator = LocalStorageManager.persistentContainer.persistentStoreCoordinator - - // See if we have a lastDraftObjectURI - guard let lastDraftObjectURI = UserDefaults.standard.url(forKey: lastDraftObjectURLKey) else { return nil } - - // See if we can get an ObjectID from the URI representation - guard let lastDraftObjectID = coordinator.managedObjectID(forURIRepresentation: lastDraftObjectURI) else { - return nil - } - - lastDraft = LocalStorageManager.persistentContainer.viewContext.object(with: lastDraftObjectID) as? WFAPost - return lastDraft - } - - mutating func clearLastDraft() { - lastDraft = nil - UserDefaults.standard.removeObject(forKey: lastDraftObjectURLKey) - } } diff --git a/iOS/PostEditor/PostEditorView.swift b/iOS/PostEditor/PostEditorView.swift index 818d4bd..e2ae217 100644 --- a/iOS/PostEditor/PostEditorView.swift +++ b/iOS/PostEditor/PostEditorView.swift @@ -128,17 +128,6 @@ struct PostEditorView: View { updatingBodyFromServer = true } }) - .onChange(of: post.status, perform: { _ in - if post.status != PostStatus.published.rawValue { - DispatchQueue.main.async { - model.editor.setLastDraft(post) - } - } else { - DispatchQueue.main.async { - model.editor.clearLastDraft() - } - } - }) .onChange(of: selectedCollection, perform: { [selectedCollection] newCollection in if post.collectionAlias == newCollection?.alias { return diff --git a/macOS/PostEditor/PostEditorView.swift b/macOS/PostEditor/PostEditorView.swift index ba7cb53..1b023c2 100644 --- a/macOS/PostEditor/PostEditorView.swift +++ b/macOS/PostEditor/PostEditorView.swift @@ -41,17 +41,6 @@ struct PostEditorView: View { post.status = PostStatus.published.rawValue } }) - .onChange(of: post.status, perform: { _ in - if post.status != PostStatus.published.rawValue { - DispatchQueue.main.async { - model.editor.setLastDraft(post) - } - } else { - DispatchQueue.main.async { - model.editor.clearLastDraft() - } - } - }) .onDisappear(perform: { if post.title.count == 0 && post.body.count == 0