105 lines
4.2 KiB
Swift
105 lines
4.2 KiB
Swift
//
|
|
// Copyright 2023, 2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Please see LICENSE in the repository root for full details.
|
|
//
|
|
|
|
import Combine
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct HomeScreenRecoveryKeyConfirmationBanner: View {
|
|
let requiresExtraAccountSetup: Bool
|
|
var context: HomeScreenViewModel.Context
|
|
|
|
var title: String { requiresExtraAccountSetup ? L10n.bannerSetUpRecoveryTitle : L10n.confirmRecoveryKeyBannerTitle }
|
|
var message: String { requiresExtraAccountSetup ? L10n.bannerSetUpRecoveryContent : L10n.confirmRecoveryKeyBannerMessage }
|
|
var actionTitle: String { requiresExtraAccountSetup ? L10n.bannerSetUpRecoverySubmit : L10n.confirmRecoveryKeyBannerPrimaryButtonTitle }
|
|
var primaryAction: HomeScreenViewAction { requiresExtraAccountSetup ? .setupRecovery : .confirmRecoveryKey }
|
|
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
content
|
|
buttons
|
|
}
|
|
.padding(16)
|
|
.background(Color.compound.bgSubtleSecondary)
|
|
.cornerRadius(14)
|
|
.padding(.horizontal, 16)
|
|
}
|
|
|
|
var content: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack(alignment: .firstTextBaseline, spacing: 16) {
|
|
Text(title)
|
|
.font(.compound.bodyLGSemibold)
|
|
.foregroundColor(.compound.textPrimary)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
if requiresExtraAccountSetup {
|
|
Button {
|
|
context.send(viewAction: .skipRecoveryKeyConfirmation)
|
|
} label: {
|
|
Image(systemName: "xmark")
|
|
.foregroundColor(.compound.iconSecondary)
|
|
.frame(width: 12, height: 12)
|
|
}
|
|
}
|
|
}
|
|
|
|
Text(message)
|
|
.font(.compound.bodyMD)
|
|
.foregroundColor(.compound.textSecondary)
|
|
}
|
|
}
|
|
|
|
var buttons: some View {
|
|
VStack(spacing: 16) {
|
|
Button(actionTitle) {
|
|
context.send(viewAction: primaryAction)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.buttonStyle(.compound(.primary, size: .medium))
|
|
.accessibilityIdentifier(A11yIdentifiers.homeScreen.recoveryKeyConfirmationBannerContinue)
|
|
|
|
if !requiresExtraAccountSetup {
|
|
Button {
|
|
context.send(viewAction: .resetEncryption)
|
|
} label: {
|
|
Text(L10n.confirmRecoveryKeyBannerSecondaryButtonTitle)
|
|
.padding(.vertical, 7)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.compound(.plain, size: .medium))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, TestablePreview {
|
|
static let viewModel = buildViewModel()
|
|
|
|
static var previews: some View {
|
|
HomeScreenRecoveryKeyConfirmationBanner(requiresExtraAccountSetup: true,
|
|
context: viewModel.context)
|
|
.previewDisplayName("Set up recovery")
|
|
HomeScreenRecoveryKeyConfirmationBanner(requiresExtraAccountSetup: false,
|
|
context: viewModel.context)
|
|
.previewDisplayName("Out of sync")
|
|
}
|
|
|
|
static func buildViewModel() -> HomeScreenViewModel {
|
|
let clientProxy = ClientProxyMock(.init(userID: "@alice:example.com",
|
|
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loading))))
|
|
|
|
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
|
|
|
|
return HomeScreenViewModel(userSession: userSession,
|
|
analyticsService: ServiceLocator.shared.analytics,
|
|
appSettings: ServiceLocator.shared.settings,
|
|
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
|
|
userIndicatorController: ServiceLocator.shared.userIndicatorController)
|
|
}
|
|
}
|