commit acdee6a326ae7c7c5d7cd005318514ea463f516f
parent f5e03f145cc8706153fee2130c295284495ef524
Author: William Casarin <jb55@jb55.com>
Date: Sun, 22 Jan 2023 10:25:12 -0800
Show Website on profiles
Changelog-Added: Show website on profiles
Diffstat:
4 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -125,6 +125,7 @@
4CB88393296F798300DC99E7 /* ReactionsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88392296F798300DC99E7 /* ReactionsModel.swift */; };
4CB88396296F7F8B00DC99E7 /* ReactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88395296F7F8B00DC99E7 /* ReactionView.swift */; };
4CB8839A297322D200DC99E7 /* DMTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB88399297322D200DC99E7 /* DMTests.swift */; };
+ 4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */; };
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
@@ -345,6 +346,7 @@
4CB88392296F798300DC99E7 /* ReactionsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsModel.swift; sourceTree = "<group>"; };
4CB88395296F7F8B00DC99E7 /* ReactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionView.swift; sourceTree = "<group>"; };
4CB88399297322D200DC99E7 /* DMTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DMTests.swift; sourceTree = "<group>"; };
+ 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsiteLink.swift; sourceTree = "<group>"; };
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
@@ -640,6 +642,7 @@
4C3EA67E28FFC01D00C48A62 /* InvoiceView.swift */,
4CB8838A296F6E1E00DC99E7 /* NIP05Badge.swift */,
4CB8838C296F710400DC99E7 /* Reposted.swift */,
+ 4CBCA92F297DB57F00EC6B2F /* WebsiteLink.swift */,
);
path = Components;
sourceTree = "<group>";
@@ -976,6 +979,7 @@
4C363A9C282838B9006E126D /* EventRef.swift in Sources */,
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */,
4C3EA66528FF5F6800C48A62 /* mem.c in Sources */,
+ 4CBCA930297DB57F00EC6B2F /* WebsiteLink.swift in Sources */,
4C3EA64128FF553900C48A62 /* hash_u5.c in Sources */,
4C3EA64F28FF59F200C48A62 /* tal.c in Sources */,
4CB88393296F798300DC99E7 /* ReactionsModel.swift in Sources */,
diff --git a/damus/Components/WebsiteLink.swift b/damus/Components/WebsiteLink.swift
@@ -0,0 +1,38 @@
+//
+// WebsiteLink.swift
+// damus
+//
+// Created by William Casarin on 2023-01-22.
+//
+
+import SwiftUI
+
+struct WebsiteLink: View {
+ let url: URL
+ @Environment(\.openURL) var openURL
+
+ var body: some View {
+ HStack {
+ Image(systemName: "link")
+ .foregroundColor(.gray)
+ .font(.footnote)
+
+ Button(action: {
+ openURL(url)
+ }, label: {
+ Text(link_text)
+ .font(.footnote)
+ })
+ }
+ }
+
+ var link_text: String {
+ url.host ?? url.absoluteString
+ }
+}
+
+struct WebsiteLink_Previews: PreviewProvider {
+ static var previews: some View {
+ WebsiteLink(url: URL(string: "https://jb55.com")!)
+ }
+}
diff --git a/damus/Nostr/Nostr.swift b/damus/Nostr/Nostr.swift
@@ -53,6 +53,10 @@ struct Profile: Codable {
set(s) { value["website"] = s }
}
+ var website_url: URL? {
+ return self.website.flatMap { URL(string: $0) }
+ }
+
var lud06: String? {
get { return value["lud06"]; }
set(s) { value["lud06"] = s }
diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift
@@ -118,7 +118,8 @@ struct ProfileView: View {
@Environment(\.dismiss) var dismiss
@Environment(\.colorScheme) var colorScheme
-
+ @Environment(\.openURL) var openURL
+
// We just want to have a white "< Home" text here, however,
// setting the initialiser is causing issues, and it's late.
// Ref: https://blog.techchee.com/navigation-bar-title-style-color-and-custom-back-button-in-swiftui/
@@ -202,7 +203,7 @@ struct ProfileView: View {
ShareButton
.offset(x: geo.size.width - 80.0, y: 50.0 )
}.frame(height: BANNER_HEIGHT)
- VStack(alignment: .leading) {
+ VStack(alignment: .leading, spacing: 8.0) {
let data = damus_state.profiles.lookup(id: profile.pubkey)
let pfp_size: CGFloat = 90.0
@@ -250,6 +251,10 @@ struct ProfileView: View {
Text(ProfileView.markdown.process(data?.about ?? ""))
.font(.subheadline)
+ if let url = data?.website_url {
+ WebsiteLink(url: url)
+ }
+
Divider()
HStack {