Skip to content

Commit

Permalink
ui: Add follow button to profile action sheet
Browse files Browse the repository at this point in the history
Testing: Tested on iPhone 15 Pro simulator with iOS 17.0.1

Closes: #1636
Changelog-Added: Add follow button to profile action sheet
Signed-off-by: Daniel D’Aquino <[email protected]>
Reviewed-by: William Casarin <[email protected]>
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
danieldaquino authored and jb55 committed Oct 24, 2023
1 parent 692d299 commit 9969e70
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion damus/Views/ProfileActionSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ struct ProfileActionSheetView: View {
return self.profile_data()?.profile
}

var followButton: some View {
return ProfileActionSheetFollowButton(
target: .pubkey(self.profile.pubkey),
follows_you: self.profile.follows(pubkey: damus_state.pubkey),
follow_state: damus_state.contacts.follow_state(profile.pubkey)
)
}

var dmButton: some View {
let dm_model = damus_state.dms.lookup_or_create(profile.pubkey)
return VStack(alignment: .center, spacing: 10) {
Expand Down Expand Up @@ -92,8 +100,9 @@ struct ProfileActionSheetView: View {
}

HStack(spacing: 20) {
self.dmButton
self.followButton
self.zapButton
self.dmButton
}
.padding()

Expand Down Expand Up @@ -129,6 +138,55 @@ struct ProfileActionSheetView: View {
}
}

fileprivate struct ProfileActionSheetFollowButton: View {
@Environment(\.colorScheme) var colorScheme

let target: FollowTarget
let follows_you: Bool
@State var follow_state: FollowState

var body: some View {
VStack(alignment: .center, spacing: 10) {
Button(
action: {
follow_state = perform_follow_btn_action(follow_state, target: target)
},
label: {
switch follow_state {
case .unfollows:
Image("user-add-down")
.foregroundColor(Color.primary)
.profile_button_style(scheme: colorScheme)
default:
Image("user-added")
.foregroundColor(Color.green)
.profile_button_style(scheme: colorScheme)
}

}
)
.buttonStyle(NeutralCircleButtonStyle())

Text(verbatim: "\(follow_btn_txt(follow_state, follows_you: follows_you))")
.foregroundStyle(.secondary)
.font(.caption)
}
.onReceive(handle_notify(.followed)) { follow in
guard case .pubkey(let pk) = follow,
pk == target.pubkey else { return }

self.follow_state = .follows
}
.onReceive(handle_notify(.unfollowed)) { unfollow in
guard case .pubkey(let pk) = unfollow,
pk == target.pubkey else { return }

self.follow_state = .unfollows
}
}
}


fileprivate struct ProfileActionSheetZapButton: View {
enum ZappingState: Equatable {
case not_zapped
Expand Down

0 comments on commit 9969e70

Please sign in to comment.