mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Set app state in App entrypoint for macOS, in relevant Views for iOS
This commit is contained in:
parent
0b19c8461f
commit
dcb18c86db
@ -48,7 +48,7 @@ struct CollectionListView: View {
|
||||
Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
|
||||
})
|
||||
Section(header: Text("Your Blogs")) {
|
||||
ForEach(collections, id: \.alias) { collection in
|
||||
ForEach(collections, id: \.self) { collection in
|
||||
NavigationLink(
|
||||
destination: PostListView(),
|
||||
isActive: Binding<Bool>(
|
||||
@ -77,6 +77,14 @@ struct CollectionListView: View {
|
||||
model.account.isLoggedIn ? "\(URL(string: model.account.server)?.host ?? "WriteFreely")" : "WriteFreely"
|
||||
)
|
||||
.listStyle(SidebarListStyle())
|
||||
.onAppear(perform: {
|
||||
#if os(iOS)
|
||||
DispatchQueue.main.async {
|
||||
self.model.showAllPosts = showAllPostsFlag
|
||||
self.model.selectedCollection = fetchSelectedCollectionFromAppStorage()
|
||||
}
|
||||
#endif
|
||||
})
|
||||
.onChange(of: model.selectedCollection) { collection in
|
||||
if collection != fetchSelectedCollectionFromAppStorage() {
|
||||
self.selectedCollectionURL = collection?.objectID.uriRepresentation()
|
||||
|
@ -62,6 +62,9 @@ struct PostListFilteredView: View {
|
||||
}
|
||||
.onAppear(perform: {
|
||||
self.postCount = fetchRequest.wrappedValue.count
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
self.model.selectedPost = fetchSelectedPostFromAppStorage()
|
||||
}
|
||||
})
|
||||
.onChange(of: fetchRequest.wrappedValue.count, perform: { value in
|
||||
self.postCount = value
|
||||
|
@ -36,11 +36,11 @@ struct WriteFreely_MultiPlatformApp: App {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
.onAppear(perform: {
|
||||
#if os(macOS)
|
||||
self.model.showAllPosts = showAllPostsFlag
|
||||
self.model.selectedCollection = fetchSelectedCollectionFromAppStorage()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
self.model.selectedPost = fetchSelectedPostFromAppStorage()
|
||||
}
|
||||
#endif
|
||||
})
|
||||
.environmentObject(model)
|
||||
.environment(\.managedObjectContext, LocalStorageManager.persistentContainer.viewContext)
|
||||
|
Loading…
Reference in New Issue
Block a user