Skip to content

Commit

Permalink
Create specific configure functions for NoteBlockUserTableViewCell an…
Browse files Browse the repository at this point in the history
…d LikeUserTableViewCell
  • Loading branch information
justtwago committed May 10, 2024
1 parent d9779f6 commit 5d93234
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ private extension LikesListController {
return UITableViewCell()
}
cell.configure(
avatarURL: URL(string: user.avatarUrl),
username: user.displayName,
blog: String(format: Constants.usernameFormat, user.username),
user: user,
onUserClicked: { [weak self] in
self?.delegate?.didSelectUser(user, at: indexPath)
},
Expand All @@ -438,7 +436,6 @@ private extension LikesListController {
static let headerSectionIndex = 0
static let headerRowIndex = 0
static let numberOfHeaderRows = 1
static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.")
}

struct Strings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,39 +669,20 @@ private extension NotificationDetailsViewController {
return
}

let hasHomeURL = userBlock.metaLinksHome != nil
let hasHomeTitle = userBlock.metaTitlesHome?.isEmpty == false
let isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier())

if isFollowEnabled {
cell.configure(
avatarURL: userBlock.media.first?.mediaURL,
username: userBlock.text,
blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host,
isFollowed: userBlock.isActionOn(id: FollowAction.actionIdentifier()),
onUserClicked: { [weak self] in
self?.displayContent(blockGroup)
},
onFollowClicked: { [weak self] followClicked in
if followClicked {
self?.followSiteWithBlock(userBlock)
} else {
self?.unfollowSiteWithBlock(userBlock)
}
},
parent: self
)
} else {
cell.configure(
avatarURL: userBlock.media.first?.mediaURL,
username: userBlock.text,
blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host,
onUserClicked: { [weak self] in
self?.displayContent(blockGroup)
},
parent: self
)
}
cell.configure(
userBlock: userBlock,
onUserClicked: { [weak self] in
self?.displayContent(blockGroup)
},
onFollowClicked: { [weak self] followClicked in
if followClicked {
self?.followSiteWithBlock(userBlock)
} else {
self?.unfollowSiteWithBlock(userBlock)
}
},
parent: self
)
}

func setupCommentCell(_ cell: NoteBlockCommentTableViewCell, blockGroup: FormattableContentGroup, at indexPath: IndexPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ class LikeUserTableViewCell: UITableViewCell, NibReusable {

private var controller: UIHostingController<NotificationDetailUserView>?

func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) {
let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked)
host(view, parent: parent)
func configure(user: LikeUser, onUserClicked: @escaping () -> Void, parent: UIViewController) {
configure(
avatarURL: URL(string: user.avatarUrl),
username: user.displayName,
blog: String(format: Constants.usernameFormat, user.username),
onUserClicked: onUserClicked,
parent: parent)
}

func configure(
avatarURL: URL?,
username: String?,
blog: String?,
isFollowed: Bool,
isFollowed: Bool? = nil,
onUserClicked: @escaping () -> Void,
onFollowClicked: @escaping (Bool) -> Void,
onFollowClicked: @escaping (Bool) -> Void = { _ in },
parent: UIViewController
) {
let view = NotificationDetailUserView(
Expand Down Expand Up @@ -52,3 +56,10 @@ class LikeUserTableViewCell: UITableViewCell, NibReusable {
self.contentView.pinSubviewToAllEdges(view)
}
}

private extension LikeUserTableViewCell {

struct Constants {
static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,43 @@ class NoteBlockUserTableViewCell: NoteBlockTableViewCell {
shouldSetSeparators = false
}

func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) {
let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked)
host(view, parent: parent)
func configure(
userBlock: FormattableUserContent,
onUserClicked: @escaping () -> Void,
onFollowClicked: @escaping (Bool) -> Void,
parent: UIViewController
) {
let isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier())
let hasHomeTitle = userBlock.metaTitlesHome?.isEmpty == false

if isFollowEnabled {
configure(
avatarURL: userBlock.media.first?.mediaURL,
username: userBlock.text,
blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host,
isFollowed: userBlock.isActionOn(id: FollowAction.actionIdentifier()),
onUserClicked: onUserClicked,
onFollowClicked: onFollowClicked,
parent: parent
)
} else {
configure(
avatarURL: userBlock.media.first?.mediaURL,
username: userBlock.text,
blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host,
onUserClicked: onUserClicked,
parent: parent
)
}
}

func configure(
avatarURL: URL?,
username: String?,
blog: String?,
isFollowed: Bool,
isFollowed: Bool? = nil,
onUserClicked: @escaping () -> Void,
onFollowClicked: @escaping (Bool) -> Void,
onFollowClicked: @escaping (Bool) -> Void = { _ in },
parent: UIViewController
) {
let view = NotificationDetailUserView(
Expand Down

0 comments on commit 5d93234

Please sign in to comment.