Show Website on profiles
Changelog-Added: Show website on profiles
This commit is contained in:
38
damus/Components/WebsiteLink.swift
Normal file
38
damus/Components/WebsiteLink.swift
Normal file
@@ -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")!)
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user