Improve password list view
This commit is contained in:
parent
55ace80869
commit
949292060b
2 changed files with 77 additions and 3 deletions
51
password/view/add/AddView.swift
Normal file
51
password/view/add/AddView.swift
Normal file
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// AddView.swift
|
||||
// password
|
||||
//
|
||||
// Created by Markus Thielker on 16.01.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddPasswordView: View {
|
||||
|
||||
@ObservedObject var viewModel: ListViewModel
|
||||
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State private var name: String = ""
|
||||
@State private var value: String = ""
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack {
|
||||
Text("Add Password")
|
||||
.font(.headline)
|
||||
Text("Create a new password to learn. It will be encrypted and stored securely.")
|
||||
}
|
||||
.padding(EdgeInsets(top: 0, leading: 0, bottom: 10, trailing: 0))
|
||||
Form {
|
||||
TextField("Name", text: $name)
|
||||
TextField("Value", text: $value)
|
||||
Text("The password will not be visible again later. Make sure to save it somewhere else too!")
|
||||
.font(.footnote)
|
||||
HStack {
|
||||
Button("Save") {
|
||||
viewModel.savePassword(name: name, value: value)
|
||||
name = ""
|
||||
value = ""
|
||||
dismiss()
|
||||
}
|
||||
Button("Cancel") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
.padding(EdgeInsets(top: 10, leading: 0, bottom: 0, trailing: 0))
|
||||
}
|
||||
}.padding(20)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
AddPasswordView(viewModel: .init())
|
||||
}
|
|
@ -10,16 +10,39 @@ import SwiftUI
|
|||
struct ListView: View {
|
||||
|
||||
@ObservedObject var viewModel: ListViewModel
|
||||
@State var isAddingPassword: Bool = false
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ForEach(viewModel.passwords) { password in
|
||||
NavigationLink(destination: Text(password.name)) {
|
||||
Text(password.name)
|
||||
List {
|
||||
ForEach(viewModel.passwords) { password in
|
||||
NavigationLink(destination: Text(password.name)) {
|
||||
Text(password.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.toolbar {
|
||||
Button(action: { isAddingPassword = true }) {
|
||||
Image(systemName: "plus")
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
Button(action: {
|
||||
viewModel.loadAllPasswords()
|
||||
}) {
|
||||
Image(systemName: "arrow.trianglehead.clockwise")
|
||||
.imageScale(.medium)
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Password Trainer")
|
||||
.sheet(isPresented: $isAddingPassword) {
|
||||
AddPasswordView(viewModel: viewModel)
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.loadAllPasswords()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue