Add Settings and Settings Edit Functionality
This commit is contained in:
parent
e1c606fdda
commit
379d3c8a0e
@ -10,7 +10,7 @@ import CoreBluetooth
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@State var currentView = 0
|
@State var currentView = 0
|
||||||
@EnvironmentObject var dataStore: DataStore
|
@StateObject var dataStore = DataStore()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@ -24,6 +24,7 @@ struct ContentView: View {
|
|||||||
case 2:
|
case 2:
|
||||||
SettingsView()
|
SettingsView()
|
||||||
.environmentObject(dataStore)
|
.environmentObject(dataStore)
|
||||||
|
.navigationTitle("Settings")
|
||||||
default:
|
default:
|
||||||
FeedListView(feeds: [])
|
FeedListView(feeds: [])
|
||||||
.environmentObject(dataStore)
|
.environmentObject(dataStore)
|
||||||
|
|||||||
@ -18,4 +18,6 @@ class DataStore: ObservableObject {
|
|||||||
self.friends = friends
|
self.friends = friends
|
||||||
self.feeds = feeds
|
self.feeds = feeds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,11 +9,10 @@ import SwiftUI
|
|||||||
|
|
||||||
@main
|
@main
|
||||||
struct RippleChatApp: App {
|
struct RippleChatApp: App {
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView()
|
ContentView()
|
||||||
.environmentObject(DataStore())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,14 +9,36 @@ import SwiftUI
|
|||||||
|
|
||||||
struct SettingsEditView: View {
|
struct SettingsEditView: View {
|
||||||
@EnvironmentObject var dataStore: DataStore
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
@State private var newFeedID = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
Section(header: Text("Personal Feed ID")) {
|
Section(header: Text("Personal Feed ID")) {
|
||||||
//TextField("FeedID", text: $scrum.title)
|
//Label(dataStore.personalID, systemImage: "person.crop.circle")
|
||||||
|
HStack {
|
||||||
|
TextField(dataStore.personalID, text: $dataStore.personalID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Section(header: Text("Friends")) {
|
Section(header: Text("Friends")) {
|
||||||
|
ForEach(dataStore.friends) { friend in
|
||||||
|
Label(friend, systemImage: "person")
|
||||||
|
}
|
||||||
|
.onDelete {indices in
|
||||||
|
dataStore.friends.remove(atOffsets: indices)
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
TextField("New Feed", text: $newFeedID)
|
||||||
|
Button(action: {
|
||||||
|
withAnimation {
|
||||||
|
let feedid = newFeedID
|
||||||
|
dataStore.friends.append(feedid)
|
||||||
|
newFeedID = ""
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Image(systemName: "plus.circle.fill")
|
||||||
|
}
|
||||||
|
.disabled(newFeedID.isEmpty)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,5 +47,6 @@ struct SettingsEditView: View {
|
|||||||
struct SettingsEditView_Previews: PreviewProvider {
|
struct SettingsEditView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsEditView()
|
SettingsEditView()
|
||||||
|
.environmentObject(DataStore())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,22 +8,72 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SettingsView: View {
|
struct SettingsView: View {
|
||||||
@State private var newEntry: String = ""
|
|
||||||
@EnvironmentObject var dataStore: DataStore
|
@EnvironmentObject var dataStore: DataStore
|
||||||
|
|
||||||
|
@State private var isPresentingEditView = false
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
|
|
||||||
|
List {
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button("Edit") {
|
||||||
|
isPresentingEditView = true
|
||||||
|
}
|
||||||
|
}
|
||||||
Section(header: Text("Personal Feed ID")) {
|
Section(header: Text("Personal Feed ID")) {
|
||||||
Text("Your FeedID is: \(dataStore.personalID)")
|
Label(dataStore.personalID, systemImage: "person.crop.circle")
|
||||||
}
|
}
|
||||||
Section(header: Text("Friends")) {
|
Section(header: Text("Friends")) {
|
||||||
|
ForEach(dataStore.friends) { friend in
|
||||||
|
Label(friend, systemImage: "person")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("Settings")
|
||||||
|
.sheet(isPresented: $isPresentingEditView) {
|
||||||
|
NavigationStack {
|
||||||
|
SettingsEditView()
|
||||||
|
.navigationTitle("Settings")
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction){
|
||||||
|
Button("Cancel") {
|
||||||
|
isPresentingEditView = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
Button("Done") {
|
||||||
|
isPresentingEditView = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SettingsView_Previews: PreviewProvider {
|
struct SettingsView_Previews: PreviewProvider {
|
||||||
|
static var friends = [
|
||||||
|
"BOS",
|
||||||
|
"ALI",
|
||||||
|
"CYN"
|
||||||
|
]
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsView()
|
SettingsView()
|
||||||
.environmentObject(DataStore(personalID: "BOB"))
|
.environmentObject(DataStore(personalID: "BOB", friends: friends))
|
||||||
|
.navigationTitle("Settings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension String: Identifiable {
|
||||||
|
public typealias ID = Int
|
||||||
|
public var id: Int {
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user