mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-23 05:56:30 +00:00
64 lines
2 KiB
Swift
64 lines
2 KiB
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import SwiftUI
|
|
|
|
struct ListsView: View {
|
|
@StateObject var viewModel: ListsViewModel
|
|
@EnvironmentObject var tabNavigationViewModel: TabNavigationViewModel
|
|
@State private var newListTitle = ""
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section {
|
|
TextField("lists.new-list-title", text: $newListTitle)
|
|
.disabled(viewModel.creatingList)
|
|
if viewModel.creatingList {
|
|
ProgressView()
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
} else {
|
|
Button {
|
|
viewModel.createList(title: newListTitle)
|
|
} label: {
|
|
Label("add", systemImage: "plus.circle")
|
|
}
|
|
.disabled(newListTitle == "")
|
|
}
|
|
}
|
|
Section {
|
|
ForEach(viewModel.lists) { list in
|
|
Button(list.title) {
|
|
tabNavigationViewModel.timeline = .list(list)
|
|
tabNavigationViewModel.presentingSecondaryNavigation = false
|
|
}
|
|
}
|
|
.onDelete {
|
|
guard let index = $0.first else { return }
|
|
|
|
viewModel.delete(list: viewModel.lists[index])
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle(Text("secondary-navigation.lists"))
|
|
.toolbar {
|
|
ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
|
|
EditButton()
|
|
}
|
|
}
|
|
.alertItem($viewModel.alertItem)
|
|
.onAppear(perform: viewModel.refreshLists)
|
|
.onReceive(viewModel.$creatingList) {
|
|
if !$0 {
|
|
newListTitle = ""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
struct ListsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ListsView(viewModel: .development)
|
|
.environmentObject(TabNavigationViewModel.development)
|
|
}
|
|
}
|
|
#endif
|