Edit button on account page

This commit is contained in:
Thomas
2022-12-23 17:37:21 +01:00
parent dff450282b
commit 749b97e663
3 changed files with 31 additions and 7 deletions

View File

@@ -13,9 +13,14 @@ struct FollowButtonView: View {
let target: FollowTarget let target: FollowTarget
@State var follow_state: FollowState @State var follow_state: FollowState
let perform: (() -> Void)?
var body: some View { var body: some View {
Button { Button {
if perform != nil {
perform!()
}
follow_state = perform_follow_btn_action(follow_state, target: target) follow_state = perform_follow_btn_action(follow_state, target: target)
} label: { } label: {
Text(follow_btn_txt(follow_state)) Text(follow_btn_txt(follow_state))
@@ -66,16 +71,19 @@ struct FollowButtonPreviews: View {
var body: some View { var body: some View {
VStack { VStack {
Text("Unfollows") Text("Unfollows")
FollowButtonView(target: target, follow_state: .unfollows) FollowButtonView(target: target, follow_state: .unfollows, perform: nil)
Text("Following") Text("Following")
FollowButtonView(target: target, follow_state: .following) FollowButtonView(target: target, follow_state: .following, perform: nil)
Text("Follows") Text("Follows")
FollowButtonView(target: target, follow_state: .follows) FollowButtonView(target: target, follow_state: .follows, perform: nil)
Text("Unfollowing") Text("Unfollowing")
FollowButtonView(target: target, follow_state: .unfollowing) FollowButtonView(target: target, follow_state: .unfollowing, perform: nil)
Text("Edit")
FollowButtonView(target: target, follow_state: .edit, perform: nil)
} }
} }
} }
@@ -98,6 +106,8 @@ func perform_follow_btn_action(_ fs: FollowState, target: FollowTarget) -> Follo
case .unfollows: case .unfollows:
notify(.follow, target) notify(.follow, target)
return .unfollowing return .unfollowing
case .edit:
return .edit
} }
} }

View File

@@ -32,7 +32,7 @@ struct FollowUserView: View {
} }
.buttonStyle(PlainButtonStyle()) .buttonStyle(PlainButtonStyle())
FollowButtonView(target: target, follow_state: damus_state.contacts.follow_state(target.pubkey)) FollowButtonView(target: target, follow_state: damus_state.contacts.follow_state(target.pubkey), perform: nil)
} }
} }
} }

View File

@@ -17,6 +17,7 @@ enum FollowState {
case following case following
case unfollowing case unfollowing
case unfollows case unfollows
case edit
} }
func follow_btn_txt(_ fs: FollowState) -> String { func follow_btn_txt(_ fs: FollowState) -> String {
@@ -29,6 +30,8 @@ func follow_btn_txt(_ fs: FollowState) -> String {
return "Unfollowing..." return "Unfollowing..."
case .unfollows: case .unfollows:
return "Follow" return "Follow"
case .edit:
return "Edit"
} }
} }
@@ -42,6 +45,8 @@ func follow_btn_enabled_state(_ fs: FollowState) -> Bool {
return false return false
case .unfollows: case .unfollows:
return true return true
case .edit:
return true
} }
} }
@@ -83,6 +88,7 @@ struct ProfileView: View {
@State private var selected_tab: ProfileTab = .posts @State private var selected_tab: ProfileTab = .posts
@StateObject var profile: ProfileModel @StateObject var profile: ProfileModel
@StateObject var followers: FollowersModel @StateObject var followers: FollowersModel
@State private var showingSheet = false
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
@Environment(\.colorScheme) var colorScheme @Environment(\.colorScheme) var colorScheme
@@ -127,7 +133,15 @@ struct ProfileView: View {
DMButton DMButton
FollowButtonView(target: profile.get_follow_target(), follow_state: damus_state.contacts.follow_state(profile.pubkey))
FollowButtonView(
target: profile.get_follow_target(),
follow_state: profile.pubkey == damus_state.pubkey ? .edit : damus_state.contacts.follow_state(profile.pubkey),
perform: profile.pubkey == damus_state.pubkey ? { showingSheet.toggle() } : nil
)
}.sheet(isPresented: $showingSheet) {
MetadataView(damus_state: damus_state, profileModel: profile)
} }
ProfileNameView(pubkey: profile.pubkey, profile: data, contacts: damus_state.contacts) ProfileNameView(pubkey: profile.pubkey, profile: data, contacts: damus_state.contacts)
@@ -211,7 +225,7 @@ func test_damus_state() -> DamusState {
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681" let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(), tips: TipCounter(our_pubkey: pubkey), profiles: Profiles(), dms: DirectMessagesModel()) let damus = DamusState(pool: RelayPool(), keypair: Keypair(pubkey: pubkey, privkey: "privkey"), likes: EventCounter(our_pubkey: pubkey), boosts: EventCounter(our_pubkey: pubkey), contacts: Contacts(), tips: TipCounter(our_pubkey: pubkey), profiles: Profiles(), dms: DirectMessagesModel())
let prof = Profile(name: "damus", display_name: "Damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", website: "https://damus.io", nip05: "jb@damus.io", lud06: nil, lud16: "jb55@sendsats.lol") let prof = Profile(name: "damus", display_name: "Damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", website: "https://damus.io", nip05: nil, lud06: nil, lud16: "jb55@sendsats.lol")
let tsprof = TimestampedProfile(profile: prof, timestamp: 0) let tsprof = TimestampedProfile(profile: prof, timestamp: 0)
damus.profiles.add(id: pubkey, profile: tsprof) damus.profiles.add(id: pubkey, profile: tsprof)
return damus return damus