diff --git a/RippleChat/ContentView.swift b/RippleChat/ContentView.swift index f0b43cf..07f8d4f 100644 --- a/RippleChat/ContentView.swift +++ b/RippleChat/ContentView.swift @@ -10,7 +10,7 @@ import CoreBluetooth struct ContentView: View { @State var currentView = 0 - @EnvironmentObject var dataStore: DataStore + @StateObject var dataStore = DataStore() var body: some View { VStack { @@ -24,6 +24,7 @@ struct ContentView: View { case 2: SettingsView() .environmentObject(dataStore) + .navigationTitle("Settings") default: FeedListView(feeds: []) .environmentObject(dataStore) diff --git a/RippleChat/DataStore.swift b/RippleChat/DataStore.swift index 92c292c..eed3e22 100644 --- a/RippleChat/DataStore.swift +++ b/RippleChat/DataStore.swift @@ -18,4 +18,6 @@ class DataStore: ObservableObject { self.friends = friends self.feeds = feeds } + + } diff --git a/RippleChat/RippleChatApp.swift b/RippleChat/RippleChatApp.swift index 141770d..d4a8766 100644 --- a/RippleChat/RippleChatApp.swift +++ b/RippleChat/RippleChatApp.swift @@ -9,11 +9,10 @@ import SwiftUI @main struct RippleChatApp: App { - var body: some Scene { WindowGroup { ContentView() - .environmentObject(DataStore()) + } } } diff --git a/RippleChat/Views/SettingsEditView.swift b/RippleChat/Views/SettingsEditView.swift index be86a3f..ba2f29b 100644 --- a/RippleChat/Views/SettingsEditView.swift +++ b/RippleChat/Views/SettingsEditView.swift @@ -9,14 +9,36 @@ import SwiftUI struct SettingsEditView: View { @EnvironmentObject var dataStore: DataStore + @State private var newFeedID = "" var body: some View { Form { 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")) { - + 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 { static var previews: some View { SettingsEditView() + .environmentObject(DataStore()) } } diff --git a/RippleChat/Views/SettingsView.swift b/RippleChat/Views/SettingsView.swift index 5db63c2..fbb9bbe 100644 --- a/RippleChat/Views/SettingsView.swift +++ b/RippleChat/Views/SettingsView.swift @@ -8,22 +8,72 @@ import SwiftUI struct SettingsView: View { - @State private var newEntry: String = "" + @EnvironmentObject var dataStore: DataStore - var body: some View { - Section(header: Text("Personal Feed ID")) { - Text("Your FeedID is: \(dataStore.personalID)") - } - Section(header: Text("Friends")) { + @State private var isPresentingEditView = false + + var body: some View { + + + List { + HStack { + Spacer() + Button("Edit") { + isPresentingEditView = true + } + } + Section(header: Text("Personal Feed ID")) { + Label(dataStore.personalID, systemImage: "person.crop.circle") + } + 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 { + static var friends = [ + "BOS", + "ALI", + "CYN" + ] static var previews: some View { 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 + } +} +