Instantly show lists options in the user context menu when following him close #143

This commit is contained in:
Thomas Ricouard 2023-01-20 18:53:07 +01:00
parent 85e09faab1
commit 997a33df69
3 changed files with 15 additions and 3 deletions

View file

@ -117,7 +117,10 @@ struct AccountDetailHeaderView: View {
HStack {
FollowButton(viewModel: .init(accountId: account.id,
relationship: relationship,
shouldDisplayNotify: true))
shouldDisplayNotify: true,
relationshipUpdated: { relationship in
viewModel.relationship = relationship
}))
}
}
}

View file

@ -50,7 +50,8 @@ public struct AccountsListRow: View {
if currentAccount.account?.id != viewModel.account.id {
FollowButton(viewModel: .init(accountId: viewModel.account.id,
relationship: viewModel.relationShip,
shouldDisplayNotify: false))
shouldDisplayNotify: false,
relationshipUpdated: { _ in }))
}
}
.onAppear {

View file

@ -9,13 +9,18 @@ public class FollowButtonViewModel: ObservableObject {
public let accountId: String
public let shouldDisplayNotify: Bool
public let relationshipUpdated: ((Relationship) -> Void)
@Published public private(set) var relationship: Relationship
@Published public private(set) var isUpdating: Bool = false
public init(accountId: String, relationship: Relationship, shouldDisplayNotify: Bool) {
public init(accountId: String,
relationship: Relationship,
shouldDisplayNotify: Bool,
relationshipUpdated: @escaping ((Relationship) -> Void)) {
self.accountId = accountId
self.relationship = relationship
self.shouldDisplayNotify = shouldDisplayNotify
self.relationshipUpdated = relationshipUpdated
}
func follow() async {
@ -23,6 +28,7 @@ public class FollowButtonViewModel: ObservableObject {
isUpdating = true
do {
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false))
relationshipUpdated(relationship)
} catch {
print("Error while following: \(error.localizedDescription)")
}
@ -34,6 +40,7 @@ public class FollowButtonViewModel: ObservableObject {
isUpdating = true
do {
relationship = try await client.post(endpoint: Accounts.unfollow(id: accountId))
relationshipUpdated(relationship)
} catch {
print("Error while unfollowing: \(error.localizedDescription)")
}
@ -44,6 +51,7 @@ public class FollowButtonViewModel: ObservableObject {
guard let client else { return }
do {
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: !relationship.notifying))
relationshipUpdated(relationship)
} catch {
print("Error while following: \(error.localizedDescription)")
}