PWD-1: replace NavigationView with NavigationStack implementation
This commit is contained in:
parent
ca240988b8
commit
4887f42b1f
1 changed files with 55 additions and 20 deletions
|
@ -11,35 +11,70 @@ import _SwiftData_SwiftUI
|
|||
struct ListView: View {
|
||||
|
||||
@Environment(\.modelContext) var context
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@ObservedObject var viewModel: ListViewModel
|
||||
|
||||
@State var isAddingPassword: Bool = false
|
||||
@State var selectedItem: UUID?
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
NavigationStack {
|
||||
HStack {
|
||||
List {
|
||||
ForEach(viewModel.passwords) { password in
|
||||
NavigationLink(destination: DetailView(viewModel: DetailViewModel(context: context, passwordID: password.id))) {
|
||||
Text(password.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.toolbar {
|
||||
Button(action: { isAddingPassword = true }) {
|
||||
Image(systemName: "plus")
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
Button(action: {
|
||||
HStack {
|
||||
Text("Your passwords")
|
||||
.fontWeight(.bold)
|
||||
|
||||
Spacer()
|
||||
|
||||
PwdButton(
|
||||
label: Image(systemName: "plus"),
|
||||
variant: .primary,
|
||||
size: .icon,
|
||||
action: { isAddingPassword = true }
|
||||
)
|
||||
PwdButton(
|
||||
label: Image(systemName: "arrow.trianglehead.clockwise")
|
||||
.imageScale(.small),
|
||||
variant: .primary,
|
||||
size: .icon,
|
||||
action: {
|
||||
viewModel.passwords = viewModel.getAllPasswords()
|
||||
}) {
|
||||
Image(systemName: "arrow.trianglehead.clockwise")
|
||||
.imageScale(.medium)
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
)
|
||||
}
|
||||
.background(.clear)
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
ForEach(viewModel.passwords) { password in
|
||||
Button("\(password.name)") {
|
||||
selectedItem = password.id
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8))
|
||||
.background(selectedItem == password.id ? .blue : .clear)
|
||||
.foregroundColor(selectedItem == password.id ? .white : (colorScheme == .dark ? .white : .black))
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
.frame(width: 250)
|
||||
.listStyle(SidebarListStyle())
|
||||
|
||||
if let selectedItem = selectedItem {
|
||||
DetailView(viewModel: DetailViewModel(context: context, passwordID: selectedItem))
|
||||
} else {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Select a password")
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Password Trainer")
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
|
||||
}
|
||||
.windowToolbarFullScreenVisibility(.onHover)
|
||||
.sheet(isPresented: $isAddingPassword) {
|
||||
AddPasswordView(viewModel: viewModel)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue