Update message bubble helper

This commit is contained in:
Garth Vander Houwen 2021-09-27 19:37:38 -07:00
parent 05a07b3ba7
commit 50c3b17768
2 changed files with 31 additions and 22 deletions

View file

@ -37,4 +37,16 @@ class MessageData: ObservableObject {
}
}
}
func save() {
DispatchQueue.global(qos: .background).async { [weak self] in
guard let messages = self?.messages else { fatalError("Self out of scope") }
guard let data = try? JSONEncoder().encode(messages) else { fatalError("Error encoding data") }
do {
let outfile = Self.fileURL
try data.write(to: outfile)
} catch {
fatalError("Can't write to file")
}
}
}
}

View file

@ -7,29 +7,26 @@ struct MessageBubble: View {
var shortName: String
var body: some View {
VStack {
HStack (alignment: .top) {
CircleText(text: shortName, color: isCurrentUser ? Color.blue : Color(.darkGray)).padding(.all, 5)
VStack (alignment: .leading) {
Text(contentMessage)
.textSelection(.enabled)
.padding(10)
.foregroundColor(.white)
.background(isCurrentUser ? Color.blue : Color(.darkGray))
.cornerRadius(10)
HStack (spacing: 4) {
let messageDate = Date(timeIntervalSince1970: TimeInterval(time))
Text(messageDate, style: .date).font(.caption2).foregroundColor(.gray)
Text(messageDate, style: .time).font(.caption2).foregroundColor(.gray)
}
.padding(.bottom, 10)
}
Spacer()
}
HStack (alignment: .top) {
}.padding(.bottom, 1)
CircleText(text: shortName, color: isCurrentUser ? Color.blue : Color(.darkGray)).padding(.all, 5)
VStack (alignment: .leading) {
Text(contentMessage)
.textSelection(.enabled)
.padding(10)
.foregroundColor(.white)
.background(isCurrentUser ? Color.blue : Color(.darkGray))
.cornerRadius(10)
HStack (spacing: 4) {
let messageDate = Date(timeIntervalSince1970: TimeInterval(time))
Text(messageDate, style: .date).font(.caption2).foregroundColor(.gray)
Text(messageDate, style: .time).font(.caption2).foregroundColor(.gray)
}
.padding(.bottom, 10)
}
Spacer()
}
}
}