From 41f615611fee07e65734e4abf2b8b59eb39c0d7a Mon Sep 17 00:00:00 2001 From: Nicola Clark Date: Sat, 26 Jul 2025 15:35:51 -0500 Subject: [PATCH] mock up a list view for the OTPs --- OwnTP/{ContentView.swift => MainScreen.swift} | 19 ++++++----- OwnTP/Models/OTP.swift | 18 +++++++++++ OwnTP/OwnTPApp.swift | 2 +- OwnTP/Views/OTPListView.swift | 32 +++++++++++++++++++ 4 files changed, 60 insertions(+), 11 deletions(-) rename OwnTP/{ContentView.swift => MainScreen.swift} (59%) create mode 100644 OwnTP/Models/OTP.swift create mode 100644 OwnTP/Views/OTPListView.swift diff --git a/OwnTP/ContentView.swift b/OwnTP/MainScreen.swift similarity index 59% rename from OwnTP/ContentView.swift rename to OwnTP/MainScreen.swift index 1b902e1..c5fe1ec 100644 --- a/OwnTP/ContentView.swift +++ b/OwnTP/MainScreen.swift @@ -8,18 +8,17 @@ import SwiftUI -struct ContentView: View { +struct MainScreen: View { + let otps = [ + OTP(label: "howdy", code: 123456), + OTP(label: "y'all", code: 7890) + ] + var body: some View { - VStack { - Image(systemName: "clock") - .imageScale(.large) - .foregroundStyle(.tint) - Text("OwnTP") - } - .padding() + OTPListView(otpList: otps) } } -#Preview { - ContentView() +#Preview("App Main Screen") { + MainScreen() } diff --git a/OwnTP/Models/OTP.swift b/OwnTP/Models/OTP.swift new file mode 100644 index 0000000..5b063f0 --- /dev/null +++ b/OwnTP/Models/OTP.swift @@ -0,0 +1,18 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public License, +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at https://mozilla.org/MPL/2.0/. +// +// Copyright 2025 Nicola Clark +// + +import Foundation + +struct OTP: Identifiable { + let id = UUID() + + /// A human-readable label to identify the OTP + let label: String + /// The value of the OTP + let code: Int +} diff --git a/OwnTP/OwnTPApp.swift b/OwnTP/OwnTPApp.swift index 496ce3e..b042c9e 100644 --- a/OwnTP/OwnTPApp.swift +++ b/OwnTP/OwnTPApp.swift @@ -12,7 +12,7 @@ import SwiftUI struct OwnTPApp: App { var body: some Scene { WindowGroup { - ContentView() + MainScreen() } } } diff --git a/OwnTP/Views/OTPListView.swift b/OwnTP/Views/OTPListView.swift new file mode 100644 index 0000000..229373b --- /dev/null +++ b/OwnTP/Views/OTPListView.swift @@ -0,0 +1,32 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public License, +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at https://mozilla.org/MPL/2.0/. +// +// Copyright 2025 Nicola Clark +// + +import SwiftUI + +struct OTPListView: View { + let otpList: [OTP] + + var body: some View { + List { + ForEach(otpList) { otp in + HStack { + Text(otp.label) + .bold() + Spacer() + Text(String(format: "%06i", otp.code)) + } + } + } + } +} + +@available(iOS 17.0, *) +#Preview("OTP List", traits: .sizeThatFitsLayout) { + OTPListView(otpList: [OTP(label: "howdy", code: 123456), OTP(label: "y'all", code: 7890)]) + .frame(width: 300, height: 150) +}