event action bar, more detail view

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-16 11:32:42 -07:00
parent e48af81b75
commit 2676dea140
9 changed files with 116 additions and 44 deletions

View File

@@ -0,0 +1,34 @@
//
// EventActionBar.swift
// damus
//
// Created by William Casarin on 2022-04-16.
//
import SwiftUI
struct EventActionBar: View {
let event: NostrEvent
var body: some View {
HStack {
EventActionButton(img: "bubble.left") {
print("reply")
}
Spacer()
EventActionButton(img: "square.and.arrow.up") {
print("share")
}
}
}
}
func EventActionButton(img: String, action: @escaping () -> ()) -> some View {
Button(action: action) {
Label("", systemImage: img)
.font(.footnote)
.foregroundColor(.gray)
}
}

View File

@@ -18,7 +18,27 @@ struct EventDetailView: View {
Spacer()
}
VStack {
HStack {
ProfileName(pubkey: event.pubkey, profile: profile)
Text("\(format_relative_time(event.created_at))")
.foregroundColor(.gray)
Spacer()
PowView(event.pow)
}
Text(event.content)
.frame(maxWidth: .infinity, alignment: .leading)
Divider()
.padding([.bottom], 10)
EventActionBar(event: event)
Spacer()
}
}
.padding()
}
}

View File

@@ -23,41 +23,31 @@ struct EventView: View {
VStack {
HStack {
Text(String(profile?.name ?? String(event.pubkey.prefix(16))))
.bold()
.onTapGesture {
UIPasteboard.general.string = event.pubkey
}
ProfileName(pubkey: event.pubkey, profile: profile)
Text("\(format_relative_time(event.created_at))")
.foregroundColor(.gray)
Spacer()
if (event.pow ?? 0) >= 10 {
Text("\(event.pow ?? 0)")
.font(.callout)
.foregroundColor(calculate_pow_color(event.pow ?? 0))
PowView(event.pow)
}
}
Text(event.content)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
EventActionBar(event: event)
Divider()
.padding([.top], 4)
}
}
.frame(minHeight: PFP_SIZE)
.padding([.bottom], 4)
}
}
// TODO: make this less saturated on white theme
func calculate_pow_color(_ pow: Int) -> Color
{
let x = Double(pow) / 30.0;
return Color(.sRGB, red: 2.0 * (1.0 - x), green: 2.0 * x, blue: 0, opacity: 0.5)
}
func format_relative_time(_ created_at: Int64) -> String
{
return time_ago_since(Date(timeIntervalSince1970: Double(created_at)))

25
damus/Views/PowView.swift Normal file
View File

@@ -0,0 +1,25 @@
//
// PowView.swift
// damus
//
// Created by William Casarin on 2022-04-16.
//
import Foundation
import SwiftUI
func PowView(_ mpow: Int?) -> some View
{
let pow = mpow ?? 0
return Text("\(pow)")
.font(.callout)
.foregroundColor(calculate_pow_color(pow))
}
// TODO: make this less saturated on white theme
func calculate_pow_color(_ pow: Int) -> Color
{
let x = Double(pow) / 30.0;
return Color(.sRGB, red: 2.0 * (1.0 - x), green: 2.0 * x, blue: 0, opacity: 0.5)
}

View File

@@ -0,0 +1,17 @@
//
// ProfileName.swift
// damus
//
// Created by William Casarin on 2022-04-16.
//
import SwiftUI
func ProfileName(pubkey: String, profile: Profile?) -> some View {
Text(String(profile?.name ?? String(pubkey.prefix(16))))
.bold()
.onTapGesture {
UIPasteboard.general.string = pubkey
}
}

View File

@@ -17,7 +17,7 @@ struct ProfilePicView: View {
var body: some View {
if let pic = picture.flatMap({ URL(string: $0) }) {
CachedAsyncImage(url: pic) { img in
AsyncImage(url: pic) { img in
img.resizable()
} placeholder: {
Color.purple.opacity(0.1)