mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Blocked by state
This commit is contained in:
parent
d1640fa1d2
commit
f5aacf7624
5 changed files with 32 additions and 5 deletions
|
@ -21,6 +21,7 @@
|
||||||
"account.statuses-and-replies" = "Posts & Replies";
|
"account.statuses-and-replies" = "Posts & Replies";
|
||||||
"account.media" = "Media";
|
"account.media" = "Media";
|
||||||
"account.show-reblogs" = "Show boosts";
|
"account.show-reblogs" = "Show boosts";
|
||||||
|
"account.unavailable" = "Profile unavailable";
|
||||||
"account.unblock" = "Unblock";
|
"account.unblock" = "Unblock";
|
||||||
"account.unblock.confirm-%@" = "Unblock %@?";
|
"account.unblock.confirm-%@" = "Unblock %@?";
|
||||||
"account.unfollow" = "Unfollow";
|
"account.unfollow" = "Unfollow";
|
||||||
|
|
|
@ -5,3 +5,10 @@ public struct CollectionUpdate: Hashable {
|
||||||
public let maintainScrollPositionItemId: String?
|
public let maintainScrollPositionItemId: String?
|
||||||
public let shouldAdjustContentInset: Bool
|
public let shouldAdjustContentInset: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CollectionUpdate {
|
||||||
|
static let empty: Self = Self(
|
||||||
|
sections: [],
|
||||||
|
maintainScrollPositionItemId: nil,
|
||||||
|
shouldAdjustContentInset: false)
|
||||||
|
}
|
||||||
|
|
|
@ -11,10 +11,7 @@ public class CollectionItemsViewModel: ObservableObject {
|
||||||
@Published public var alertItem: AlertItem?
|
@Published public var alertItem: AlertItem?
|
||||||
public private(set) var nextPageMaxId: String?
|
public private(set) var nextPageMaxId: String?
|
||||||
|
|
||||||
@Published private var lastUpdate = CollectionUpdate(
|
@Published private var lastUpdate = CollectionUpdate.empty
|
||||||
sections: [],
|
|
||||||
maintainScrollPositionItemId: nil,
|
|
||||||
shouldAdjustContentInset: false)
|
|
||||||
private let collectionService: CollectionService
|
private let collectionService: CollectionService
|
||||||
private var viewModelCache = [CollectionItem: (viewModel: CollectionItemViewModel, events: AnyCancellable)]()
|
private var viewModelCache = [CollectionItem: (viewModel: CollectionItemViewModel, events: AnyCancellable)]()
|
||||||
private let eventsSubject = PassthroughSubject<CollectionItemEvent, Never>()
|
private let eventsSubject = PassthroughSubject<CollectionItemEvent, Never>()
|
||||||
|
|
|
@ -67,7 +67,18 @@ extension ProfileViewModel: CollectionViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var updates: AnyPublisher<CollectionUpdate, Never> {
|
public var updates: AnyPublisher<CollectionUpdate, Never> {
|
||||||
collectionViewModel.flatMap(\.updates).eraseToAnyPublisher()
|
collectionViewModel.flatMap(\.updates)
|
||||||
|
.combineLatest($accountViewModel.map { $0?.relationship })
|
||||||
|
.map {
|
||||||
|
let (updates, relationship) = $0
|
||||||
|
|
||||||
|
if let relationship = relationship, relationship.blockedBy {
|
||||||
|
return .empty
|
||||||
|
} else {
|
||||||
|
return updates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
public var title: AnyPublisher<String, Never> {
|
public var title: AnyPublisher<String, Never> {
|
||||||
|
|
|
@ -24,6 +24,7 @@ final class AccountHeaderView: UIView {
|
||||||
let followingButton = UIButton()
|
let followingButton = UIButton()
|
||||||
let followersButton = UIButton()
|
let followersButton = UIButton()
|
||||||
let segmentedControl = UISegmentedControl()
|
let segmentedControl = UISegmentedControl()
|
||||||
|
let unavailableLabel = UILabel()
|
||||||
|
|
||||||
var viewModel: ProfileViewModel? {
|
var viewModel: ProfileViewModel? {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -47,8 +48,10 @@ final class AccountHeaderView: UIView {
|
||||||
unfollowButton.isHidden = !relationship.following
|
unfollowButton.isHidden = !relationship.following
|
||||||
|
|
||||||
relationshipButtonsStackView.isHidden = false
|
relationshipButtonsStackView.isHidden = false
|
||||||
|
unavailableLabel.isHidden = !relationship.blockedBy
|
||||||
} else {
|
} else {
|
||||||
relationshipButtonsStackView.isHidden = true
|
relationshipButtonsStackView.isHidden = true
|
||||||
|
unavailableLabel.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if accountViewModel.displayName.isEmpty {
|
if accountViewModel.displayName.isEmpty {
|
||||||
|
@ -319,6 +322,14 @@ private extension AccountHeaderView {
|
||||||
|
|
||||||
baseStackView.addArrangedSubview(segmentedControl)
|
baseStackView.addArrangedSubview(segmentedControl)
|
||||||
|
|
||||||
|
baseStackView.addArrangedSubview(unavailableLabel)
|
||||||
|
unavailableLabel.adjustsFontForContentSizeCategory = true
|
||||||
|
unavailableLabel.font = .preferredFont(forTextStyle: .title3)
|
||||||
|
unavailableLabel.textAlignment = .center
|
||||||
|
unavailableLabel.numberOfLines = 0
|
||||||
|
unavailableLabel.text = NSLocalizedString("account.unavailable", comment: "")
|
||||||
|
unavailableLabel.isHidden = true
|
||||||
|
|
||||||
let headerImageAspectRatioConstraint = headerImageView.heightAnchor.constraint(
|
let headerImageAspectRatioConstraint = headerImageView.heightAnchor.constraint(
|
||||||
equalTo: headerImageView.widthAnchor,
|
equalTo: headerImageView.widthAnchor,
|
||||||
multiplier: 1 / 3)
|
multiplier: 1 / 3)
|
||||||
|
|
Loading…
Reference in a new issue