From 9969e70b5ff3187dd0a5f95d3661c0b7d3d6298f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Mon, 23 Oct 2023 23:33:02 +0000 Subject: [PATCH] ui: Add follow button to profile action sheet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: William Casarin Signed-off-by: William Casarin --- damus/Views/ProfileActionSheetView.swift | 60 +++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/damus/Views/ProfileActionSheetView.swift b/damus/Views/ProfileActionSheetView.swift index 3de8276e1..d89288944 100644 --- a/damus/Views/ProfileActionSheetView.swift +++ b/damus/Views/ProfileActionSheetView.swift @@ -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