Skip to content

Commit

Permalink
Reader: Add empty state for tags feed (#23132)
Browse files Browse the repository at this point in the history
  • Loading branch information
wargcm authored May 1, 2024
2 parents 3278259 + 9985ba3 commit e2b37e3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ class ReaderCardsStreamViewController: ReaderStreamViewController {
return ReaderCardService()
}()

/// Tracks whether or not we should force sync
/// This is set to true after the Reader Manage view is dismissed
private var shouldForceRefresh = false

private lazy var selectInterestsViewController: ReaderSelectInterestsViewController = {
let title = NSLocalizedString("Discover and follow blogs you love", comment: "Reader select interests title label text")
let subtitle = NSLocalizedString(
"reader.select.tags.subtitle",
value: "Choose your tags",
comment: "Reader select interests subtitle label text"
)
let buttonTitleEnabled = NSLocalizedString("Done", comment: "Reader select interests next button enabled title text")
let buttonTitleDisabled = NSLocalizedString("Select a few to continue", comment: "Reader select interests next button disabled title text")
let loading = NSLocalizedString("Finding blogs and stories you’ll love...", comment: "Label displayed to the user while loading their selected interests")

let configuration = ReaderSelectInterestsConfiguration(
title: title,
subtitle: subtitle,
buttonTitle: (enabled: buttonTitleEnabled, disabled: buttonTitleDisabled),
loading: loading
)

return ReaderSelectInterestsViewController(configuration: configuration)
}()

/// Whether the current view controller is visible
private var isVisible: Bool {
return isViewLoaded && view.window != nil
Expand Down Expand Up @@ -261,46 +236,6 @@ private extension ReaderCardsStreamViewController {
}
}
}

func hideSelectInterestsView() {
guard selectInterestsViewController.parent != nil else {
if shouldForceRefresh {
scrollViewToTop()
displayLoadingStream()
super.syncIfAppropriate(forceSync: true)
shouldForceRefresh = false
}

return
}

scrollViewToTop()
displayLoadingStream()
super.syncIfAppropriate(forceSync: true)

UIView.animate(withDuration: 0.2, animations: {
self.selectInterestsViewController.view.alpha = 0
}) { _ in
self.selectInterestsViewController.remove()
self.selectInterestsViewController.view.alpha = 1
}
}

func showSelectInterestsView() {
guard selectInterestsViewController.parent == nil else {
return
}

selectInterestsViewController.view.frame = self.view.bounds
self.add(selectInterestsViewController)

selectInterestsViewController.didSaveInterests = { [weak self] _ in
guard let self else {
return
}
self.hideSelectInterestsView()
}
}
}

// MARK: - ReaderTopicsTableCardCellDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,45 @@ import AutomatticTracks
// The set object flags each tag in the stream so that we know whether or not we've fetched the remote data for the tag.
// We need to ensure that we only fetch the remote data once per tag to avoid the resultsController from refreshing the table view indefinitely.
private var tagStreamSyncTracker = Set<String>()
lazy var selectInterestsViewController: ReaderSelectInterestsViewController = {
let title = NSLocalizedString(
"reader.select.tags.title",
value: "Discover and follow blogs you love",
comment: "Reader select interests title label text"
)
let subtitle = NSLocalizedString(
"reader.select.tags.subtitle",
value: "Choose your tags",
comment: "Reader select interests subtitle label text"
)
let buttonTitleEnabled = NSLocalizedString(
"reader.select.tags.done",
value: "Done",
comment: "Reader select interests next button enabled title text"
)
let buttonTitleDisabled = NSLocalizedString(
"reader.select.tags.continue",
value: "Select a few to continue",
comment: "Reader select interests next button disabled title text"
)
let loading = NSLocalizedString(
"reader.select.tags.loading",
value: "Finding blogs and stories you’ll love...",
comment: "Label displayed to the user while loading their selected interests"
)

let configuration = ReaderSelectInterestsConfiguration(
title: title,
subtitle: subtitle,
buttonTitle: (enabled: buttonTitleEnabled, disabled: buttonTitleDisabled),
loading: loading
)

return ReaderSelectInterestsViewController(configuration: configuration)
}()
/// Tracks whether or not we should force sync
/// This is set to true after the Reader Manage view is dismissed
var shouldForceRefresh = false

// MARK: - Factory Methods

Expand Down Expand Up @@ -680,6 +719,8 @@ import AutomatticTracks
displayNoResultsView()
} else if contentType == .saved, content.isEmpty {
displayNoResultsView()
} else if contentType == .tags, content.isEmpty {
showSelectInterestsView()
}
}

Expand Down Expand Up @@ -1836,6 +1877,8 @@ extension ReaderStreamViewController {
displayNoResultsForSavedPosts()
} else if contentType == .topic && siteID == ReaderHelpers.discoverSiteID {
displayNoResultsViewForDiscover()
} else if contentType == .tags {
showSelectInterestsView()
}
return
}
Expand Down Expand Up @@ -1918,7 +1961,53 @@ extension ReaderStreamViewController {
hideGhost()
}

func showSelectInterestsView() {
guard selectInterestsViewController.parent == nil else {
return
}

selectInterestsViewController.view.frame = self.view.bounds
self.add(selectInterestsViewController)

selectInterestsViewController.didSaveInterests = { [weak self] _ in
guard let self else {
return
}
self.hideSelectInterestsView()
}
}

func hideSelectInterestsView(showLoadingStream: Bool = true) {
let isTagsFeed = contentType == .tags
guard selectInterestsViewController.parent != nil else {
if shouldForceRefresh {
scrollViewToTop()
if !isTagsFeed {
displayLoadingStream()
}
syncIfAppropriate(forceSync: true)
shouldForceRefresh = false
}

return
}

scrollViewToTop()
if !isTagsFeed {
displayLoadingStream()
}
syncIfAppropriate(forceSync: true)

UIView.animate(withDuration: 0.2, animations: {
self.selectInterestsViewController.view.alpha = 0
}) { _ in
self.selectInterestsViewController.remove()
self.selectInterestsViewController.view.alpha = 1
}
}

func hideResultsStatus() {
hideSelectInterestsView()
resultsStatusView.removeFromView()
footerView.isHidden = false
tableView.tableHeaderView?.isHidden = false
Expand Down

0 comments on commit e2b37e3

Please sign in to comment.