Mercurial > public > lazybear
diff LazyBear/Views/Global Helpers/Extensive List/Helpers/ToolbarMenu.swift @ 417:5f21f7c23c5e
Add comments and clean code
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 11 Jun 2021 11:37:42 +0200 |
parents | LazyBear/Views/Global Helpers/Company list/Helpers/ToolbarMenu.swift@a0cf8fe47044 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Global Helpers/Extensive List/Helpers/ToolbarMenu.swift Fri Jun 11 11:37:42 2021 +0200 @@ -0,0 +1,44 @@ +// +// ToolbarMenu.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 25/4/21. +// + +import SwiftUI + +struct ToolbarMenu: View { + @Binding var showRenameListAction: Bool + @Binding var showDeleteListAlert: Bool + + @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) + var watchlistCompany: FetchedResults<WatchlistCompany> + + var body: some View { + Menu { + Section { + Button(action: { showRenameListAction = true }) { + Label("Rename list", systemImage: "square.and.pencil") + } + } + + if Set(watchlistCompany.map { $0.watchlist }).count > 1 { /// If there are only 1 watchlist -> It cannot be deleted + Section(header: Text("Secondary actions")) { + Button(action: { showDeleteListAlert = true }) { + Label("Delete list", systemImage: "trash") + } + } + } + } + label: { + Label("Options", systemImage: "ellipsis.circle") + .imageScale(.large) + } + } +} + +struct ToolbarMenu_Previews: PreviewProvider { + static var previews: some View { + ToolbarMenu(showRenameListAction: .constant(false), showDeleteListAlert: .constant(false)) + } +}