2026-04-18 01:05:22 +02:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
struct WatchRootView: View {
|
|
|
|
|
@ObservedObject var model: AppViewModel
|
2026-04-19 16:29:13 +02:00
|
|
|
@State private var showsQueue = false
|
2026-04-18 01:05:22 +02:00
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
Group {
|
|
|
|
|
if model.session == nil {
|
|
|
|
|
WatchPairingView(model: model)
|
2026-04-19 21:50:03 +02:00
|
|
|
} else if showsQueue {
|
|
|
|
|
WatchQueueView(model: model)
|
2026-04-18 01:05:22 +02:00
|
|
|
} else {
|
2026-04-19 21:50:03 +02:00
|
|
|
WatchHomeView(model: model)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.background(Color.black.ignoresSafeArea())
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
.tint(IdP.tint)
|
2026-04-19 21:50:03 +02:00
|
|
|
.preferredColorScheme(.dark)
|
2026-04-19 16:29:13 +02:00
|
|
|
.onOpenURL { url in
|
|
|
|
|
if (url.host ?? url.lastPathComponent).lowercased() == "inbox" {
|
|
|
|
|
showsQueue = true
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct WatchPairingView: View {
|
|
|
|
|
@ObservedObject var model: AppViewModel
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
2026-04-19 21:50:03 +02:00
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
|
|
WatchBadge(title: "PAIR · STEP 1", tone: .accent)
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
Text("Link your watch")
|
2026-04-19 21:50:03 +02:00
|
|
|
.font(.system(size: 15, weight: .semibold))
|
2026-04-19 16:29:13 +02:00
|
|
|
.foregroundStyle(.white)
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
Text("Use the shared demo passport so approvals stay visible on your wrist.")
|
|
|
|
|
.font(.footnote)
|
2026-04-19 21:50:03 +02:00
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
|
|
|
|
|
|
|
|
Spacer(minLength: 4)
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
Button("Use demo payload") {
|
|
|
|
|
Task {
|
|
|
|
|
await model.signInWithSuggestedPayload()
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
.buttonStyle(PrimaryActionStyle())
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
|
.padding(8)
|
2026-04-19 16:29:13 +02:00
|
|
|
.navigationTitle("idp.global")
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private struct WatchHomeView: View {
|
|
|
|
|
@ObservedObject var model: AppViewModel
|
2026-04-18 01:05:22 +02:00
|
|
|
|
|
|
|
|
var body: some View {
|
2026-04-19 16:29:13 +02:00
|
|
|
Group {
|
|
|
|
|
if let request = model.pendingRequests.first {
|
|
|
|
|
WatchApprovalView(model: model, requestID: request.id)
|
|
|
|
|
} else {
|
|
|
|
|
WatchQueueView(model: model)
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
struct WatchApprovalView: View {
|
2026-04-18 01:05:22 +02:00
|
|
|
@ObservedObject var model: AppViewModel
|
2026-04-19 16:29:13 +02:00
|
|
|
let requestID: ApprovalRequest.ID
|
|
|
|
|
|
|
|
|
|
private var request: ApprovalRequest? {
|
|
|
|
|
model.requests.first(where: { $0.id == requestID })
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
@ViewBuilder
|
|
|
|
|
private func signInPrompt(handle: String) -> some View {
|
|
|
|
|
var attributed = AttributedString("Sign in as \(handle)?")
|
|
|
|
|
attributed.font = .system(size: 15, weight: .semibold)
|
|
|
|
|
attributed.foregroundColor = .white
|
|
|
|
|
if let range = attributed.range(of: handle) {
|
|
|
|
|
attributed[range].foregroundColor = IdP.tint
|
|
|
|
|
}
|
|
|
|
|
return Text(attributed)
|
|
|
|
|
.lineLimit(2)
|
|
|
|
|
.minimumScaleFactor(0.8)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 01:05:22 +02:00
|
|
|
var body: some View {
|
2026-04-19 16:29:13 +02:00
|
|
|
Group {
|
|
|
|
|
if let request {
|
2026-04-19 21:50:03 +02:00
|
|
|
VStack(alignment: .leading, spacing: 5) {
|
|
|
|
|
HStack(spacing: 5) {
|
|
|
|
|
MonogramAvatar(
|
|
|
|
|
title: request.watchAppDisplayName,
|
|
|
|
|
size: 18,
|
|
|
|
|
tint: BrandTint.color(for: request.watchAppDisplayName)
|
|
|
|
|
)
|
|
|
|
|
Text(request.watchAppDisplayName)
|
|
|
|
|
.font(.system(size: 11, weight: .medium))
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
.lineLimit(1)
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
signInPrompt(handle: model.profile?.handle ?? "@you")
|
2026-04-18 06:11:07 +02:00
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
HStack(spacing: 3) {
|
|
|
|
|
Image(systemName: "location.fill")
|
|
|
|
|
.font(.system(size: 8))
|
|
|
|
|
Text("\(request.watchLocationSummary) · now")
|
|
|
|
|
}
|
|
|
|
|
.font(.system(size: 10))
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
|
|
|
|
|
Spacer(minLength: 4)
|
2026-04-18 06:11:07 +02:00
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
GeometryReader { geo in
|
|
|
|
|
HStack(spacing: 5) {
|
2026-04-19 16:29:13 +02:00
|
|
|
Button {
|
|
|
|
|
Task {
|
|
|
|
|
Haptics.warning()
|
|
|
|
|
await model.reject(request)
|
|
|
|
|
}
|
|
|
|
|
} label: {
|
|
|
|
|
Image(systemName: "xmark")
|
2026-04-19 21:50:03 +02:00
|
|
|
.font(.footnote.weight(.semibold))
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
.buttonStyle(SecondaryActionStyle())
|
2026-04-19 21:50:03 +02:00
|
|
|
.frame(width: (geo.size.width - 5) / 3)
|
2026-04-18 06:11:07 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
WatchHoldToApproveButton(isBusy: model.activeRequestID == request.id) {
|
|
|
|
|
await model.approve(request)
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.frame(height: 36)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
|
.padding(.horizontal, 8)
|
|
|
|
|
.padding(.top, 4)
|
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2026-04-19 16:29:13 +02:00
|
|
|
.toolbar {
|
|
|
|
|
ToolbarItem(placement: .bottomBar) {
|
|
|
|
|
NavigationLink("Queue") {
|
|
|
|
|
WatchQueueView(model: model)
|
|
|
|
|
}
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
} else {
|
|
|
|
|
WatchEmptyState(
|
|
|
|
|
title: "No request",
|
|
|
|
|
message: "This sign-in is no longer pending.",
|
|
|
|
|
systemImage: "checkmark.circle"
|
|
|
|
|
)
|
2026-04-18 06:11:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private struct WatchQueueView: View {
|
2026-04-18 01:05:22 +02:00
|
|
|
@ObservedObject var model: AppViewModel
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
2026-04-19 21:50:03 +02:00
|
|
|
ScrollView {
|
|
|
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
|
|
|
Text("INBOX · \(model.requests.count)")
|
|
|
|
|
.font(.system(size: 10, weight: .bold))
|
|
|
|
|
.tracking(0.6)
|
|
|
|
|
.foregroundStyle(IdP.tint)
|
|
|
|
|
.padding(.horizontal, 4)
|
|
|
|
|
.padding(.top, 2)
|
|
|
|
|
|
|
|
|
|
if model.requests.isEmpty {
|
|
|
|
|
WatchEmptyState(
|
|
|
|
|
title: "All clear",
|
|
|
|
|
message: "New sign-in requests appear here.",
|
|
|
|
|
systemImage: "shield"
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
ForEach(model.requests) { request in
|
|
|
|
|
NavigationLink {
|
|
|
|
|
WatchRequestDetailView(model: model, requestID: request.id)
|
|
|
|
|
} label: {
|
|
|
|
|
WatchQueueRow(request: request)
|
|
|
|
|
}
|
|
|
|
|
.buttonStyle(.plain)
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.padding(.horizontal, 6)
|
|
|
|
|
.padding(.bottom, 8)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.scrollIndicators(.hidden)
|
2026-04-19 16:29:13 +02:00
|
|
|
.navigationTitle("Queue")
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private struct WatchQueueRow: View {
|
2026-04-18 01:05:22 +02:00
|
|
|
let request: ApprovalRequest
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
2026-04-19 21:50:03 +02:00
|
|
|
HStack(spacing: 6) {
|
|
|
|
|
MonogramAvatar(
|
|
|
|
|
title: request.watchAppDisplayName,
|
|
|
|
|
size: 20,
|
|
|
|
|
tint: BrandTint.color(for: request.watchAppDisplayName)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2026-04-19 16:29:13 +02:00
|
|
|
Text(request.watchAppDisplayName)
|
2026-04-19 21:50:03 +02:00
|
|
|
.font(.system(size: 11, weight: .semibold))
|
2026-04-18 06:11:07 +02:00
|
|
|
.foregroundStyle(.white)
|
2026-04-19 21:50:03 +02:00
|
|
|
.lineLimit(1)
|
|
|
|
|
Text(request.kind.title)
|
|
|
|
|
.font(.system(size: 9))
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
.lineLimit(1)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
|
|
|
|
|
Spacer(minLength: 4)
|
|
|
|
|
|
|
|
|
|
Text(relativeTime)
|
|
|
|
|
.font(.system(size: 9))
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.padding(6)
|
|
|
|
|
.overlay(
|
|
|
|
|
RoundedRectangle(cornerRadius: 7, style: .continuous)
|
|
|
|
|
.stroke(Color.white.opacity(0.12), lineWidth: 1)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var relativeTime: String {
|
|
|
|
|
let seconds = Int(Date.now.timeIntervalSince(request.createdAt))
|
|
|
|
|
if seconds < 60 { return "now" }
|
|
|
|
|
if seconds < 3600 { return "\(seconds / 60)m" }
|
|
|
|
|
if seconds < 86_400 { return "\(seconds / 3600)h" }
|
|
|
|
|
return "\(seconds / 86_400)d"
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct WatchRequestDetailView: View {
|
|
|
|
|
@ObservedObject var model: AppViewModel
|
|
|
|
|
let requestID: ApprovalRequest.ID
|
|
|
|
|
|
|
|
|
|
private var request: ApprovalRequest? {
|
|
|
|
|
model.requests.first(where: { $0.id == requestID })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
Group {
|
|
|
|
|
if let request {
|
|
|
|
|
ScrollView {
|
2026-04-19 21:50:03 +02:00
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
2026-04-19 16:29:13 +02:00
|
|
|
RequestHeroCard(request: request, handle: model.profile?.handle ?? "@you")
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
Text(request.watchTrustExplanation)
|
2026-04-18 01:05:22 +02:00
|
|
|
.font(.footnote)
|
2026-04-19 21:50:03 +02:00
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
2026-04-18 01:05:22 +02:00
|
|
|
|
|
|
|
|
if request.status == .pending {
|
2026-04-19 16:29:13 +02:00
|
|
|
WatchHoldToApproveButton(isBusy: model.activeRequestID == request.id) {
|
|
|
|
|
await model.approve(request)
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
Button("Deny") {
|
|
|
|
|
Task {
|
|
|
|
|
Haptics.warning()
|
|
|
|
|
await model.reject(request)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
.buttonStyle(SecondaryActionStyle())
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.padding(8)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-04-19 16:29:13 +02:00
|
|
|
WatchEmptyState(
|
|
|
|
|
title: "No request",
|
|
|
|
|
message: "This sign-in is no longer pending.",
|
|
|
|
|
systemImage: "shield"
|
|
|
|
|
)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
.navigationTitle("Details")
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct WatchHoldToApproveButton: View {
|
|
|
|
|
var isBusy = false
|
|
|
|
|
let action: () async -> Void
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
@State private var progress: CGFloat = 0
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
ZStack {
|
|
|
|
|
RoundedRectangle(cornerRadius: IdP.controlRadius, style: .continuous)
|
2026-04-19 21:50:03 +02:00
|
|
|
.fill(isBusy ? Color.white.opacity(0.18) : Color.idpPrimary)
|
2026-04-19 16:29:13 +02:00
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
if isBusy {
|
|
|
|
|
Text("Working…")
|
|
|
|
|
.font(.footnote.weight(.semibold))
|
|
|
|
|
.foregroundStyle(.white)
|
|
|
|
|
} else {
|
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
|
Image(systemName: "checkmark")
|
|
|
|
|
Text("Approve")
|
|
|
|
|
}
|
|
|
|
|
.font(.footnote.weight(.semibold))
|
|
|
|
|
.foregroundStyle(Color.idpPrimaryForeground)
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
RoundedRectangle(cornerRadius: IdP.controlRadius, style: .continuous)
|
|
|
|
|
.trim(from: 0, to: progress)
|
2026-04-19 21:50:03 +02:00
|
|
|
.stroke(IdP.tint, style: StrokeStyle(lineWidth: 2, lineCap: .round))
|
2026-04-19 16:29:13 +02:00
|
|
|
.rotationEffect(.degrees(-90))
|
2026-04-19 21:50:03 +02:00
|
|
|
.padding(1.5)
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.frame(height: 36)
|
2026-04-19 16:29:13 +02:00
|
|
|
.contentShape(RoundedRectangle(cornerRadius: IdP.controlRadius, style: .continuous))
|
|
|
|
|
.onLongPressGesture(minimumDuration: 0.6, maximumDistance: 18, pressing: updateProgress) {
|
|
|
|
|
guard !isBusy else { return }
|
|
|
|
|
Task {
|
|
|
|
|
Haptics.success()
|
|
|
|
|
await action()
|
|
|
|
|
progress = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.watchPrimaryActionGesture()
|
|
|
|
|
.accessibilityAddTraits(.isButton)
|
|
|
|
|
.accessibilityHint("Press and hold to approve the sign-in request.")
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private func updateProgress(_ isPressing: Bool) {
|
|
|
|
|
guard !isBusy else { return }
|
|
|
|
|
withAnimation(.linear(duration: isPressing ? 0.6 : 0.15)) {
|
|
|
|
|
progress = isPressing ? 1 : 0
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private extension View {
|
|
|
|
|
@ViewBuilder
|
|
|
|
|
func watchPrimaryActionGesture() -> some View {
|
|
|
|
|
if #available(watchOS 11.0, *) {
|
|
|
|
|
self.handGestureShortcut(.primaryAction)
|
|
|
|
|
} else {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private extension ApprovalRequest {
|
|
|
|
|
var watchAppDisplayName: String {
|
|
|
|
|
source.replacingOccurrences(of: "auth.", with: "")
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
var watchTrustExplanation: String {
|
|
|
|
|
risk == .elevated
|
|
|
|
|
? "This request needs a higher-assurance proof before it can continue."
|
|
|
|
|
: "This request matches a familiar device and sign-in pattern."
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
var watchLocationSummary: String {
|
2026-04-19 21:50:03 +02:00
|
|
|
"Berlin"
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-18 01:05:22 +02:00
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private struct WatchEmptyState: View {
|
|
|
|
|
let title: String
|
|
|
|
|
let message: String
|
|
|
|
|
let systemImage: String
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
2026-04-19 21:50:03 +02:00
|
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
|
|
|
Image(systemName: systemImage)
|
|
|
|
|
.font(.title3)
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
Text(title)
|
|
|
|
|
.font(.system(size: 13, weight: .semibold))
|
|
|
|
|
.foregroundStyle(.white)
|
2026-04-19 16:29:13 +02:00
|
|
|
Text(message)
|
2026-04-19 21:50:03 +02:00
|
|
|
.font(.footnote)
|
|
|
|
|
.foregroundStyle(Color.idpMutedForeground)
|
|
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
2026-04-19 21:50:03 +02:00
|
|
|
.padding(8)
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
#Preview("Watch Approval") {
|
2026-04-19 16:29:13 +02:00
|
|
|
WatchApprovalPreviewHost()
|
2026-04-19 21:50:03 +02:00
|
|
|
.preferredColorScheme(.dark)
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
#Preview("Watch Queue") {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
WatchQueuePreviewHost()
|
|
|
|
|
}
|
|
|
|
|
.preferredColorScheme(.dark)
|
2026-04-19 16:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
|
private struct WatchApprovalPreviewHost: View {
|
|
|
|
|
@State private var model = WatchPreviewFixtures.model()
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
WatchApprovalView(model: model, requestID: WatchPreviewFixtures.requests[0].id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 21:50:03 +02:00
|
|
|
@MainActor
|
|
|
|
|
private struct WatchQueuePreviewHost: View {
|
|
|
|
|
@State private var model = WatchPreviewFixtures.model()
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
WatchQueueView(model: model)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private enum WatchPreviewFixtures {
|
|
|
|
|
static let profile = MemberProfile(
|
|
|
|
|
name: "Jurgen Meyer",
|
|
|
|
|
handle: "@jurgen",
|
|
|
|
|
organization: "idp.global",
|
|
|
|
|
deviceCount: 3,
|
|
|
|
|
recoverySummary: "Recovery kit healthy."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
static let session = AuthSession(
|
|
|
|
|
deviceName: "Apple Watch",
|
|
|
|
|
originHost: "github.com",
|
|
|
|
|
pairedAt: .now.addingTimeInterval(-60 * 45),
|
|
|
|
|
tokenPreview: "berlin",
|
|
|
|
|
pairingCode: "idp.global://pair?token=swiftapp-demo-berlin&origin=github.com&device=Apple%20Watch",
|
|
|
|
|
pairingTransport: .preview
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
static let requests: [ApprovalRequest] = [
|
|
|
|
|
ApprovalRequest(
|
|
|
|
|
title: "GitHub sign-in",
|
|
|
|
|
subtitle: "A sign-in request is waiting on your iPhone.",
|
|
|
|
|
source: "github.com",
|
|
|
|
|
createdAt: .now.addingTimeInterval(-60 * 2),
|
|
|
|
|
kind: .signIn,
|
|
|
|
|
risk: .routine,
|
|
|
|
|
scopes: ["profile", "email"],
|
|
|
|
|
status: .pending
|
2026-04-19 21:50:03 +02:00
|
|
|
),
|
|
|
|
|
ApprovalRequest(
|
|
|
|
|
title: "Lufthansa sign-in",
|
|
|
|
|
subtitle: "Verify identity",
|
|
|
|
|
source: "lufthansa.com",
|
|
|
|
|
createdAt: .now.addingTimeInterval(-60 * 4),
|
|
|
|
|
kind: .accessGrant,
|
|
|
|
|
risk: .routine,
|
|
|
|
|
scopes: ["profile"],
|
|
|
|
|
status: .pending
|
|
|
|
|
),
|
|
|
|
|
ApprovalRequest(
|
|
|
|
|
title: "Hetzner",
|
|
|
|
|
subtitle: "Console",
|
|
|
|
|
source: "hetzner.cloud",
|
|
|
|
|
createdAt: .now.addingTimeInterval(-60 * 8),
|
|
|
|
|
kind: .elevatedAction,
|
|
|
|
|
risk: .elevated,
|
|
|
|
|
scopes: ["device"],
|
|
|
|
|
status: .pending
|
2026-04-19 16:29:13 +02:00
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
|
static func model() -> AppViewModel {
|
|
|
|
|
let model = AppViewModel(
|
|
|
|
|
service: MockIDPService.shared,
|
|
|
|
|
notificationCoordinator: WatchPreviewCoordinator(),
|
|
|
|
|
appStateStore: WatchPreviewStore(),
|
|
|
|
|
launchArguments: []
|
|
|
|
|
)
|
|
|
|
|
model.session = session
|
|
|
|
|
model.profile = profile
|
|
|
|
|
model.requests = requests
|
|
|
|
|
model.notifications = []
|
|
|
|
|
model.notificationPermission = .allowed
|
|
|
|
|
return model
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-19 16:29:13 +02:00
|
|
|
private struct WatchPreviewCoordinator: NotificationCoordinating {
|
|
|
|
|
func authorizationStatus() async -> NotificationPermissionState { .allowed }
|
|
|
|
|
func requestAuthorization() async throws -> NotificationPermissionState { .allowed }
|
|
|
|
|
func scheduleTestNotification(title: String, body: String) async throws {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct WatchPreviewStore: AppStateStoring {
|
|
|
|
|
func load() -> PersistedAppState? { nil }
|
|
|
|
|
func save(_ state: PersistedAppState) {}
|
|
|
|
|
func clear() {}
|
2026-04-18 01:05:22 +02:00
|
|
|
}
|