comparison LazyBear/Views/Global Helpers/Company list/Helpers/ToolbarMenu.swift @ 395:a0cf8fe47044

Fix minor bugs
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Fri, 07 May 2021 11:43:47 +0200
parents 4c90e5b18632
children
comparison
equal deleted inserted replaced
394:4c90e5b18632 395:a0cf8fe47044
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct ToolbarMenu: View { 10 struct ToolbarMenu: View {
11 @Binding var showRenameAction: Bool 11 @Binding var showRenameListAction: Bool
12 @Binding var showDeleteAlert: Bool 12 @Binding var showDeleteListAlert: Bool
13
14 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: [])
15 var watchlistCompany: FetchedResults<WatchlistCompany>
13 16
14 var body: some View { 17 var body: some View {
15 Menu { 18 Menu {
16 Section { 19 Section {
17 Button(action: { showRenameAction = true }) { 20 Button(action: { showRenameListAction = true }) {
18 Label("Rename list", systemImage: "square.and.pencil") 21 Label("Rename list", systemImage: "square.and.pencil")
19 } 22 }
20 } 23 }
21 24
22 Section(header: Text("Secondary actions")) { 25 // If there are only 1 watchlist -> It cannot be deleted
23 Button(action: { showDeleteAlert = true }) { 26 if Set(watchlistCompany.map { $0.watchlist }).count > 1 {
24 Label("Delete list", systemImage: "trash") 27 Section(header: Text("Secondary actions")) {
28 Button(action: { showDeleteListAlert = true }) {
29 Label("Delete list", systemImage: "trash")
30 }
25 } 31 }
26 } 32 }
27 } 33 }
28 label: { 34 label: {
29 Label("Options", systemImage: "ellipsis.circle") 35 Label("Options", systemImage: "ellipsis.circle")
32 } 38 }
33 } 39 }
34 40
35 struct ToolbarMenu_Previews: PreviewProvider { 41 struct ToolbarMenu_Previews: PreviewProvider {
36 static var previews: some View { 42 static var previews: some View {
37 ToolbarMenu(showRenameAction: .constant(false), showDeleteAlert: .constant(false)) 43 ToolbarMenu(showRenameListAction: .constant(false), showDeleteListAlert: .constant(false))
38 } 44 }
39 } 45 }