1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

ui: Add follow button to profile action sheet

Testing: Tested on iPhone 15 Pro simulator with iOS 17.0.1

Closes: https://github.com/damus-io/damus/issues/1636
Changelog-Added: Add follow button to profile action sheet
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino 2023-10-23 23:33:02 +00:00 committed by William Casarin
parent 692d29942b
commit 9969e70b5f

View File

@ -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) {
@ -92,8 +100,9 @@ struct ProfileActionSheetView: View {
}
HStack(spacing: 20) {
self.dmButton
self.followButton
self.zapButton
self.dmButton
}
.padding()
@ -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