comparison LazyBear/Views/Profile/Helpers/WatchlistCreator.swift @ 430:c78d5b5b3bda

Minor updates
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 19 Jun 2021 16:21:26 +0200
parents 4effac4733b0
children
comparison
equal deleted inserted replaced
429:e4ca9898b79b 430:c78d5b5b3bda
12 @State private var showSearchView = false 12 @State private var showSearchView = false
13 @State private var showCancelAlert = false 13 @State private var showCancelAlert = false
14 @State private var watchlistNameIsEmpty = false 14 @State private var watchlistNameIsEmpty = false
15 15
16 @Environment(\.managedObjectContext) private var moc 16 @Environment(\.managedObjectContext) private var moc
17 @Environment(\.presentationMode) private var presentationMode 17 @Environment(\.presentationMode) private var watchlistCreatorPresentation
18 18
19 var body: some View { 19 var body: some View {
20 NavigationView { 20 NavigationView {
21 Form { 21 Form {
22 Section(header: Text("Watchlist name")) { 22 Section(header: Text("Watchlist name")) {
58 } 58 }
59 .alert(isPresented: $showCancelAlert) { /// Show alert when the user tries to exit the view without saving the new watchlist 59 .alert(isPresented: $showCancelAlert) { /// Show alert when the user tries to exit the view without saving the new watchlist
60 Alert( 60 Alert(
61 title: Text("Your watchlist won't be saved"), 61 title: Text("Your watchlist won't be saved"),
62 message: Text("This action can't be undo"), 62 message: Text("This action can't be undo"),
63 primaryButton: .destructive(Text("Exit")) { presentationMode.wrappedValue.dismiss() }, 63 primaryButton: .destructive(Text("Exit")) { watchlistCreatorPresentation.wrappedValue.dismiss() },
64 secondaryButton: .cancel() 64 secondaryButton: .cancel()
65 ) 65 )
66 } 66 }
67 } 67 }
68 .alert(isPresented: $watchlistNameIsEmpty) { /// Show alert when the user tries to save the watchlist without a name 68 .alert(isPresented: $watchlistNameIsEmpty) { /// Show alert when the user tries to save the watchlist without a name
103 } 103 }
104 104
105 do { 105 do {
106 try moc.save() 106 try moc.save()
107 print("Watchlist created") 107 print("Watchlist created")
108 presentationMode.wrappedValue.dismiss() // Dismiss view 108 watchlistCreatorPresentation.wrappedValue.dismiss() // Dismiss view
109 } catch { 109 } catch {
110 print(error.localizedDescription) 110 print(error.localizedDescription)
111 } 111 }
112 } 112 }
113 } 113 }