1
0
mirror of git://jb55.com/damus synced 2024-09-30 00:40:45 +00:00

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

@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
4C75EFA427FA577B0006080F /* PostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFA327FA577B0006080F /* PostView.swift */; }; 4C75EFA427FA577B0006080F /* PostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFA327FA577B0006080F /* PostView.swift */; };
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFA527FF87A20006080F /* Nostr.swift */; }; 4C75EFA627FF87A20006080F /* Nostr.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFA527FF87A20006080F /* Nostr.swift */; };
4C75EFAA28049C9F0006080F /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 4C75EFA928049C9F0006080F /* CachedAsyncImage */; };
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFAC28049CFB0006080F /* PostButton.swift */; }; 4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFAC28049CFB0006080F /* PostButton.swift */; };
4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFAE28049D340006080F /* NostrFilter.swift */; }; 4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFAE28049D340006080F /* NostrFilter.swift */; };
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB028049D510006080F /* NostrResponse.swift */; }; 4C75EFB128049D510006080F /* NostrResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB028049D510006080F /* NostrResponse.swift */; };
@ -33,6 +32,9 @@
4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; }; 4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */; };
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; }; 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */; };
4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF4280B29E600AB5EEF /* TimeAgo.swift */; }; 4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF4280B29E600AB5EEF /* TimeAgo.swift */; };
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */; };
4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */; };
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -81,6 +83,9 @@
4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; }; 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDetailView.swift; sourceTree = "<group>"; };
4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePicView.swift; sourceTree = "<group>"; }; 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePicView.swift; sourceTree = "<group>"; };
4CEE2AF4280B29E600AB5EEF /* TimeAgo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeAgo.swift; sourceTree = "<group>"; }; 4CEE2AF4280B29E600AB5EEF /* TimeAgo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeAgo.swift; sourceTree = "<group>"; };
4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileName.swift; sourceTree = "<group>"; };
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowView.swift; sourceTree = "<group>"; };
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventActionBar.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -90,7 +95,6 @@
files = ( files = (
4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */, 4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */,
4CE6DF1227F7A2B300C66700 /* Starscream in Frameworks */, 4CE6DF1227F7A2B300C66700 /* Starscream in Frameworks */,
4C75EFAA28049C9F0006080F /* CachedAsyncImage in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -119,6 +123,9 @@
4C75EFB82804A2740006080F /* EventView.swift */, 4C75EFB82804A2740006080F /* EventView.swift */,
4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */, 4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */,
4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */, 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */,
4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */,
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
); );
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
@ -227,7 +234,6 @@
name = damus; name = damus;
packageProductDependencies = ( packageProductDependencies = (
4CE6DF1127F7A2B300C66700 /* Starscream */, 4CE6DF1127F7A2B300C66700 /* Starscream */,
4C75EFA928049C9F0006080F /* CachedAsyncImage */,
4CEE2AEA2805AEA300AB5EEF /* secp256k1 */, 4CEE2AEA2805AEA300AB5EEF /* secp256k1 */,
); );
productName = damus; productName = damus;
@ -304,7 +310,6 @@
mainGroup = 4CE6DEDA27F7A08100C66700; mainGroup = 4CE6DEDA27F7A08100C66700;
packageReferences = ( packageReferences = (
4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */, 4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */,
4C75EFA828049C9F0006080F /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */,
4CEE2AE92805AEA300AB5EEF /* XCRemoteSwiftPackageReference "secp256k1" */, 4CEE2AE92805AEA300AB5EEF /* XCRemoteSwiftPackageReference "secp256k1" */,
); );
productRefGroup = 4CE6DEE427F7A08100C66700 /* Products */; productRefGroup = 4CE6DEE427F7A08100C66700 /* Products */;
@ -357,10 +362,13 @@
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */, 4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
4C75EFB328049D640006080F /* NostrEvent.swift in Sources */, 4C75EFB328049D640006080F /* NostrEvent.swift in Sources */,
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */, 4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */, 4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */,
4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */, 4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */,
4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */, 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */,
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */, 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */,
4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */,
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */, 4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */, 4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */,
4C75EFA427FA577B0006080F /* PostView.swift in Sources */, 4C75EFA427FA577B0006080F /* PostView.swift in Sources */,
@ -705,14 +713,6 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
4C75EFA828049C9F0006080F /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/lorenzofiamingo/swiftui-cached-async-image";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
};
};
4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */ = { 4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/daltoniam/Starscream"; repositoryURL = "https://github.com/daltoniam/Starscream";
@ -732,11 +732,6 @@
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
4C75EFA928049C9F0006080F /* CachedAsyncImage */ = {
isa = XCSwiftPackageProductDependency;
package = 4C75EFA828049C9F0006080F /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */;
productName = CachedAsyncImage;
};
4CE6DF1127F7A2B300C66700 /* Starscream */ = { 4CE6DF1127F7A2B300C66700 /* Starscream */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = 4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */; package = 4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */;

View File

@ -17,15 +17,6 @@
"revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21", "revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"version" : "4.0.4" "version" : "4.0.4"
} }
},
{
"identity" : "swiftui-cached-async-image",
"kind" : "remoteSourceControl",
"location" : "https://github.com/lorenzofiamingo/swiftui-cached-async-image",
"state" : {
"revision" : "eeb1565d780d1b75d045e21b5ca2a1e3650b0fc2",
"version" : "2.1.0"
}
} }
], ],
"version" : 2 "version" : 2

View File

@ -50,7 +50,7 @@ struct ContentView: View {
ForEach(events, id: \.id) { ev in ForEach(events, id: \.id) { ev in
if ev.is_local && timeline == .debug || (timeline == .global && !ev.is_local) || (timeline == .friends && is_friend(ev.pubkey)) { if ev.is_local && timeline == .debug || (timeline == .global && !ev.is_local) || (timeline == .friends && is_friend(ev.pubkey)) {
let profile: Profile? = profiles[ev.pubkey]?.profile let profile: Profile? = profiles[ev.pubkey]?.profile
NavigationLink(destination: EventDetailView(event: ev, profile: profile)) { NavigationLink(destination: EventDetailView(event: ev, profile: profile).navigationBarTitle("Note")) {
EventView(event: ev, profile: profile) EventView(event: ev, profile: profile)
} }
.buttonStyle(PlainButtonStyle()) .buttonStyle(PlainButtonStyle())

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() 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 { VStack {
HStack { HStack {
Text(String(profile?.name ?? String(event.pubkey.prefix(16)))) ProfileName(pubkey: event.pubkey, profile: profile)
.bold()
.onTapGesture {
UIPasteboard.general.string = event.pubkey
}
Text("\(format_relative_time(event.created_at))") Text("\(format_relative_time(event.created_at))")
.foregroundColor(.gray) .foregroundColor(.gray)
Spacer() Spacer()
if (event.pow ?? 0) >= 10 { if (event.pow ?? 0) >= 10 {
Text("\(event.pow ?? 0)") PowView(event.pow)
.font(.callout)
.foregroundColor(calculate_pow_color(event.pow ?? 0))
} }
} }
Text(event.content) Text(event.content)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
Spacer() Spacer()
EventActionBar(event: event)
Divider() Divider()
.padding([.top], 4)
} }
} }
.frame(minHeight: PFP_SIZE) .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 func format_relative_time(_ created_at: Int64) -> String
{ {
return time_ago_since(Date(timeIntervalSince1970: Double(created_at))) 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 { var body: some View {
if let pic = picture.flatMap({ URL(string: $0) }) { if let pic = picture.flatMap({ URL(string: $0) }) {
CachedAsyncImage(url: pic) { img in AsyncImage(url: pic) { img in
img.resizable() img.resizable()
} placeholder: { } placeholder: {
Color.purple.opacity(0.1) Color.purple.opacity(0.1)