@@ -69,8 +69,7 @@ struct EventView: View {
|
||||
let profile = damus.profiles.lookup(id: event.pubkey)
|
||||
VStack {
|
||||
let pmodel = ProfileModel(pubkey: event.pubkey, damus: damus)
|
||||
let fs = damus.contacts.follow_state(event.pubkey)
|
||||
let pv = ProfileView(damus: damus, follow_state: fs, profile: pmodel)
|
||||
let pv = ProfileView(damus_state: damus, profile: pmodel)
|
||||
|
||||
NavigationLink(destination: pv) {
|
||||
ProfilePicView(pubkey: event.pubkey, size: PFP_SIZE!, highlight: highlight, image_cache: damus.image_cache, profiles: damus.profiles)
|
||||
@@ -121,10 +120,16 @@ struct EventView: View {
|
||||
Label("Copy Text", systemImage: "doc.on.doc")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = "@" + event.pubkey
|
||||
} label: {
|
||||
Label("Copy User ID", systemImage: "tag")
|
||||
}
|
||||
|
||||
Button {
|
||||
UIPasteboard.general.string = "&" + event.id
|
||||
} label: {
|
||||
Label("Copy ID", systemImage: "tag")
|
||||
Label("Copy Note ID", systemImage: "tag")
|
||||
}
|
||||
|
||||
Button {
|
||||
|
||||
44
damus/Views/FollowButtonView.swift
Normal file
44
damus/Views/FollowButtonView.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// FollowButtonView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-05-16.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FollowButtonView: View {
|
||||
let pubkey: String
|
||||
@State var follow_state: FollowState
|
||||
|
||||
var body: some View {
|
||||
Button("\(follow_btn_txt(follow_state))") {
|
||||
follow_state = perform_follow_btn_action(follow_state, target: pubkey)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.onReceive(handle_notify(.followed)) { notif in
|
||||
let pk = notif.object as! String
|
||||
if pk != pubkey {
|
||||
return
|
||||
}
|
||||
|
||||
self.follow_state = .follows
|
||||
}
|
||||
.onReceive(handle_notify(.unfollowed)) { notif in
|
||||
let pk = notif.object as! String
|
||||
if pk != pubkey {
|
||||
return
|
||||
}
|
||||
|
||||
self.follow_state = .unfollows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
struct FollowButtonView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
FollowButtonView()
|
||||
}
|
||||
}
|
||||
*/
|
||||
59
damus/Views/FollowingView.swift
Normal file
59
damus/Views/FollowingView.swift
Normal file
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// FollowingView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2022-05-16.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FollowUserView: View {
|
||||
let pubkey: String
|
||||
let damus_state: DamusState
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top) {
|
||||
let pmodel = ProfileModel(pubkey: pubkey, damus: damus_state)
|
||||
let pv = ProfileView(damus_state: damus_state, profile: pmodel)
|
||||
|
||||
NavigationLink(destination: pv) {
|
||||
ProfilePicView(pubkey: pubkey, size: PFP_SIZE!, highlight: .none, image_cache: damus_state.image_cache, profiles: damus_state.profiles)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
let profile = damus_state.profiles.lookup(id: pubkey)
|
||||
ProfileName(pubkey: pubkey, profile: profile)
|
||||
if let about = profile.flatMap { $0.about } {
|
||||
Text(about)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
FollowButtonView(pubkey: pubkey, follow_state: damus_state.contacts.follow_state(pubkey))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FollowingView: View {
|
||||
let contact: NostrEvent
|
||||
let damus_state: DamusState
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading) {
|
||||
ForEach(contact.referenced_pubkeys) { pk in
|
||||
FollowUserView(pubkey: pk.ref_id, damus_state: damus_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
struct FollowingView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
FollowingView(contact: <#NostrEvent#>, damus_state: <#DamusState#>)
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -61,9 +61,8 @@ func perform_follow_btn_action(_ fs: FollowState, target: String) -> FollowState
|
||||
}
|
||||
|
||||
struct ProfileView: View {
|
||||
let damus: DamusState
|
||||
let damus_state: DamusState
|
||||
|
||||
@State var follow_state: FollowState = .follows
|
||||
@State private var selected_tab: ProfileTab = .posts
|
||||
@StateObject var profile: ProfileModel
|
||||
|
||||
@@ -71,32 +70,13 @@ struct ProfileView: View {
|
||||
|
||||
var TopSection: some View {
|
||||
VStack(alignment: .leading) {
|
||||
let data = damus.profiles.lookup(id: profile.pubkey)
|
||||
let data = damus_state.profiles.lookup(id: profile.pubkey)
|
||||
HStack(alignment: .top) {
|
||||
ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE!, highlight: .custom(Color.black, 2), image_cache: damus.image_cache, profiles: damus.profiles)
|
||||
ProfilePicView(pubkey: profile.pubkey, size: PFP_SIZE!, highlight: .custom(Color.black, 2), image_cache: damus_state.image_cache, profiles: damus_state.profiles)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("\(follow_btn_txt(follow_state))") {
|
||||
follow_state = perform_follow_btn_action(follow_state, target: profile.pubkey)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.onReceive(handle_notify(.followed)) { notif in
|
||||
let pk = notif.object as! String
|
||||
if pk != profile.pubkey {
|
||||
return
|
||||
}
|
||||
|
||||
self.follow_state = .follows
|
||||
}
|
||||
.onReceive(handle_notify(.unfollowed)) { notif in
|
||||
let pk = notif.object as! String
|
||||
if pk != profile.pubkey {
|
||||
return
|
||||
}
|
||||
|
||||
self.follow_state = .unfollows
|
||||
}
|
||||
FollowButtonView(pubkey: profile.pubkey, follow_state: damus_state.contacts.follow_state(profile.pubkey))
|
||||
}
|
||||
|
||||
if let pubkey = profile.pubkey {
|
||||
@@ -108,7 +88,21 @@ struct ProfileView: View {
|
||||
.font(.footnote)
|
||||
.foregroundColor(id_to_color(pubkey))
|
||||
}
|
||||
|
||||
Text(data?.about ?? "")
|
||||
|
||||
if let contact = profile.contacts {
|
||||
Divider()
|
||||
|
||||
NavigationLink(destination: FollowingView(contact: contact, damus_state: damus_state)) {
|
||||
HStack {
|
||||
Text("\(profile.following)")
|
||||
Text("Following")
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +113,7 @@ struct ProfileView: View {
|
||||
|
||||
Divider()
|
||||
|
||||
InnerTimelineView(events: $profile.events, damus: damus)
|
||||
InnerTimelineView(events: $profile.events, damus: damus_state)
|
||||
}
|
||||
.frame(maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
@@ -128,7 +122,6 @@ struct ProfileView: View {
|
||||
|
||||
.navigationBarTitle("Profile")
|
||||
.onAppear() {
|
||||
follow_state = damus.contacts.follow_state(profile.pubkey)
|
||||
profile.subscribe()
|
||||
}
|
||||
.onDisappear {
|
||||
|
||||
Reference in New Issue
Block a user