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")
|
Text(model.account.server == "https://write.as" ? "Anonymous" : "Drafts")
|
||||||
})
|
})
|
||||||
Section(header: Text("Your Blogs")) {
|
Section(header: Text("Your Blogs")) {
|
||||||
ForEach(collections, id: \.alias) { collection in
|
ForEach(collections, id: \.self) { collection in
|
||||||
NavigationLink(
|
NavigationLink(
|
||||||
destination: PostListView(),
|
destination: PostListView(),
|
||||||
isActive: Binding<Bool>(
|
isActive: Binding<Bool>(
|
||||||
@ -77,6 +77,14 @@ struct CollectionListView: View {
|
|||||||
model.account.isLoggedIn ? "\(URL(string: model.account.server)?.host ?? "WriteFreely")" : "WriteFreely"
|
model.account.isLoggedIn ? "\(URL(string: model.account.server)?.host ?? "WriteFreely")" : "WriteFreely"
|
||||||
)
|
)
|
||||||
.listStyle(SidebarListStyle())
|
.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
|
.onChange(of: model.selectedCollection) { collection in
|
||||||
if collection != fetchSelectedCollectionFromAppStorage() {
|
if collection != fetchSelectedCollectionFromAppStorage() {
|
||||||
self.selectedCollectionURL = collection?.objectID.uriRepresentation()
|
self.selectedCollectionURL = collection?.objectID.uriRepresentation()
|
||||||
|
@ -62,6 +62,9 @@ struct PostListFilteredView: View {
|
|||||||
}
|
}
|
||||||
.onAppear(perform: {
|
.onAppear(perform: {
|
||||||
self.postCount = fetchRequest.wrappedValue.count
|
self.postCount = fetchRequest.wrappedValue.count
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
self.model.selectedPost = fetchSelectedPostFromAppStorage()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.onChange(of: fetchRequest.wrappedValue.count, perform: { value in
|
.onChange(of: fetchRequest.wrappedValue.count, perform: { value in
|
||||||
self.postCount = value
|
self.postCount = value
|
||||||
|
@ -36,11 +36,11 @@ struct WriteFreely_MultiPlatformApp: App {
|
|||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView()
|
ContentView()
|
||||||
.onAppear(perform: {
|
.onAppear(perform: {
|
||||||
|
#if os(macOS)
|
||||||
self.model.showAllPosts = showAllPostsFlag
|
self.model.showAllPosts = showAllPostsFlag
|
||||||
self.model.selectedCollection = fetchSelectedCollectionFromAppStorage()
|
self.model.selectedCollection = fetchSelectedCollectionFromAppStorage()
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
self.model.selectedPost = fetchSelectedPostFromAppStorage()
|
||||||
self.model.selectedPost = fetchSelectedPostFromAppStorage()
|
#endif
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.environmentObject(model)
|
.environmentObject(model)
|
||||||
.environment(\.managedObjectContext, LocalStorageManager.persistentContainer.viewContext)
|
.environment(\.managedObjectContext, LocalStorageManager.persistentContainer.viewContext)
|
||||||
|
Loading…
Reference in New Issue
Block a user