@@ -7,6 +7,8 @@ final class ReaderPostCell: UITableViewCell {
77
88 static let avatarSize : CGFloat = 28
99
10+ private var viewModel : ReaderPostCellViewModel ? // important: has to retain it
11+
1012 override init ( style: UITableViewCell . CellStyle , reuseIdentifier: String ? ) {
1113 super. init ( style: style, reuseIdentifier: reuseIdentifier)
1214
@@ -23,9 +25,8 @@ final class ReaderPostCell: UITableViewCell {
2325 }
2426
2527 private func registerActions( ) {
26- // TODO: (reader) implement actions
27-
2828 view. authorButton. addTarget ( self , action: #selector( buttonAuthorTapped) , for: . primaryActionTriggered)
29+ view. buttonMore. addTarget ( self , action: #selector( buttonMoreTapped) , for: . primaryActionTriggered)
2930 view. buttons. bookmark. addTarget ( self , action: #selector( buttonBookmarkTapped) , for: . primaryActionTriggered)
3031 view. buttons. reblog. addTarget ( self , action: #selector( buttonReblogTapped) , for: . primaryActionTriggered)
3132 view. buttons. comment. addTarget ( self , action: #selector( buttonCommentTapped) , for: . primaryActionTriggered)
@@ -35,6 +36,7 @@ final class ReaderPostCell: UITableViewCell {
3536 override func prepareForReuse( ) {
3637 super. prepareForReuse ( )
3738
39+ viewModel = nil
3840 view. prepareForReuse ( )
3941 }
4042
@@ -43,6 +45,8 @@ final class ReaderPostCell: UITableViewCell {
4345 isCompact: Bool ,
4446 isSeparatorHidden: Bool
4547 ) {
48+ self . viewModel = viewModel
49+
4650 view. isCompact = isCompact
4751 separatorInset = UIEdgeInsets ( . leading, isSeparatorHidden ? 9999 : view. insets. left)
4852 view. configure ( with: viewModel)
@@ -51,23 +55,27 @@ final class ReaderPostCell: UITableViewCell {
5155 // MARK: - Actions
5256
5357 @objc private func buttonAuthorTapped( ) {
54- print ( " author " )
58+ viewModel? . showSiteDetails ( )
59+ }
60+
61+ @objc private func buttonMoreTapped( ) {
62+ viewModel? . showMore ( with: view. buttonMore)
5563 }
5664
5765 @objc private func buttonBookmarkTapped( ) {
58- print ( " bookmark " )
66+ viewModel ? . toogleBookmark ( )
5967 }
6068
6169 @objc private func buttonReblogTapped( ) {
62- print ( " reblog " )
70+ viewModel ? . reblog ( )
6371 }
6472
6573 @objc private func buttonCommentTapped( ) {
66- print ( " comment " )
74+ viewModel ? . comment ( )
6775 }
6876
6977 @objc private func buttonLikeTapped( ) {
70- print ( " like " )
78+ viewModel ? . toggleLike ( )
7179 }
7280}
7381
@@ -102,7 +110,6 @@ private final class ReaderPostCellView: UIView {
102110
103111 private let coverAspectRatio : CGFloat = 239.0 / 358.0
104112 private var imageViewConstraints : [ NSLayoutConstraint ] = [ ]
105- private var viewModel : ReaderPostCellViewModel ? // important: has to retain it
106113 private var cancellables : [ AnyCancellable ] = [ ]
107114
108115 override init ( frame: CGRect ) {
@@ -221,15 +228,12 @@ private final class ReaderPostCellView: UIView {
221228
222229 func prepareForReuse( ) {
223230 cancellables = [ ]
224- viewModel = nil
225231 avatarView. prepareForReuse ( )
226232 imageView. prepareForReuse ( )
227233 imageView. isHidden = false
228234 }
229235
230236 func configure( with viewModel: ReaderPostCellViewModel ) {
231- self . viewModel = viewModel
232-
233237 setAvatar ( with: viewModel)
234238 authorButton. configuration? . attributedTitle = AttributedString ( viewModel. author, attributes: Self . authorAttributes)
235239 timeLabel. text = viewModel. time
@@ -241,10 +245,24 @@ private final class ReaderPostCellView: UIView {
241245 imageView. isHidden = true
242246 }
243247
248+ buttons. bookmark. configuration = {
249+ var configuration = buttons. bookmark. configuration ?? . plain( )
250+ configuration. image = UIImage ( systemName: viewModel. isBookmarked ? " bookmark.fill " : " bookmark " )
251+ configuration. baseForegroundColor = viewModel. isBookmarked ? UIAppColor . brand : . secondaryLabel
252+ return configuration
253+ } ( )
254+
244255 buttons. comment. isHidden = !viewModel. isCommentsEnabled
245256 buttons. comment. configuration? . attributedTitle = viewModel. commentCount. map { AttributedString ( $0, attributes: Self . toolbarAttributes) }
257+
246258 buttons. like. isHidden = !viewModel. isLikesEnabled
247- buttons. like. configuration? . attributedTitle = viewModel. likeCount. map { AttributedString ( $0, attributes: Self . toolbarAttributes) }
259+ buttons. like. configuration = {
260+ var configuration = buttons. like. configuration ?? . plain( )
261+ configuration. attributedTitle = viewModel. likeCount. map { AttributedString ( $0, attributes: Self . toolbarAttributes) }
262+ configuration. image = UIImage ( systemName: viewModel. isLiked ? " star.fill " : " star " )
263+ configuration. baseForegroundColor = viewModel. isLiked ? . systemYellow : . secondaryLabel
264+ return configuration
265+ } ( )
248266 }
249267
250268 private func setAvatar( with viewModel: ReaderPostCellViewModel ) {
0 commit comments