1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-29 03:01:07 +01:00
metatext-app-ios-iphone-ipad/Views/SwiftUI/AddRemoveFromListsView.swift
2021-03-02 16:50:22 -08:00

41 lines
1.4 KiB
Swift

// Copyright © 2021 Metabolist. All rights reserved.
import SwiftUI
import ViewModels
struct AddRemoveFromListsView: View {
@StateObject var viewModel: AddRemoveFromListsViewModel
var body: some View {
Group {
if viewModel.loaded {
List(viewModel.lists) { list in
Button {
if viewModel.listIdsWithAccount.contains(list.id) {
viewModel.removeFromList(id: list.id)
} else {
viewModel.addToList(id: list.id)
}
} label: {
HStack {
Text(list.title)
if viewModel.listIdsWithAccount.contains(list.id) {
Spacer()
Image(systemName: "checkmark.circle")
.foregroundColor(.green)
}
}
}
.accessibility(addTraits: viewModel.listIdsWithAccount.contains(list.id) ? [.isSelected] : [])
}
} else {
ProgressView()
}
}
.onAppear(perform: viewModel.refreshLists)
.onAppear(perform: viewModel.fetchListsWithAccount)
.navigationTitle(Text("secondary-navigation.lists"))
.alertItem($viewModel.alertItem)
}
}