Re-enable launch-to-last-draft policy

This commit is contained in:
Angelo Stavrow 2021-09-24 15:29:20 -04:00
parent 3c1e04e3bf
commit ff7e7c3c0e
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 26 additions and 12 deletions

View File

@ -49,7 +49,7 @@ struct ContentView: View {
}
}
#else
PostListView(selectedCollection: nil, showAllPosts: false)
PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts)
#endif
Text("Select a post, or create a new local draft.")

View File

@ -125,6 +125,10 @@ struct PostListView: View {
.overlay(Divider(), alignment: .top)
}
.ignoresSafeArea()
.onAppear {
model.selectedCollection = selectedCollection
model.showAllPosts = showAllPosts
}
#else
PostListFilteredView(
collection: selectedCollection,

View File

@ -34,17 +34,19 @@ struct WriteFreely_MultiPlatformApp: App {
WindowGroup {
ContentView()
.onAppear(perform: {
// if model.editor.showAllPostsFlag {
// DispatchQueue.main.async {
// self.model.selectedCollection = nil
// self.model.showAllPosts = true
// }
// } else {
// DispatchQueue.main.async {
// self.model.selectedCollection = model.editor.fetchSelectedCollectionFromAppStorage()
// self.model.showAllPosts = false
// }
// }
if model.editor.showAllPostsFlag {
DispatchQueue.main.async {
self.model.selectedCollection = nil
self.model.showAllPosts = true
showLastDraftOrCreateNewLocalPost()
}
} else {
DispatchQueue.main.async {
self.model.selectedCollection = model.editor.fetchSelectedCollectionFromAppStorage()
self.model.showAllPosts = false
showLastDraftOrCreateNewLocalPost()
}
}
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// if model.editor.lastDraftURL != nil {
// self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage()
@ -128,6 +130,14 @@ struct WriteFreely_MultiPlatformApp: App {
#endif
}
private func showLastDraftOrCreateNewLocalPost() {
if model.editor.lastDraftURL != nil {
self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage()
} else {
createNewLocalPost()
}
}
private func createNewLocalPost() {
withAnimation {
// Un-set the currently selected post