SecureStorageSample/SecureStorageSample Watch App/ContentView.swift

118 lines
3.2 KiB
Swift

//
// ContentView.swift
// SecureStorageSample Watch App
//
// Created by Matt Bruce on 1/14/26.
//
import SwiftUI
import SharedKit
struct ContentView: View {
@State private var store = WatchProfileStore.shared
var body: some View {
VStack(alignment: .leading) {
PhoneConnectivityBadge(isReachable: store.isPhoneReachable)
ProfileSectionView(profile: store.profile)
Divider()
SyncableSettingSectionView(
value: store.syncValue,
updatedAt: store.syncUpdatedAt
)
if !store.statusMessage.isEmpty {
StatusMessageView(message: store.statusMessage)
}
}
.padding()
}
}
#Preview {
ContentView()
}
private struct PhoneConnectivityBadge: View {
let isReachable: Bool
var body: some View {
if !isReachable {
Text("Open iPhone App to Sync")
.font(.caption2)
.foregroundStyle(Color.Status.warning)
.padding(.horizontal, WatchDesign.Spacing.small)
.padding(.vertical, WatchDesign.Spacing.xSmall)
.background(Color.Status.warning.opacity(WatchDesign.Opacity.subtle))
.clipShape(.rect(cornerRadius: WatchDesign.CornerRadius.pill))
}
}
}
private struct ProfileSectionView: View {
let profile: UserProfile?
var body: some View {
VStack(alignment: .leading) {
Text("User Profile")
.font(.caption)
.foregroundStyle(.secondary)
if let profile {
Text(profile.name)
.bold()
Text(profile.email)
.font(.caption)
.foregroundStyle(.secondary)
Text("Age: \(profile.ageDescription)")
.font(.caption2)
.foregroundStyle(.secondary)
Text(profile.createdAt, format: .dateTime)
.font(.caption2)
.foregroundStyle(.secondary)
} else {
Text("No profile synced yet")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}
private struct SyncableSettingSectionView: View {
let value: String?
let updatedAt: Date?
var body: some View {
VStack(alignment: .leading) {
Text("Syncable Setting")
.font(.caption)
.foregroundStyle(.secondary)
if let value {
Text(value)
.font(.system(.caption, design: .monospaced))
if let updatedAt {
Text(updatedAt, format: .dateTime)
.font(.caption2)
.foregroundStyle(.secondary)
}
} else {
Text("No sync value received")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}
private struct StatusMessageView: View {
let message: String
var body: some View {
Text(message)
.font(.caption2)
.foregroundStyle(.secondary)
}
}