Add detail view to check password
This commit is contained in:
parent
949292060b
commit
2707a0d982
2 changed files with 53 additions and 1 deletions
52
password/view/detail/DetailView.swift
Normal file
52
password/view/detail/DetailView.swift
Normal 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)
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ struct ListView: View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
List {
|
List {
|
||||||
ForEach(viewModel.passwords) { password in
|
ForEach(viewModel.passwords) { password in
|
||||||
NavigationLink(destination: Text(password.name)) {
|
NavigationLink(destination: DetailView(password: password)) {
|
||||||
Text(password.name)
|
Text(password.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue