Mercurial > public > lazybear
comparison LazyBear/Views/Global Helpers/Company list/ExtensiveList.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 |
---|---|
18 @Environment(\.managedObjectContext) private var moc | 18 @Environment(\.managedObjectContext) private var moc |
19 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) | 19 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) |
20 var watchlistCompany: FetchedResults<WatchlistCompany> | 20 var watchlistCompany: FetchedResults<WatchlistCompany> |
21 | 21 |
22 @State private var isEditMode: EditMode = .inactive | 22 @State private var isEditMode: EditMode = .inactive |
23 @State private var showRenameAction = false | 23 @State private var showRenameListAction = false |
24 @State private var showDeleteAlert = false | 24 @State private var showDeleteListAlert = false |
25 @State private var showSearchView = false | 25 @State private var showSearchView = false |
26 | 26 |
27 var body: some View { | 27 var body: some View { |
28 NavigationView { | 28 NavigationView { |
29 ZStack { | 29 ZStack { |
52 } | 52 } |
53 | 53 |
54 // Blur background | 54 // Blur background |
55 Color(.black) | 55 Color(.black) |
56 .edgesIgnoringSafeArea(.all) | 56 .edgesIgnoringSafeArea(.all) |
57 .opacity(showRenameAction ? 0.2: 0) | 57 .opacity(showRenameListAction ? 0.2: 0) |
58 .animation(.easeInOut) | 58 .animation(.easeInOut) |
59 .onTapGesture { showRenameAction = false } | 59 .onTapGesture { showRenameListAction = false } |
60 | 60 |
61 // Show rename Action Sheet | 61 // Show rename Action Sheet |
62 TextfieldAlert(listName: listName, showRenameAction: $showRenameAction, presentationMode: presentationMode) | 62 TextfieldAlert(listName: listName, showRenameAction: $showRenameListAction, presentationMode: presentationMode) |
63 .offset(y: showRenameAction ? 0: 700) | 63 .offset(y: showRenameListAction ? 0: 700) |
64 .animation(.easeInOut) | 64 .animation(.easeInOut) |
65 } | 65 } |
66 // Show delete list alert | 66 // Show delete list alert |
67 .alert(isPresented: $showDeleteAlert) { | 67 .alert(isPresented: $showDeleteListAlert) { |
68 Alert( | 68 Alert( |
69 title: Text("Are you sure you want to delete this list?"), | 69 title: Text("Are you sure you want to delete this list?"), |
70 message: Text("This action can't be undo"), | 70 message: Text("This action can't be undo"), |
71 primaryButton: .destructive(Text("Delete")) { deleteList() }, | 71 primaryButton: .destructive(Text("Delete")) { deleteList() }, |
72 secondaryButton: .cancel() | 72 secondaryButton: .cancel() |
85 } | 85 } |
86 } | 86 } |
87 } | 87 } |
88 ToolbarItem(placement: .navigationBarTrailing) { | 88 ToolbarItem(placement: .navigationBarTrailing) { |
89 if addOnDelete { | 89 if addOnDelete { |
90 ToolbarMenu(showRenameAction: $showRenameAction, showDeleteAlert: $showDeleteAlert) | 90 ToolbarMenu(showRenameListAction: $showRenameListAction, showDeleteListAlert: $showDeleteListAlert) |
91 } | 91 } |
92 } | 92 } |
93 } | 93 } |
94 .environment(\.editMode, self.$isEditMode) // Always after Toolbar | 94 .environment(\.editMode, self.$isEditMode) // Always after Toolbar |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 // Delete company from watchlist | 98 /* |
99 Delete company from watchlist | |
100 */ | |
99 private func deleteCompany(at offsets: IndexSet) { | 101 private func deleteCompany(at offsets: IndexSet) { |
100 for index in offsets { | 102 for index in offsets { |
101 let company = watchlistCompany[index] | 103 let company = watchlistCompany[index] |
102 moc.delete(company) | 104 moc.delete(company) |
103 } | 105 } |
107 } catch { | 109 } catch { |
108 print(error.localizedDescription) | 110 print(error.localizedDescription) |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 // Remove entire watchlist | 114 /* |
115 Remove entire list if it's not the last one. It can't be zero watchlists | |
116 */ | |
113 private func deleteList() { | 117 private func deleteList() { |
114 let selectedWatchlist = watchlistCompany.filter({ $0.watchlist == listName }) | 118 let selectedWatchlist = watchlistCompany.filter({ $0.watchlist == listName }) |
115 for company in selectedWatchlist { | 119 for company in selectedWatchlist { |
116 moc.delete(company) | 120 moc.delete(company) |
117 } | 121 } |