Mercurial > public > lazybear
comparison LazyBear/Views/Profile/Helpers/RenameListSheet.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 | 8c58ce834d95 |
children |
comparison
equal
deleted
inserted
replaced
429:e4ca9898b79b | 430:c78d5b5b3bda |
---|---|
8 import SwiftUI | 8 import SwiftUI |
9 import Introspect | 9 import Introspect |
10 | 10 |
11 struct RenameListSheet: View { | 11 struct RenameListSheet: View { |
12 var oldWatchlistName: String | 12 var oldWatchlistName: String |
13 | |
13 @State private var newWatchlistName = String() | 14 @State private var newWatchlistName = String() |
14 | 15 |
15 @Environment(\.presentationMode) private var renameListSheetPresentationMode | 16 @Environment(\.presentationMode) private var renameListSheetPresentation |
16 @Environment(\.managedObjectContext) private var moc | 17 @Environment(\.managedObjectContext) private var moc |
17 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) | 18 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) |
18 var watchlistCompanies: FetchedResults<WatchlistCompany> | 19 var watchlistCompanies: FetchedResults<WatchlistCompany> |
19 | 20 |
20 var body: some View { | 21 var body: some View { |
29 } | 30 } |
30 } | 31 } |
31 .navigationTitle("Rename your watchlist") | 32 .navigationTitle("Rename your watchlist") |
32 .toolbar { | 33 .toolbar { |
33 ToolbarItem(placement: .navigationBarLeading) { | 34 ToolbarItem(placement: .navigationBarLeading) { |
34 Button(action: { renameListSheetPresentationMode.wrappedValue.dismiss() }) { | 35 Button(action: { renameListSheetPresentation.wrappedValue.dismiss() }) { |
35 Image(systemName: "multiply") | 36 Image(systemName: "multiply") |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 ToolbarItem(placement: .navigationBarTrailing) { | 40 ToolbarItem(placement: .navigationBarTrailing) { |
53 watchlistCompany.watchlistName = newWatchlistName | 54 watchlistCompany.watchlistName = newWatchlistName |
54 } | 55 } |
55 | 56 |
56 do { | 57 do { |
57 try moc.save() | 58 try moc.save() |
58 renameListSheetPresentationMode.wrappedValue.dismiss() | 59 renameListSheetPresentation.wrappedValue.dismiss() |
60 | |
59 } catch { | 61 } catch { |
60 print(error.localizedDescription) | 62 print(error.localizedDescription) |
61 } | 63 } |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 struct RenameListSheet_Previews: PreviewProvider { | 67 struct RenameListSheet_Previews: PreviewProvider { |
68 @Environment(\.presentationMode) static var presentationMode | |
69 | |
66 static var previews: some View { | 70 static var previews: some View { |
67 RenameListSheet(oldWatchlistName: "Old name") | 71 RenameListSheet(oldWatchlistName: "Old name") |
68 } | 72 } |
69 } | 73 } |