Skip to content

Commit

Permalink
Remove remaining unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Nov 8, 2024
1 parent 81ea949 commit 2c1d3ac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 0 additions & 2 deletions WordPress/Classes/Models/ReaderDefaultTopic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ import Foundation
case recommended = "/jpios/discover/recommended"
case firstPosts = "/jpios/discover/first-posts"
case latest = "/jpios/discover/latest"
case recent = "/jpios/recent"
case liked = "/jpios/liked"
}
}
21 changes: 13 additions & 8 deletions WordPress/Classes/System/Root View/ReaderPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,20 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {

private func makeViewController(for screen: ReaderStaticScreen) -> UIViewController {
switch screen {
case .recent, .discover, .likes:
if screen == .discover {
return ReaderDiscoverViewController()
case .discover:
return ReaderDiscoverViewController()
case .recent:
// TODO: (tech debt) Fix an issue where this fails if opened before the menus are fetched for the first time
if let topic = sidebarViewModel.getRecentTopic() {
return ReaderStreamViewController.controllerWithTopic(topic)
} else {
return makeErrorViewController()
}
case .likes:
if let topic = sidebarViewModel.getLikesTopic() {
return ReaderStreamViewController.controllerWithTopic(topic)
} else {
if let topic = screen.topicType.flatMap(sidebarViewModel.getTopic) {
return ReaderStreamViewController.controllerWithTopic(topic)
} else {
return makeErrorViewController() // This should never happen
}
return makeErrorViewController()
}
case .saved:
return ReaderStreamViewController.controllerForContentType(.saved)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ struct ReaderPostMenu {
guard let topic else {
return false
}
return ReaderHelpers.isTopicTag(topic) ||
ReaderHelpers.topicIsDiscover(topic) ||
ReaderHelpers.topicIsFreshlyPressed(topic) ||
ReaderHelpers.topicIsFollowing(topic)
if ReaderHelpers.isTopicTag(topic) {
return true
}
return (topic is ReaderDefaultTopic) && !ReaderHelpers.topicIsLiked(topic)
}

// MARK: Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ final class ReaderSidebarViewModel: ObservableObject {
}
}

func getRecentTopic() -> ReaderAbstractTopic? {
try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext)
.first(where: ReaderHelpers.topicIsFollowing)
}

func getLikesTopic() -> ReaderAbstractTopic? {
try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext)
.first(where: ReaderHelpers.topicIsLiked)
}

func getTopic(for topicType: ReaderTopicType) -> ReaderAbstractTopic? {
return try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext).first {
ReaderHelpers.topicType($0) == topicType
Expand Down

0 comments on commit 2c1d3ac

Please sign in to comment.