commit 2676dea1409957d3312b52d48dbcae3d876b2c09
parent e48af81b7522ae813b526a5a6d1ae91bf4d63f02
Author: William Casarin <jb55@jb55.com>
Date: Sat, 16 Apr 2022 11:32:42 -0700
event action bar, more detail view
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
9 files changed, 116 insertions(+), 44 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
4C75EFA427FA577B0006080F /* PostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFA327FA577B0006080F /* PostView.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 */; };
4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFAE28049D340006080F /* NostrFilter.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 */; };
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF2280B25C500AB5EEF /* ProfilePicView.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 */
/* Begin PBXContainerItemProxy section */
@@ -81,6 +83,9 @@
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>"; };
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 */
/* Begin PBXFrameworksBuildPhase section */
@@ -90,7 +95,6 @@
files = (
4CEE2AEB2805AEA300AB5EEF /* secp256k1 in Frameworks */,
4CE6DF1227F7A2B300C66700 /* Starscream in Frameworks */,
- 4C75EFAA28049C9F0006080F /* CachedAsyncImage in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -119,6 +123,9 @@
4C75EFB82804A2740006080F /* EventView.swift */,
4CEE2AF0280B216B00AB5EEF /* EventDetailView.swift */,
4CEE2AF2280B25C500AB5EEF /* ProfilePicView.swift */,
+ 4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */,
+ 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
+ 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
);
path = Views;
sourceTree = "<group>";
@@ -227,7 +234,6 @@
name = damus;
packageProductDependencies = (
4CE6DF1127F7A2B300C66700 /* Starscream */,
- 4C75EFA928049C9F0006080F /* CachedAsyncImage */,
4CEE2AEA2805AEA300AB5EEF /* secp256k1 */,
);
productName = damus;
@@ -304,7 +310,6 @@
mainGroup = 4CE6DEDA27F7A08100C66700;
packageReferences = (
4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */,
- 4C75EFA828049C9F0006080F /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */,
4CEE2AE92805AEA300AB5EEF /* XCRemoteSwiftPackageReference "secp256k1" */,
);
productRefGroup = 4CE6DEE427F7A08100C66700 /* Products */;
@@ -357,10 +362,13 @@
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
4C75EFB328049D640006080F /* NostrEvent.swift in Sources */,
4C75EFB128049D510006080F /* NostrResponse.swift in Sources */,
+ 4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
+ 4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */,
4CEE2AEF2805BE2500AB5EEF /* NostrTimeline.swift in Sources */,
4C75EFAF28049D350006080F /* NostrFilter.swift in Sources */,
4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */,
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */,
+ 4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */,
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */,
4C75EFA427FA577B0006080F /* PostView.swift in Sources */,
@@ -705,14 +713,6 @@
/* End XCConfigurationList 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" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/daltoniam/Starscream";
@@ -732,11 +732,6 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
- 4C75EFA928049C9F0006080F /* CachedAsyncImage */ = {
- isa = XCSwiftPackageProductDependency;
- package = 4C75EFA828049C9F0006080F /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */;
- productName = CachedAsyncImage;
- };
4CE6DF1127F7A2B300C66700 /* Starscream */ = {
isa = XCSwiftPackageProductDependency;
package = 4CE6DF1027F7A2B300C66700 /* XCRemoteSwiftPackageReference "Starscream" */;
diff --git a/damus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/damus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -17,15 +17,6 @@
"revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"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
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -50,7 +50,7 @@ struct ContentView: View {
ForEach(events, id: \.id) { ev in
if ev.is_local && timeline == .debug || (timeline == .global && !ev.is_local) || (timeline == .friends && is_friend(ev.pubkey)) {
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)
}
.buttonStyle(PlainButtonStyle())
diff --git a/damus/Views/EventActionBar.swift b/damus/Views/EventActionBar.swift
@@ -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)
+ }
+}
diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift
@@ -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()
}
}
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -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)))
diff --git a/damus/Views/PowView.swift b/damus/Views/PowView.swift
@@ -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)
+}
+
diff --git a/damus/Views/ProfileName.swift b/damus/Views/ProfileName.swift
@@ -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
+ }
+}
+
diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift
@@ -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)