Session Manager: Single session logout

This commit is contained in:
Doug
2022-10-05 12:35:32 +01:00
committed by Doug
parent da2b1cad4f
commit 3c34092a6a
13 changed files with 251 additions and 20 deletions
@@ -45,6 +45,8 @@ final class UserSessionOverviewCoordinator: Coordinator, Presentable {
viewModel = UserSessionOverviewViewModel(sessionInfo: parameters.sessionInfo, service: service)
hostingController = VectorHostingController(rootView: UserSessionOverview(viewModel: viewModel.context))
hostingController.vc_setLargeTitleDisplayMode(.never)
hostingController.vc_removeBackTitle()
indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: hostingController)
}
@@ -55,12 +57,17 @@ final class UserSessionOverviewCoordinator: Coordinator, Presentable {
MXLog.debug("[UserSessionOverviewCoordinator] did start.")
viewModel.completion = { [weak self] result in
guard let self = self else { return }
MXLog.debug("[UserSessionOverviewCoordinator] UserSessionOverviewViewModel did complete with result: \(result).")
switch result {
case .verifyCurrentSession:
break // TODO:
case let .showSessionDetails(sessionInfo: sessionInfo):
self.completion?(.openSessionDetails(sessionInfo: sessionInfo))
case let .renameSession(sessionInfo):
self.completion?(.renameSession(sessionInfo))
case let .logoutOfSession(sessionInfo):
self.completion?(.logoutOfSession(sessionInfo))
}
}
}
@@ -20,6 +20,8 @@ import Foundation
enum UserSessionOverviewCoordinatorResult {
case openSessionDetails(sessionInfo: UserSessionInfo)
case renameSession(UserSessionInfo)
case logoutOfSession(UserSessionInfo)
}
// MARK: View model
@@ -27,6 +29,8 @@ enum UserSessionOverviewCoordinatorResult {
enum UserSessionOverviewViewModelResult: Equatable {
case showSessionDetails(sessionInfo: UserSessionInfo)
case verifyCurrentSession
case renameSession(UserSessionInfo)
case logoutOfSession(UserSessionInfo)
}
// MARK: View
@@ -43,4 +47,6 @@ enum UserSessionOverviewViewAction {
case verifyCurrentSession
case viewSessionDetails
case togglePushNotifications
case renameSession
case logoutOfSession
}
@@ -69,6 +69,10 @@ class UserSessionOverviewViewModel: UserSessionOverviewViewModelType, UserSessio
case .togglePushNotifications:
self.state.showLoadingIndicator = true
service.togglePushNotifications()
case .renameSession:
completion?(.renameSession(sessionInfo))
case .logoutOfSession:
completion?(.logoutOfSession(sessionInfo))
}
}
}
@@ -31,9 +31,11 @@ struct UserSessionOverview: View {
})
.padding(16)
SwiftUI.Section {
UserSessionOverviewDisclosureCell(title: VectorL10n.userSessionOverviewSessionDetailsButtonTitle, onBackgroundTap: {
UserSessionOverviewItem(title: VectorL10n.userSessionOverviewSessionDetailsButtonTitle,
showsChevron: true) {
viewModel.send(viewAction: .viewSessionDetails)
})
}
if let enabled = viewModel.viewState.isPusherEnabled {
UserSessionOverviewToggleCell(title: VectorL10n.userSessionPushNotifications,
message: VectorL10n.userSessionPushNotificationsMessage,
@@ -42,6 +44,13 @@ struct UserSessionOverview: View {
}
}
}
SwiftUI.Section {
UserSessionOverviewItem(title: VectorL10n.manageSessionSignOut,
isDestructive: true) {
viewModel.send(viewAction: .logoutOfSession)
}
}
}
.background(theme.colors.system.ignoresSafeArea())
.frame(maxHeight: .infinity)
@@ -49,6 +58,19 @@ struct UserSessionOverview: View {
.navigationTitle(viewModel.viewState.isCurrentSession ?
VectorL10n.userSessionOverviewCurrentSessionTitle :
VectorL10n.userSessionOverviewSessionTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Menu {
Button { viewModel.send(viewAction: .renameSession) } label: {
Label(VectorL10n.manageSessionRename, systemImage: "pencil")
}
} label: {
Image(systemName: "ellipsis.circle")
}
}
}
.accentColor(theme.colors.accent)
}
}
@@ -16,10 +16,12 @@
import SwiftUI
struct UserSessionOverviewDisclosureCell: View {
struct UserSessionOverviewItem: View {
@Environment(\.theme) private var theme: ThemeSwiftUI
let title: String
var showsChevron = false
var isDestructive = false
var onBackgroundTap: (() -> Void)?
var body: some View {
@@ -29,9 +31,12 @@ struct UserSessionOverviewDisclosureCell: View {
HStack {
Text(title)
.font(theme.fonts.body)
.foregroundColor(theme.colors.primaryContent)
.foregroundColor(textColor)
.frame(maxWidth: .infinity, alignment: .leading)
Image(Asset.Images.chevron.name)
if showsChevron {
Image(Asset.Images.chevron.name)
}
}
.padding(.vertical, 15)
.padding(.horizontal, 16)
@@ -40,17 +45,27 @@ struct UserSessionOverviewDisclosureCell: View {
.background(theme.colors.background)
}
}
var textColor: Color {
isDestructive ? theme.colors.alert : theme.colors.primaryContent
}
}
struct UserSessionOverviewDisclosureCell_Previews: PreviewProvider {
struct UserSessionOverviewButtonCell_Previews: PreviewProvider {
static var buttons: some View {
NavigationView {
ScrollView {
UserSessionOverviewItem(title: "Nav item", showsChevron: true)
UserSessionOverviewItem(title: "Button")
UserSessionOverviewItem(title: "Button", isDestructive: true)
}
}
}
static var previews: some View {
Group {
UserSessionOverviewDisclosureCell(title: "Title")
.theme(.light)
.preferredColorScheme(.light)
UserSessionOverviewDisclosureCell(title: "Title")
.theme(.dark)
.preferredColorScheme(.dark)
buttons.theme(.light).preferredColorScheme(.light)
buttons.theme(.dark).preferredColorScheme(.dark)
}
}
}