Show SubscriptionAddView via a sheet
This commit is contained in:
parent
924145dcec
commit
3728d3ebe0
2 changed files with 39 additions and 15 deletions
|
|
@ -7,32 +7,37 @@ struct SubscriptionAddView: View {
|
|||
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
|
||||
@EnvironmentObject private var store: Store
|
||||
@State private var topic: String = ""
|
||||
@Binding var isShowing: Bool
|
||||
|
||||
private var subscriptionManager: SubscriptionManager {
|
||||
return SubscriptionManager(store: store)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Form {
|
||||
Section(
|
||||
header: Text("Topic name"),
|
||||
footer: Text("Topics may not be password protected, so choose a name that's not easy to guess. Once subscribed, you can PUT/POST notifications")
|
||||
) {
|
||||
TextField("Topic name, e.g. phil_alerts", text: $topic)
|
||||
.disableAutocapitalization()
|
||||
.disableAutocorrection(true)
|
||||
}
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
NavigationView {
|
||||
VStack {
|
||||
Form {
|
||||
Section(
|
||||
header: Text("Topic name"),
|
||||
footer: Text("Topics may not be password protected, so choose a name that's not easy to guess. Once subscribed, you can PUT/POST notifications")
|
||||
) {
|
||||
TextField("Topic name, e.g. phil_alerts", text: $topic)
|
||||
.disableAutocapitalization()
|
||||
.disableAutocorrection(true)
|
||||
}
|
||||
|
||||
Button(action: subscribeAction) {
|
||||
Text("Subscribe")
|
||||
}
|
||||
.disabled(!isValid(topic: topic))
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
CloseButton(isShowing: $isShowing)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Add Subscription")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,3 +57,16 @@ struct SubscriptionAddView: View {
|
|||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
struct CloseButton: View {
|
||||
@Binding var isShowing: Bool
|
||||
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
isShowing = false
|
||||
}, label: {
|
||||
Image(systemName: "xmark")
|
||||
.font(.headline)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ struct SubscriptionListView: View {
|
|||
|
||||
@EnvironmentObject private var store: Store
|
||||
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Subscription.topic, ascending: true)]) var subscriptions: FetchedResults<Subscription>
|
||||
@State private var showingAddSubscriptionView = false
|
||||
|
||||
private var subscriptionManager: SubscriptionManager {
|
||||
return SubscriptionManager(store: store)
|
||||
|
|
@ -50,7 +51,9 @@ struct SubscriptionListView: View {
|
|||
.navigationTitle("Subscribed topics")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
NavigationLink(destination: SubscriptionAddView()) {
|
||||
Button {
|
||||
self.showingAddSubscriptionView = true
|
||||
} label: {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +72,9 @@ struct SubscriptionListView: View {
|
|||
.padding(40)
|
||||
}
|
||||
})
|
||||
.sheet(isPresented: $showingAddSubscriptionView) {
|
||||
SubscriptionAddView(isShowing: $showingAddSubscriptionView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue