mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Present action sheet to confirm logout
This commit is contained in:
parent
735326891e
commit
5a2b999bcd
@ -2,6 +2,10 @@ import SwiftUI
|
||||
|
||||
struct AccountLogoutView: View {
|
||||
@EnvironmentObject var model: WriteFreelyModel
|
||||
@Environment(\.managedObjectContext) var moc
|
||||
|
||||
@State private var isPresentingLogoutConfirmation: Bool = false
|
||||
@State private var editedPostsWarningString: String = ""
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@ -15,10 +19,35 @@ struct AccountLogoutView: View {
|
||||
Text("Log Out")
|
||||
})
|
||||
}
|
||||
.actionSheet(isPresented: $isPresentingLogoutConfirmation, content: {
|
||||
ActionSheet(
|
||||
title: Text("Log Out?"),
|
||||
message: Text("\(editedPostsWarningString)You won't lose any local posts. Are you sure?"),
|
||||
buttons: [
|
||||
.destructive(Text("Log Out"), action: {
|
||||
model.logout()
|
||||
}),
|
||||
.cancel()
|
||||
]
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func logoutHandler() {
|
||||
model.logout()
|
||||
let request = WFAPost.createFetchRequest()
|
||||
request.predicate = NSPredicate(format: "status == %i", 1)
|
||||
do {
|
||||
let editedPosts = try LocalStorageManager.persistentContainer.viewContext.fetch(request)
|
||||
if editedPosts.count == 1 {
|
||||
editedPostsWarningString = "You'll lose unpublished changes to \(editedPosts.count) edited post. "
|
||||
}
|
||||
if editedPosts.count > 1 {
|
||||
editedPostsWarningString = "You'll lose unpublished changes to \(editedPosts.count) edited posts. "
|
||||
}
|
||||
} catch {
|
||||
print("Error: failed to fetch cached posts")
|
||||
}
|
||||
self.isPresentingLogoutConfirmation = true
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user