Fixed Different Views and switching between them via the toolbar
This commit is contained in:
@@ -9,47 +9,55 @@ import SwiftUI
|
||||
import CoreBluetooth
|
||||
|
||||
struct ContentView: View {
|
||||
@ObservedObject private var bluetoothViewModel = BluetoothViewModel()
|
||||
@StateObject private var store = FeedStore(feed: Feed.sampleFeed)
|
||||
private var feedStores = [FeedStore(feed: Feed.sampleFeed), FeedStore(feed: Feed.sampleFeed2)]
|
||||
//@Binding var currentView: CurrentView
|
||||
@State var currentView = 0
|
||||
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundColor(.accentColor)
|
||||
Text("Hello, world!")
|
||||
Button("Save Feed") {
|
||||
Task {
|
||||
do {
|
||||
// try await store.save(feed: Feed.sampleFeed)
|
||||
for feed in feedStores {
|
||||
try await feed.save(feed: feed.feed)
|
||||
}
|
||||
} catch {
|
||||
fatalError(error.localizedDescription)
|
||||
switch self.currentView {
|
||||
case 0: PeeringView()
|
||||
case 1: FeedListView(feeds: [])
|
||||
case 2: SettingsView()
|
||||
default:
|
||||
FeedListView(feeds: [])
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .bottomBar) {
|
||||
Button(action: {
|
||||
self.currentView = 0
|
||||
}) {
|
||||
VStack {
|
||||
Label("Discovery", systemImage: "dot.radiowaves.left.and.right")
|
||||
Text("Discovery")
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button(action: {
|
||||
self.currentView = 1
|
||||
}) {
|
||||
VStack {
|
||||
Label("Feeds", systemImage: "person.2")
|
||||
Text("Feeds")
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button(action: {
|
||||
self.currentView = 2
|
||||
}) {
|
||||
VStack {
|
||||
Label("Settings", systemImage: "gear")
|
||||
Text("Settings")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
Spacer()
|
||||
NewFeedEntryView()
|
||||
// NavigationView {
|
||||
// List(bluetoothViewModel.peripheralNames, id: \.self) { peripheral in
|
||||
// Text(peripheral)
|
||||
// }
|
||||
// .navigationTitle("Peripherals")
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
public static var cv = CurrentView.feeds
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
}
|
||||
|
||||
@@ -9,42 +9,10 @@ import SwiftUI
|
||||
|
||||
@main
|
||||
struct RippleChatApp: App {
|
||||
//@State private var currentView: CurrentView = CurrentView.feeds
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .bottomBar) {
|
||||
Button(action: {}) {
|
||||
VStack {
|
||||
Label("Discovery", systemImage: "dot.radiowaves.left.and.right")
|
||||
Text("Discovery")
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button(action: {}) {
|
||||
VStack {
|
||||
Label("Discovery", systemImage: "person.2")
|
||||
Text("Feeds")
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button(action: {}) {
|
||||
VStack {
|
||||
Label("Discovery", systemImage: "gear")
|
||||
Text("Settings")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CurrentView {
|
||||
case peers
|
||||
case feeds
|
||||
case friends
|
||||
case settings
|
||||
}
|
||||
|
||||
@@ -9,9 +9,26 @@ import SwiftUI
|
||||
|
||||
struct FeedListView: View {
|
||||
@State var feeds: [Feed]
|
||||
@StateObject var store = FeedStore(feed: Feed.sampleFeed)
|
||||
var feedStores = [FeedStore(feed: Feed.sampleFeed), FeedStore(feed: Feed.sampleFeed2)]
|
||||
|
||||
var body: some View {
|
||||
Text("FeedListView")
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundColor(.accentColor)
|
||||
Text("Hello, world!")
|
||||
Button("Save Feed") {
|
||||
Task {
|
||||
do {
|
||||
for feed in feedStores {
|
||||
try await feed.save(feed: feed.feed)
|
||||
}
|
||||
} catch {
|
||||
fatalError(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,16 @@
|
||||
import SwiftUI
|
||||
|
||||
struct PeeringView: View {
|
||||
@ObservedObject private var bluetoothViewModel = BluetoothViewModel()
|
||||
|
||||
var body: some View {
|
||||
Text("Peering View")
|
||||
NavigationView {
|
||||
List(bluetoothViewModel.peripheralNames, id: \.self) { peripheral in
|
||||
Text(peripheral)
|
||||
}
|
||||
.navigationTitle("Peripherals")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
RippleChat/Views/SettingsView.swift
Normal file
20
RippleChat/Views/SettingsView.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SettingsView.swift
|
||||
// RippleChat
|
||||
//
|
||||
// Created by Severin Memmishofer on 11.07.23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
var body: some View {
|
||||
Text("Hello, Settings!")
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsView()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user