Remove anything that attempts to set selected post or last draft

This commit is contained in:
Angelo Stavrow 2020-10-29 12:03:31 -04:00
parent 1170caaf4a
commit bd695b23e6
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
5 changed files with 1 additions and 85 deletions

View File

@ -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

View File

@ -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(

View File

@ -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)
}
}

View File

@ -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

View File

@ -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