diff --git a/RippleChat.xcodeproj/project.pbxproj b/RippleChat.xcodeproj/project.pbxproj index 4d7273a..9e69ed9 100644 --- a/RippleChat.xcodeproj/project.pbxproj +++ b/RippleChat.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 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 */; }; + F59375722A5FF344001FA46A /* FeedDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F59375712A5FF344001FA46A /* FeedDetailView.swift */; }; F5A4B1212A5D4D1F00F5AE01 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */; }; F5A4B1232A5D5F8B00F5AE01 /* BTPeripheral.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */; }; F5A4B1252A5D7A8D00F5AE01 /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */; }; @@ -72,6 +73,7 @@ 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 = ""; }; + F59375712A5FF344001FA46A /* FeedDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedDetailView.swift; sourceTree = ""; }; F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPeripheral.swift; sourceTree = ""; }; F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = ""; }; @@ -182,6 +184,7 @@ F5A4B1262A5D861E00F5AE01 /* SettingsEditView.swift */, F5F1419B2A5EFA3600C81B1A /* LogEntryView.swift */, F5F1419D2A5EFA4700C81B1A /* FeedCardView.swift */, + F59375712A5FF344001FA46A /* FeedDetailView.swift */, ); path = Views; sourceTree = ""; @@ -329,6 +332,7 @@ F5F1419C2A5EFA3600C81B1A /* LogEntryView.swift in Sources */, F5847B6A2A59AB24009E28D4 /* FeedStore.swift in Sources */, F5A4B1272A5D861E00F5AE01 /* SettingsEditView.swift in Sources */, + F59375722A5FF344001FA46A /* FeedDetailView.swift in Sources */, F5F1419E2A5EFA4700C81B1A /* FeedCardView.swift in Sources */, F581F59B2A5AE72F0081C383 /* BluetoothController.swift in Sources */, 96454F1D2A558EBC0040BEBD /* ContentView.swift in Sources */, @@ -493,7 +497,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"RippleChat/Preview Content\""; - DEVELOPMENT_TEAM = GN2B48NJ47; + DEVELOPMENT_TEAM = B5S58UWR64; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Allow for bluetooth use"; @@ -524,7 +528,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"RippleChat/Preview Content\""; - DEVELOPMENT_TEAM = GN2B48NJ47; + DEVELOPMENT_TEAM = B5S58UWR64; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Allow for bluetooth use"; diff --git a/RippleChat/Body.swift b/RippleChat/Body.swift index 8a57f12..8bc8fcb 100644 --- a/RippleChat/Body.swift +++ b/RippleChat/Body.swift @@ -5,9 +5,10 @@ // Created by Severin Memmishofer on 08.07.23. // +import SwiftUI import Foundation -struct Body: Codable { +public struct Body: Codable { let tag: String let value: String diff --git a/RippleChat/Feed.swift b/RippleChat/Feed.swift index 7869992..845c034 100644 --- a/RippleChat/Feed.swift +++ b/RippleChat/Feed.swift @@ -17,6 +17,14 @@ struct Feed: Codable { self.feed = feed } + func getLastLogEntry() -> LogEntry { + if self.feed.isEmpty { + return LogEntry() + } else { + return self.feed.last! + } + } + } extension Feed { diff --git a/RippleChat/LogEntry.swift b/RippleChat/LogEntry.swift index 3ce0187..81cd032 100644 --- a/RippleChat/LogEntry.swift +++ b/RippleChat/LogEntry.swift @@ -7,7 +7,9 @@ import Foundation -struct LogEntry: Codable { +struct LogEntry: Codable, Identifiable { + + var id: UUID = UUID() let feedid: String let sequenceNumber: Int @@ -20,3 +22,7 @@ struct LogEntry: Codable { } } + +extension LogEntry { + static let sampleLogEntry = LogEntry(feedid: "BOB", sequenceNumber: 2, body: Body(tag: Apps.txt, value: "My first post!")) +} diff --git a/RippleChat/Views/FeedCardView.swift b/RippleChat/Views/FeedCardView.swift index 3d3173f..cc011e2 100644 --- a/RippleChat/Views/FeedCardView.swift +++ b/RippleChat/Views/FeedCardView.swift @@ -24,9 +24,9 @@ struct FeedCardView: View { HStack { Text("feedID: \(feed.feedID)") Spacer() - Text("Sequence Number: \(lastLogEntry.sequenceNumber)") + Text("SEQ: \(lastLogEntry.sequenceNumber)") } - Text("Log Entry: \(lastLogEntry.body.value)") + Text("Last: \(lastLogEntry.body.value)") } .padding() } diff --git a/RippleChat/Views/FeedDetailView.swift b/RippleChat/Views/FeedDetailView.swift new file mode 100644 index 0000000..bfbb891 --- /dev/null +++ b/RippleChat/Views/FeedDetailView.swift @@ -0,0 +1,33 @@ +// +// FeedDetailView.swift +// RippleChat +// +// Created by Severin Memmishofer on 13.07.23. +// + +import SwiftUI + +struct FeedDetailView: View { + @EnvironmentObject var dataStore: DataStore + var feed: Feed + + init(feed: Feed) { + self.feed = feed + } + + var body: some View { + NavigationStack { + List(feed.feed) { logEntry in + LogEntryView(logEntry: logEntry) + } + } + .navigationTitle("Feed: \(feed.feedID)") + } +} + +struct FeedsDetailView_Previews: PreviewProvider { + static var previews: some View { + FeedDetailView(feed: Feed.sampleFeed) + .environmentObject(DataStore.sampleDataStore) + } +} diff --git a/RippleChat/Views/FeedListView.swift b/RippleChat/Views/FeedListView.swift index 3eb8de1..41d5bf2 100644 --- a/RippleChat/Views/FeedListView.swift +++ b/RippleChat/Views/FeedListView.swift @@ -11,21 +11,23 @@ struct FeedListView: View { @EnvironmentObject var dataStore: DataStore var body: some View { - Text("FeedListView") - Image(systemName: "globe") - .imageScale(.large) - .foregroundColor(.accentColor) - Text("Hello, world!") - Button("Save Feed") { - } NavigationStack { - List(dataStore.feedStores) { feedStore in - NavigationLink(destination: Text(feedStore.feed.feedID)) { - FeedCardView(feed: feedStore.feed) + Form { + Section(header: Text("Your own Feed:")) { + NavigationLink(destination: FeedDetailView(feed: dataStore.personalFeed)) { + FeedCardView(feed: dataStore.personalFeed) + } + } + Section(header: Text("Feeds of your Firends")) { + List(dataStore.feedStores) { feedStore in + NavigationLink(destination: FeedDetailView(feed: feedStore.feed)) { + FeedCardView(feed: feedStore.feed) + } + } } } + NewFeedEntryView() } - NewFeedEntryView() } } diff --git a/RippleChat/Views/LogEntryView.swift b/RippleChat/Views/LogEntryView.swift index dc3c80e..48abdba 100644 --- a/RippleChat/Views/LogEntryView.swift +++ b/RippleChat/Views/LogEntryView.swift @@ -8,13 +8,32 @@ import SwiftUI struct LogEntryView: View { + var logEntry: LogEntry + + init(logEntry: LogEntry) { + self.logEntry = logEntry + } + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + HStack { + VStack { + HStack { + Text("SEQ: \(logEntry.sequenceNumber)") + Spacer() + Text("Tag: \(logEntry.body.tag)") + } + HStack { + Text("Value: \(logEntry.body.value)") + Spacer() + } + } + } + .padding() } } struct LogEntryView_Previews: PreviewProvider { static var previews: some View { - LogEntryView() + LogEntryView(logEntry: LogEntry.sampleLogEntry) } } diff --git a/RippleChat/Views/NewFeedEntryView.swift b/RippleChat/Views/NewFeedEntryView.swift index f0b2a5d..6fe3b06 100644 --- a/RippleChat/Views/NewFeedEntryView.swift +++ b/RippleChat/Views/NewFeedEntryView.swift @@ -10,11 +10,16 @@ import SwiftUI struct NewFeedEntryView: View { @State private var newEntry: String = "" @EnvironmentObject var dataStore: DataStore + var body: some View { VStack(alignment: .leading) { HStack { TextField("Enter your new feed message:", text: $newEntry) - Button(action: {}) { + Button(action: { + let nextSeq = dataStore.personalFeed.getLastLogEntry().sequenceNumber + 1 + let newBody = Body(tag: Apps.txt, value: newEntry) + let newLogEntry = LogEntry(feedid: dataStore.personalID, sequenceNumber: nextSeq, body: newBody) + }) { Text("Send") } }