Implement reload from server on Mac

This commit is contained in:
Angelo Stavrow 2020-08-26 16:41:29 -04:00
parent e3ed0831e6
commit 978192201d
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -3,6 +3,7 @@ import SwiftUI
struct PostListView: View {
@EnvironmentObject var model: WriteFreelyModel
@State var selectedCollection: PostCollection
@State private var isPresentingRefreshWarning = false
#if os(iOS)
@State private var isPresentingSettings = false
@ -78,6 +79,25 @@ struct PostListView: View {
}, label: {
Image(systemName: "square.and.pencil")
})
Button(action: {
isPresentingRefreshWarning = true
}, label: {
Image(systemName: "arrow.clockwise")
})
.alert(isPresented: $isPresentingRefreshWarning, content: {
Alert(
title: Text("Are you sure you want to reload content from the server?"),
message: Text("""
Content on your Mac will be replaced by content from the server and any unpublished changes \
will be lost, except for local drafts.
You can't undo this action.
"""),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Reload From Server"), action: reloadFromServer)
)
})
.disabled(!model.account.isLoggedIn)
}
#endif
}
@ -99,6 +119,15 @@ struct PostListView: View {
}
}
}
private func reloadFromServer() {
DispatchQueue.main.async {
model.store.purgeRemotePosts()
model.collections.clearUserCollection()
model.fetchUserCollections()
model.fetchUserPosts()
}
}
}
struct PostList_Previews: PreviewProvider {