Add detail view to check password

This commit is contained in:
Markus Thielker 2025-01-16 16:10:28 +01:00
parent 949292060b
commit 2707a0d982
No known key found for this signature in database
2 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,52 @@
//
// DetailView.swift
// password
//
// Created by Markus Thielker on 16.01.25.
//
import SwiftUI
struct DetailView: View {
let password: Password
@State var value: String = ""
func validateInput(input: String, password: Password) -> Bool {
return input == password.value
}
var body: some View {
VStack {
Text("Enter the password for \(password.name)")
Form {
SecureField("", text: $value)
Button("Submit") {
let correct = validateInput(input: value, password: password)
if (correct) {
let alert = NSAlert()
alert.messageText = "Correct"
alert.informativeText = "That one was correct!"
alert.addButton(withTitle: "Let's go!")
alert.runModal()
} else {
let alert = NSAlert()
alert.messageText = "Not quite"
alert.informativeText = " That one was not quite right! Try again!"
alert.addButton(withTitle: "Okay")
alert.runModal()
}
value = ""
}
}
}
.padding()
}
}
#Preview {
let password = Password(name: "macbook", value: "password")
DetailView(password: password)
}

View file

@ -16,7 +16,7 @@ struct ListView: View {
NavigationView {
List {
ForEach(viewModel.passwords) { password in
NavigationLink(destination: Text(password.name)) {
NavigationLink(destination: DetailView(password: password)) {
Text(password.name)
}
}