Code review fixes, created DestructiveButton

This commit is contained in:
paleksandrs
2022-11-03 10:49:02 +02:00
parent a5c4410d52
commit 246e2b01c7
3 changed files with 45 additions and 53 deletions

View File

@@ -138,7 +138,11 @@ struct UserSessionsOverview: View {
}
}
if viewModel.viewState.otherSessionsViewData.count > 0 {
signOutOtherSessionsButton
DestructiveButton {
viewModel.send(viewAction: .logoutOtherSessions)
} label: {
Label(VectorL10n.manageSessionSignOutOtherSessions, systemImage: "rectangle.portrait.and.arrow.forward.fill")
}
}
} label: {
Image(systemName: "ellipsis")
@@ -209,7 +213,11 @@ struct UserSessionsOverview: View {
private var optionsMenu: some View {
Button { } label: {
Menu {
signOutButton
DestructiveButton {
viewModel.send(viewAction: .logoutOtherSessions)
} label: {
Label(VectorL10n.userOtherSessionMenuSignOutSessions(String(viewModel.viewState.otherSessionsViewData.count)), systemImage: "rectangle.portrait.and.arrow.forward.fill")
}
} label: {
Image(systemName: "ellipsis")
.foregroundColor(theme.colors.secondaryContent)
@@ -218,38 +226,6 @@ struct UserSessionsOverview: View {
}
}
}
@ViewBuilder
private var signOutButton: some View {
let label = Label(VectorL10n.userOtherSessionMenuSignOutSessions(String(viewModel.viewState.otherSessionsViewData.count)), systemImage: "rectangle.portrait.and.arrow.forward.fill")
if #available(iOS 15, *) {
Button(role: .destructive) {
viewModel.send(viewAction: .logoutOtherSessions)
} label: {
label
}
} else {
Button {
viewModel.send(viewAction: .logoutOtherSessions)
} label: {
label
}
}
}
@ViewBuilder
private var signOutOtherSessionsButton: some View {
let label = Label(VectorL10n.manageSessionSignOutOtherSessions, systemImage: "rectangle.portrait.and.arrow.forward.fill")
if #available(iOS 15, *) {
Button(role: .destructive) { viewModel.send(viewAction: .logoutOtherSessions) } label: {
label
}
} else {
Button { viewModel.send(viewAction: .logoutOtherSessions) } label: {
label
}
}
}
}
// MARK: - Previews