From b71426d6b9755230392ad1b8659aeeea9cdbeaa4 Mon Sep 17 00:00:00 2001 From: "severin.memmishofer" Date: Tue, 11 Jul 2023 10:50:33 +0200 Subject: [PATCH] Fixed Different Views and switching between them via the toolbar --- RippleChat.xcodeproj/project.pbxproj | 8 ++-- RippleChat/ContentView.swift | 64 ++++++++++++++++------------ RippleChat/RippleChatApp.swift | 32 -------------- RippleChat/Views/FeedListView.swift | 17 ++++++++ RippleChat/Views/PeeringView.swift | 8 ++++ RippleChat/Views/SettingsView.swift | 20 +++++++++ 6 files changed, 85 insertions(+), 64 deletions(-) create mode 100644 RippleChat/Views/SettingsView.swift diff --git a/RippleChat.xcodeproj/project.pbxproj b/RippleChat.xcodeproj/project.pbxproj index e589f10..e7f903f 100644 --- a/RippleChat.xcodeproj/project.pbxproj +++ b/RippleChat.xcodeproj/project.pbxproj @@ -19,13 +19,13 @@ 96BD33102A5C27B0007A6E53 /* NewFeedEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BD330F2A5C27B0007A6E53 /* NewFeedEntryView.swift */; }; 96BD33132A5C400B007A6E53 /* FeedListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BD33122A5C400B007A6E53 /* FeedListView.swift */; }; 96BD33162A5C403C007A6E53 /* PeeringView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BD33152A5C403C007A6E53 /* PeeringView.swift */; }; - 96BD33182A5C404F007A6E53 /* FriendsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BD33172A5C404F007A6E53 /* FriendsListView.swift */; }; F581F59B2A5AE72F0081C383 /* BluetoothViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F581F59A2A5AE72F0081C383 /* BluetoothViewModel.swift */; }; F5847B622A599BF4009E28D4 /* Body.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5847B612A599BF4009E28D4 /* Body.swift */; }; F5847B642A599CC3009E28D4 /* LogEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5847B632A599CC3009E28D4 /* LogEntry.swift */; }; F5847B662A599EA4009E28D4 /* Feed.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5847B652A599EA4009E28D4 /* Feed.swift */; }; F5847B6A2A59AB24009E28D4 /* FeedStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5847B692A59AB24009E28D4 /* FeedStore.swift */; }; F58EB2D02A5590E800E22DA6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F58EB2CF2A5590E800E22DA6 /* README.md */; }; + F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -61,13 +61,13 @@ 96BD330F2A5C27B0007A6E53 /* NewFeedEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewFeedEntryView.swift; sourceTree = ""; }; 96BD33122A5C400B007A6E53 /* FeedListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListView.swift; sourceTree = ""; }; 96BD33152A5C403C007A6E53 /* PeeringView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeeringView.swift; sourceTree = ""; }; - 96BD33172A5C404F007A6E53 /* FriendsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListView.swift; sourceTree = ""; }; F581F59A2A5AE72F0081C383 /* BluetoothViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothViewModel.swift; sourceTree = ""; }; F5847B612A599BF4009E28D4 /* Body.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Body.swift; sourceTree = ""; }; F5847B632A599CC3009E28D4 /* LogEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEntry.swift; sourceTree = ""; }; F5847B652A599EA4009E28D4 /* Feed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Feed.swift; sourceTree = ""; }; F5847B692A59AB24009E28D4 /* FeedStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedStore.swift; sourceTree = ""; }; F58EB2CF2A5590E800E22DA6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -166,7 +166,7 @@ 96BD330F2A5C27B0007A6E53 /* NewFeedEntryView.swift */, 96BD33122A5C400B007A6E53 /* FeedListView.swift */, 96BD33152A5C403C007A6E53 /* PeeringView.swift */, - 96BD33172A5C404F007A6E53 /* FriendsListView.swift */, + F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */, ); path = Views; sourceTree = ""; @@ -305,7 +305,6 @@ files = ( F5847B622A599BF4009E28D4 /* Body.swift in Sources */, 96BD33162A5C403C007A6E53 /* PeeringView.swift in Sources */, - 96BD33182A5C404F007A6E53 /* FriendsListView.swift in Sources */, F5847B662A599EA4009E28D4 /* Feed.swift in Sources */, 96BD33132A5C400B007A6E53 /* FeedListView.swift in Sources */, F5847B642A599CC3009E28D4 /* LogEntry.swift in Sources */, @@ -313,6 +312,7 @@ F5847B6A2A59AB24009E28D4 /* FeedStore.swift in Sources */, F581F59B2A5AE72F0081C383 /* BluetoothViewModel.swift in Sources */, 96454F1D2A558EBC0040BEBD /* ContentView.swift in Sources */, + F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */, 96BD330E2A5C254B007A6E53 /* TextApp.swift in Sources */, 96454F1B2A558EBC0040BEBD /* RippleChatApp.swift in Sources */, ); diff --git a/RippleChat/ContentView.swift b/RippleChat/ContentView.swift index cccaaab..9f1289e 100644 --- a/RippleChat/ContentView.swift +++ b/RippleChat/ContentView.swift @@ -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() } diff --git a/RippleChat/RippleChatApp.swift b/RippleChat/RippleChatApp.swift index e9299a5..e7067c0 100644 --- a/RippleChat/RippleChatApp.swift +++ b/RippleChat/RippleChatApp.swift @@ -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 -} diff --git a/RippleChat/Views/FeedListView.swift b/RippleChat/Views/FeedListView.swift index 36a9636..6033354 100644 --- a/RippleChat/Views/FeedListView.swift +++ b/RippleChat/Views/FeedListView.swift @@ -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) + } + } + } } } diff --git a/RippleChat/Views/PeeringView.swift b/RippleChat/Views/PeeringView.swift index da9f6f7..53f108f 100644 --- a/RippleChat/Views/PeeringView.swift +++ b/RippleChat/Views/PeeringView.swift @@ -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") + } } } diff --git a/RippleChat/Views/SettingsView.swift b/RippleChat/Views/SettingsView.swift new file mode 100644 index 0000000..6871573 --- /dev/null +++ b/RippleChat/Views/SettingsView.swift @@ -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() + } +}