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 {
|
struct ListView: View {
|
||||||
|
|
||||||
@Environment(\.modelContext) var context
|
@Environment(\.modelContext) var context
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
@ObservedObject var viewModel: ListViewModel
|
@ObservedObject var viewModel: ListViewModel
|
||||||
|
|
||||||
@State var isAddingPassword: Bool = false
|
@State var isAddingPassword: Bool = false
|
||||||
|
@State var selectedItem: UUID?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationStack {
|
||||||
|
HStack {
|
||||||
List {
|
List {
|
||||||
ForEach(viewModel.passwords) { password in
|
HStack {
|
||||||
NavigationLink(destination: DetailView(viewModel: DetailViewModel(context: context, passwordID: password.id))) {
|
Text("Your passwords")
|
||||||
Text(password.name)
|
.fontWeight(.bold)
|
||||||
}
|
|
||||||
}
|
Spacer()
|
||||||
}
|
|
||||||
.scrollContentBackground(.hidden)
|
PwdButton(
|
||||||
.toolbar {
|
label: Image(systemName: "plus"),
|
||||||
Button(action: { isAddingPassword = true }) {
|
variant: .primary,
|
||||||
Image(systemName: "plus")
|
size: .icon,
|
||||||
.frame(width: 20, height: 20)
|
action: { isAddingPassword = true }
|
||||||
}
|
)
|
||||||
Button(action: {
|
PwdButton(
|
||||||
|
label: Image(systemName: "arrow.trianglehead.clockwise")
|
||||||
|
.imageScale(.small),
|
||||||
|
variant: .primary,
|
||||||
|
size: .icon,
|
||||||
|
action: {
|
||||||
viewModel.passwords = viewModel.getAllPasswords()
|
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) {
|
.sheet(isPresented: $isAddingPassword) {
|
||||||
AddPasswordView(viewModel: viewModel)
|
AddPasswordView(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue