11import UIKit
22
3- /// View prompting the user to create their next post
4- class BlogDashboardNextPostView : UIView {
3+ /// Card cell prompting the user to create their first post
4+ final class DashboardFirstPostCardCell : DashboardEmptyPostsCardCell , BlogDashboardCardConfigurable {
5+ func configure( blog: Blog , viewController: BlogDashboardViewController ? , apiResponse: BlogDashboardRemoteEntity ? ) {
6+ super. configure ( blog: blog, viewController: viewController, apiResponse: apiResponse, cardType: . createPost)
7+ }
8+ }
9+
10+ /// Card cell prompting the user to create their next post
11+ final class DashboardNextPostCardCell : DashboardEmptyPostsCardCell , BlogDashboardCardConfigurable {
12+ func configure( blog: Blog , viewController: BlogDashboardViewController ? , apiResponse: BlogDashboardRemoteEntity ? ) {
13+ super. configure ( blog: blog, viewController: viewController, apiResponse: apiResponse, cardType: . nextPost)
14+ }
15+ }
16+
17+ /// Card cell used when no posts are available to display
18+ class DashboardEmptyPostsCardCell : UICollectionViewCell , Reusable {
19+
20+ // MARK: Views
21+
22+ private lazy var frameView : BlogDashboardCardFrameView = {
23+ let frameView = BlogDashboardCardFrameView ( )
24+ frameView. translatesAutoresizingMaskIntoConstraints = false
25+ frameView. hideHeader ( )
26+ return frameView
27+ } ( )
28+
529 private lazy var mainStackView : UIStackView = {
630 let mainStackView = UIStackView ( )
731 mainStackView. translatesAutoresizingMaskIntoConstraints = false
@@ -54,20 +78,21 @@ class BlogDashboardNextPostView: UIView {
5478 return imageView
5579 } ( )
5680
57- var onTap : ( ( ) -> Void ) ?
81+ // MARK: Private Variables
5882
59- var hasPublishedPosts : Bool = true {
60- didSet {
61- titleLabel. text = hasPublishedPosts ? Strings . nextPostTitle : Strings . firstPostTitle
62- descriptionLabel. text = hasPublishedPosts ? Strings . nextPostDescription : Strings . firstPostDescription
63- }
64- }
83+ /// The VC presenting this cell
84+ private weak var viewController : BlogDashboardViewController ?
85+ private var blog : Blog ?
86+
87+ // MARK: Initializers
6588
6689 override init ( frame: CGRect ) {
6790 super. init ( frame: frame)
6891
69- addSubview ( mainStackView)
70- pinSubviewToAllEdges ( mainStackView)
92+ contentView. addSubview ( frameView)
93+ contentView. pinSubviewToAllEdges ( frameView, priority: Constants . constraintPriority)
94+
95+ frameView. add ( subview: mainStackView)
7196
7297 mainStackView. addArrangedSubviews ( [
7398 contentStackView,
@@ -83,19 +108,58 @@ class BlogDashboardNextPostView: UIView {
83108 addGestureRecognizer ( tap)
84109 }
85110
111+ required init ? ( coder: NSCoder ) {
112+ fatalError ( " init(coder:) has not been implemented " )
113+ }
114+
115+ // MARK: Actions
116+
86117 @objc private func promptTapped( ) {
87- onTap ? ( )
118+ presentEditor ( )
88119 }
120+ }
89121
90- required init ? ( coder: NSCoder ) {
91- fatalError ( " init(coder:) has not been implemented " )
122+ // MARK: BlogDashboardCardConfigurable
123+
124+ extension DashboardEmptyPostsCardCell {
125+ func configure( blog: Blog , viewController: BlogDashboardViewController ? , apiResponse: BlogDashboardRemoteEntity ? , cardType: DashboardCard ) {
126+ self . blog = blog
127+ self . viewController = viewController
128+
129+ switch cardType {
130+ case . createPost:
131+ titleLabel. text = Strings . firstPostTitle
132+ descriptionLabel. text = Strings . firstPostDescription
133+ case . nextPost:
134+ titleLabel. text = Strings . nextPostTitle
135+ descriptionLabel. text = Strings . nextPostDescription
136+ default :
137+ assertionFailure ( " Cell used with wrong card type " )
138+ return
139+ }
140+
141+ BlogDashboardAnalytics . shared. track ( . dashboardCardShown, properties: [ " type " : " post " , " sub_type " : cardType. rawValue] )
142+ }
143+ }
144+
145+ // MARK: Private Helpers
146+
147+ private extension DashboardEmptyPostsCardCell {
148+ func presentEditor( ) {
149+ let controller = viewController? . tabBarController as? WPTabBarController
150+ controller? . showPostTab ( )
92151 }
152+ }
153+
154+ // MARK: Constants
93155
156+ extension DashboardEmptyPostsCardCell {
94157 private enum Constants {
95158 static let horizontalSpacing : CGFloat = 16
96159 static let verticalSpacing : CGFloat = 10
97160 static let padding = UIEdgeInsets ( top: 8 , left: 16 , bottom: 8 , right: 16 )
98161 static let imageSize = CGSize ( width: 70 , height: 70 )
162+ static let constraintPriority = UILayoutPriority ( 999 )
99163 }
100164
101165 private enum Strings {
0 commit comments