Added LogEntryView
This commit is contained in:
parent
6507b50666
commit
b1dc6bc473
@ -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 = "<group>"; };
|
||||
F5847B692A59AB24009E28D4 /* FeedStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedStore.swift; sourceTree = "<group>"; };
|
||||
F58EB2CF2A5590E800E22DA6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
F59375712A5FF344001FA46A /* FeedDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedDetailView.swift; sourceTree = "<group>"; };
|
||||
F5A4B1202A5D4D1F00F5AE01 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
F5A4B1222A5D5F8B00F5AE01 /* BTPeripheral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTPeripheral.swift; sourceTree = "<group>"; };
|
||||
F5A4B1242A5D7A8D00F5AE01 /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = "<group>"; };
|
||||
@ -182,6 +184,7 @@
|
||||
F5A4B1262A5D861E00F5AE01 /* SettingsEditView.swift */,
|
||||
F5F1419B2A5EFA3600C81B1A /* LogEntryView.swift */,
|
||||
F5F1419D2A5EFA4700C81B1A /* FeedCardView.swift */,
|
||||
F59375712A5FF344001FA46A /* FeedDetailView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
@ -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";
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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!"))
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
33
RippleChat/Views/FeedDetailView.swift
Normal file
33
RippleChat/Views/FeedDetailView.swift
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user