mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-23 08:50:58 +00:00
Instantly show lists options in the user context menu when following him close #143
This commit is contained in:
parent
85e09faab1
commit
997a33df69
3 changed files with 15 additions and 3 deletions
|
@ -117,7 +117,10 @@ struct AccountDetailHeaderView: View {
|
||||||
HStack {
|
HStack {
|
||||||
FollowButton(viewModel: .init(accountId: account.id,
|
FollowButton(viewModel: .init(accountId: account.id,
|
||||||
relationship: relationship,
|
relationship: relationship,
|
||||||
shouldDisplayNotify: true))
|
shouldDisplayNotify: true,
|
||||||
|
relationshipUpdated: { relationship in
|
||||||
|
viewModel.relationship = relationship
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,8 @@ public struct AccountsListRow: View {
|
||||||
if currentAccount.account?.id != viewModel.account.id {
|
if currentAccount.account?.id != viewModel.account.id {
|
||||||
FollowButton(viewModel: .init(accountId: viewModel.account.id,
|
FollowButton(viewModel: .init(accountId: viewModel.account.id,
|
||||||
relationship: viewModel.relationShip,
|
relationship: viewModel.relationShip,
|
||||||
shouldDisplayNotify: false))
|
shouldDisplayNotify: false,
|
||||||
|
relationshipUpdated: { _ in }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
|
@ -9,13 +9,18 @@ public class FollowButtonViewModel: ObservableObject {
|
||||||
|
|
||||||
public let accountId: String
|
public let accountId: String
|
||||||
public let shouldDisplayNotify: Bool
|
public let shouldDisplayNotify: Bool
|
||||||
|
public let relationshipUpdated: ((Relationship) -> Void)
|
||||||
@Published public private(set) var relationship: Relationship
|
@Published public private(set) var relationship: Relationship
|
||||||
@Published public private(set) var isUpdating: Bool = false
|
@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.accountId = accountId
|
||||||
self.relationship = relationship
|
self.relationship = relationship
|
||||||
self.shouldDisplayNotify = shouldDisplayNotify
|
self.shouldDisplayNotify = shouldDisplayNotify
|
||||||
|
self.relationshipUpdated = relationshipUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
func follow() async {
|
func follow() async {
|
||||||
|
@ -23,6 +28,7 @@ public class FollowButtonViewModel: ObservableObject {
|
||||||
isUpdating = true
|
isUpdating = true
|
||||||
do {
|
do {
|
||||||
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false))
|
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false))
|
||||||
|
relationshipUpdated(relationship)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error while following: \(error.localizedDescription)")
|
print("Error while following: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
|
@ -34,6 +40,7 @@ public class FollowButtonViewModel: ObservableObject {
|
||||||
isUpdating = true
|
isUpdating = true
|
||||||
do {
|
do {
|
||||||
relationship = try await client.post(endpoint: Accounts.unfollow(id: accountId))
|
relationship = try await client.post(endpoint: Accounts.unfollow(id: accountId))
|
||||||
|
relationshipUpdated(relationship)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error while unfollowing: \(error.localizedDescription)")
|
print("Error while unfollowing: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
|
@ -44,6 +51,7 @@ public class FollowButtonViewModel: ObservableObject {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: !relationship.notifying))
|
relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: !relationship.notifying))
|
||||||
|
relationshipUpdated(relationship)
|
||||||
} catch {
|
} catch {
|
||||||
print("Error while following: \(error.localizedDescription)")
|
print("Error while following: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue