SPB Git

Repository Public

WelcomeScreen.swift 5.6 KB 120 lines swift

1// SP Notes iOS2// File: Features/Account/WelcomeScreen.swift3// Description: First screen of a device without a session: the brand, what the app does, and the passkey sign-in with clear4//              explanations when it cannot proceed. Also the discreet banner shown once a session has ended.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SPNotesCore9import SwiftUI1011struct WelcomeScreen: View {12    @Environment(AppModel.self) private var app13    @State private var isSigningIn = false14    @State private var failure: SignInFailure?1516    var body: some View {17        ScrollView {18            VStack(spacing: 28) {19                Spacer(minLength: 40)20                BrandMark(size: 104)21                VStack(spacing: 10) {22                    Text("SP Notes").font(.largeTitle.bold()).foregroundStyle(Color.spText)23                    Text("Tes notes, partout avec toi, même hors ligne.")24                        .font(.title3).foregroundStyle(Color.spTextSecondary).multilineTextAlignment(.center)25                }26                VStack(spacing: 14) {27                    Button {28                        Task { await signIn() }29                    } label: {30                        HStack(spacing: 10) {31                            if isSigningIn { ProgressView().tint(.white) } else { Image(systemName: "person.badge.key.fill") }32                            Text("Se connecter avec une clé d’accès")33                        }34                    }35                    .buttonStyle(PrimaryButtonStyle())36                    .disabled(isSigningIn)37                    .accessibilityIdentifier("sign-in")3839                    if let message = failure?.message {40                        Label(message, systemImage: "exclamationmark.circle")41                            .font(.subheadline).foregroundStyle(Color.spText)42                            .padding(14)43                            .frame(maxWidth: .infinity, alignment: .leading)44                            .background(Color.spSurface2, in: RoundedRectangle(cornerRadius: 12, style: .continuous))45                            .accessibilityIdentifier("sign-in-error")46                    } else if !app.network.isOnline {47                        Label("Tu es hors ligne : la première connexion demande le réseau.", systemImage: "wifi.slash")48                            .font(.subheadline).foregroundStyle(Color.spTextSecondary)49                    }50                }51                VStack(alignment: .leading, spacing: 16) {52                    promise("iphone", "Sur cet appareil d’abord", "Chaque note est enregistrée ici à l’instant, puis synchronisée avec ton serveur.")53                    promise("wifi.slash", "Hors ligne sans compromis", "Une fois synchronisées, tes notes s’ouvrent, se modifient et se cherchent sans réseau.")54                    promise("key", "Sans mot de passe", "La clé d’accès créée sur note.spboucher.ai te connecte avec Face ID ou Touch ID.")55                }56                .padding(.top, 8)57                Spacer(minLength: 24)58            }59            .padding(.horizontal, 28)60            .frame(maxWidth: 460)61            .frame(maxWidth: .infinity)62        }63        .scrollBounceBehavior(.basedOnSize)64        .background(Color.spBackground.ignoresSafeArea())65    }6667    private func promise(_ symbol: String, _ title: LocalizedStringKey, _ text: LocalizedStringKey) -> some View {68        HStack(alignment: .top, spacing: 14) {69            Image(systemName: symbol).font(.title3).foregroundStyle(Color.accentColor).frame(width: 30).accessibilityHidden(true)70            VStack(alignment: .leading, spacing: 2) {71                Text(title).font(.subheadline.weight(.semibold)).foregroundStyle(Color.spText)72                Text(text).font(.subheadline).foregroundStyle(Color.spTextSecondary)73            }74        }75        .accessibilityElement(children: .combine)76    }7778    private func signIn() async {79        isSigningIn = true80        failure = nil81        defer { isSigningIn = false }82        do { try await app.signIn(); Haptics.success() } catch { failure = SignInFailure(error) }83    }84}8586/// "Session terminée" — the app keeps working locally; this only offers to sign in again.87struct SessionExpiredBanner: View {88    @Environment(AppModel.self) private var app89    @State private var isSigningIn = false90    @State private var failure: SignInFailure?9192    var body: some View {93        VStack(alignment: .leading, spacing: 8) {94            HStack(alignment: .firstTextBaseline, spacing: 10) {95                Image(systemName: "person.crop.circle.badge.exclamationmark").foregroundStyle(Color.spWarning).accessibilityHidden(true)96                Text("Session terminée — reconnecte-toi pour synchroniser")97                    .font(.subheadline).foregroundStyle(Color.spText)98                    .fixedSize(horizontal: false, vertical: true)99            }100            Button {101                Task {102                    isSigningIn = true; failure = nil103                    defer { isSigningIn = false }104                    do { try await app.signIn() } catch { failure = SignInFailure(error) }105                }106            } label: {107                if isSigningIn { ProgressView() } else { Text("Se connecter").font(.subheadline.weight(.semibold)) }108            }109            .buttonStyle(.bordered)110            .disabled(isSigningIn)111            .accessibilityIdentifier("reconnect")112            if let message = failure?.message {113                Text(message).font(.footnote).foregroundStyle(Color.spTextSecondary)114            }115        }116        .frame(maxWidth: .infinity, alignment: .leading)117        .accessibilityIdentifier("session-expired-banner")118    }119}120
Files main
Menu

Theme