Properly update button-state when following people (IOS-194)

This commit is contained in:
Nathan Mattes 2023-11-20 13:59:25 +01:00
parent 601d52c28f
commit 6cf5134ff6
2 changed files with 13 additions and 4 deletions

View File

@ -30,15 +30,18 @@ extension DataSourceFacade {
static func responseToUserFollowAction(
dependency: NeedsDependency & AuthContextProvider,
user: Mastodon.Entity.Account
) async throws {
) async throws -> Mastodon.Entity.Relationship {
let selectionFeedbackGenerator = await UISelectionFeedbackGenerator()
await selectionFeedbackGenerator.selectionChanged()
_ = try await dependency.context.apiService.toggleFollow(
let response = try await dependency.context.apiService.toggleFollow(
user: user,
authenticationBox: dependency.authContext.mastodonAuthenticationBox
)
).value
dependency.context.authenticationService.fetchFollowingAndBlockedAsync()
return response
}
}

View File

@ -115,8 +115,14 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate {
guard let indexPath = tableView.indexPath(for: cell) else { return }
guard case let .account(account, _) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return }
cell.profileCardView.setButtonState(.loading)
Task {
try await DataSourceFacade.responseToUserFollowAction(dependency: self, user: account)
let newRelationship = try await DataSourceFacade.responseToUserFollowAction(dependency: self, user: account)
await MainActor.run {
cell.profileCardView.updateButtonState(with: newRelationship, isMe: false)
}
}
}