mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Remove anything that attempts to set selected post or last draft
This commit is contained in:
parent
1170caaf4a
commit
bd695b23e6
@ -13,19 +13,7 @@ class WriteFreelyModel: ObservableObject {
|
|||||||
@Published var isLoggingIn: Bool = false
|
@Published var isLoggingIn: Bool = false
|
||||||
@Published var isProcessingRequest: Bool = false
|
@Published var isProcessingRequest: Bool = false
|
||||||
@Published var hasNetworkConnection: Bool = true
|
@Published var hasNetworkConnection: Bool = true
|
||||||
@Published var selectedPost: WFAPost? {
|
@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 isPresentingDeleteAlert: Bool = false
|
@Published var isPresentingDeleteAlert: Bool = false
|
||||||
@Published var isPresentingLoginErrorAlert: Bool = false
|
@Published var isPresentingLoginErrorAlert: Bool = false
|
||||||
@Published var isPresentingNetworkErrorAlert: Bool = false
|
@Published var isPresentingNetworkErrorAlert: Bool = false
|
||||||
|
@ -12,30 +12,6 @@ struct ContentView: View {
|
|||||||
Text("Select a post, or create a new local draft.")
|
Text("Select a post, or create a new local draft.")
|
||||||
.foregroundColor(.secondary)
|
.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)
|
.environmentObject(model)
|
||||||
.alert(isPresented: $model.isPresentingDeleteAlert) {
|
.alert(isPresented: $model.isPresentingDeleteAlert) {
|
||||||
Alert(
|
Alert(
|
||||||
|
@ -8,31 +8,5 @@ enum PostAppearance: String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PostEditorModel {
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -128,17 +128,6 @@ struct PostEditorView: View {
|
|||||||
updatingBodyFromServer = true
|
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
|
.onChange(of: selectedCollection, perform: { [selectedCollection] newCollection in
|
||||||
if post.collectionAlias == newCollection?.alias {
|
if post.collectionAlias == newCollection?.alias {
|
||||||
return
|
return
|
||||||
|
@ -41,17 +41,6 @@ struct PostEditorView: View {
|
|||||||
post.status = PostStatus.published.rawValue
|
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: {
|
.onDisappear(perform: {
|
||||||
if post.title.count == 0
|
if post.title.count == 0
|
||||||
&& post.body.count == 0
|
&& post.body.count == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user