following and unfollowing
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -68,7 +68,9 @@ struct EventView: View {
|
||||
return HStack {
|
||||
let profile = damus.profiles.lookup(id: event.pubkey)
|
||||
VStack {
|
||||
let pv = ProfileView(damus: damus, profile: ProfileModel(pubkey: event.pubkey, damus: damus))
|
||||
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)
|
||||
|
||||
NavigationLink(destination: pv) {
|
||||
ProfilePicView(pubkey: event.pubkey, size: PFP_SIZE!, highlight: highlight, image_cache: damus.image_cache, profiles: damus.profiles)
|
||||
@@ -196,3 +198,5 @@ func make_actionbar_model(ev: NostrEvent, damus: DamusState) -> ActionBarModel {
|
||||
our_tip: our_tip
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,9 +12,58 @@ enum ProfileTab: Hashable {
|
||||
case following
|
||||
}
|
||||
|
||||
enum FollowState {
|
||||
case follows
|
||||
case following
|
||||
case unfollowing
|
||||
case unfollows
|
||||
}
|
||||
|
||||
func follow_btn_txt(_ fs: FollowState) -> String {
|
||||
switch fs {
|
||||
case .follows:
|
||||
return "Unfollow"
|
||||
case .following:
|
||||
return "Following..."
|
||||
case .unfollowing:
|
||||
return "Unfollowing..."
|
||||
case .unfollows:
|
||||
return "Follow"
|
||||
}
|
||||
}
|
||||
|
||||
func follow_btn_enabled_state(_ fs: FollowState) -> Bool {
|
||||
switch fs {
|
||||
case .follows:
|
||||
return true
|
||||
case .following:
|
||||
return false
|
||||
case .unfollowing:
|
||||
return false
|
||||
case .unfollows:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func perform_follow_btn_action(_ fs: FollowState, target: String) -> FollowState {
|
||||
switch fs {
|
||||
case .follows:
|
||||
notify(.unfollow, target)
|
||||
return .following
|
||||
case .following:
|
||||
return .following
|
||||
case .unfollowing:
|
||||
return .following
|
||||
case .unfollows:
|
||||
notify(.follow, target)
|
||||
return .unfollowing
|
||||
}
|
||||
}
|
||||
|
||||
struct ProfileView: View {
|
||||
let damus: DamusState
|
||||
|
||||
@State var follow_state: FollowState = .follows
|
||||
@State private var selected_tab: ProfileTab = .posts
|
||||
@StateObject var profile: ProfileModel
|
||||
|
||||
@@ -28,8 +77,25 @@ struct ProfileView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
Button("Follow") {
|
||||
print("follow \(profile.pubkey)")
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +128,7 @@ struct ProfileView: View {
|
||||
|
||||
.navigationBarTitle("Profile")
|
||||
.onAppear() {
|
||||
follow_state = damus.contacts.follow_state(profile.pubkey)
|
||||
profile.subscribe()
|
||||
}
|
||||
.onDisappear {
|
||||
|
||||
Reference in New Issue
Block a user