Skip to content

Commit de2000a

Browse files
author
Momo Ozawa
committed
Refactor: show congrats notice if needed
1 parent 90cc17e commit de2000a

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,16 @@ extension BlogDashboardViewController {
256256

257257
private func showNoticeAsNeeded() {
258258
let quickStartGuide = QuickStartTourGuide.shared
259+
259260
guard let tourToSuggest = quickStartGuide.tourToSuggest(for: blog) else {
261+
quickStartGuide.showCongratsNoticeIfNeeded(for: blog)
260262
return
261263
}
262264

263265
if quickStartGuide.tourInProgress {
264266
// If tour is in progress, show notice regardless of quickstart is shown in dashboard or my site
265267
quickStartGuide.suggest(tourToSuggest, for: blog)
266-
}
267-
else {
268+
} else {
268269
guard shouldShowQuickStartChecklist() else {
269270
return
270271
}

WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+FancyAlerts.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ extension BlogDetailsViewController {
6464

6565
private func showNoticeAsNeeded() {
6666
let quickStartGuide = QuickStartTourGuide.shared
67+
6768
guard let tourToSuggest = quickStartGuide.tourToSuggest(for: blog) else {
69+
quickStartGuide.showCongratsNoticeIfNeeded(for: blog)
6870
return
6971
}
7072

7173
if quickStartGuide.tourInProgress {
7274
// If tour is in progress, show notice regardless of quickstart is shown in dashboard or my site
7375
quickStartGuide.suggest(tourToSuggest, for: blog)
74-
}
75-
else {
76+
} else {
7677
guard shouldShowQuickStartChecklist() else {
7778
return
7879
}

WordPress/Classes/ViewRelated/Blog/QuickStartTourGuide.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ open class QuickStartTourGuide: NSObject {
2323
/// A flag indicating if the user is currently going through a tour or not.
2424
private(set) var tourInProgress = false
2525

26+
/// A flag indidcating whether we should show the congrats notice or not.
27+
private var shouldShowCongratsNotice = false
28+
2629
/// Represents the current entry point.
2730
@objc var currentEntryPoint: QuickStartTourEntryPoint = .unknown
2831

@@ -229,6 +232,22 @@ open class QuickStartTourGuide: NSObject {
229232
completed(tour: tour, for: blog, postNotification: postNotification)
230233
}
231234

235+
func showCongratsNoticeIfNeeded(for blog: Blog) {
236+
guard allToursCompleted(for: blog), shouldShowCongratsNotice else {
237+
return
238+
}
239+
240+
shouldShowCongratsNotice = false
241+
242+
let noticeStyle = QuickStartNoticeStyle(attributedMessage: nil, isDismissable: true)
243+
let notice = Notice(title: Strings.congratulationsTitle,
244+
message: Strings.congratulationsMessage,
245+
style: noticeStyle,
246+
tag: noticeTag)
247+
248+
ActionDispatcher.dispatch(NoticeAction.post(notice))
249+
}
250+
232251
// we have this because poor stupid ObjC doesn't know what the heck an optional is
233252
@objc func currentElementInt() -> Int {
234253
return currentWaypoint()?.element.rawValue ?? NSNotFound
@@ -353,6 +372,7 @@ private extension QuickStartTourGuide {
353372
WPAnalytics.track(.quickStartAllToursCompleted)
354373
grantCongratulationsAward(for: blog)
355374
tourInProgress = false
375+
shouldShowCongratsNotice = true
356376
} else {
357377
if let nextTour = tourToSuggest(for: blog) {
358378
PushNotificationsManager.shared.postNotification(for: nextTour)
@@ -448,6 +468,11 @@ private extension QuickStartTourGuide {
448468
static let quickStartDelay: DispatchTimeInterval = .milliseconds(500)
449469
static let nextStepDelay: DispatchTimeInterval = .milliseconds(1000)
450470
}
471+
472+
private enum Strings {
473+
static let congratulationsTitle = NSLocalizedString("Congrats! You know your way around", comment: "Title shown when all tours have been completed.")
474+
static let congratulationsMessage = NSLocalizedString("Doesn't it feel good to cross things off a list?", comment: "Message shown when all tours have been completed")
475+
}
451476
}
452477

453478
internal extension NSNotification.Name {

0 commit comments

Comments
 (0)