From c08c82742dfd745b59121e99fe65aff23898e153 Mon Sep 17 00:00:00 2001 From: Chris McGraw <2454408+wargcm@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:39:51 -0400 Subject: [PATCH 1/3] Add Tags Reader feed --- .../ViewRelated/Reader/ReaderHelpers.swift | 10 +++++----- .../Tab Navigation/ReaderNavigationButton.swift | 4 ++++ .../Reader/Tab Navigation/ReaderTabItem.swift | 8 ++++++++ .../reader-menu-tags.imageset/Contents.json | 15 +++++++++++++++ .../reader-menu-tags.svg | 1 + 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/Contents.json create mode 100644 WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/reader-menu-tags.svg diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift b/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift index 8463d0a4d660..e0fb342ee1ed 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift @@ -629,7 +629,7 @@ extension ReaderHelpers { static let defaultSavedItemPosition = 2 - /// Sorts the default tabs according to the order [Following, Discover, Likes], and adds the Saved tab + /// Sorts the default tabs according to the order [Discover, Subscriptions, Saved, Liked, Your Tags] class func rearrange(items: [ReaderTabItem]) -> [ReaderTabItem] { guard !items.isEmpty else { @@ -642,7 +642,6 @@ extension ReaderHelpers { return true } - // first item: Discover if topicIsDiscover(leftTopic) { return true } @@ -650,7 +649,6 @@ extension ReaderHelpers { return false } - // second item: Following/subscriptions if topicIsFollowing(leftTopic) { return true } @@ -658,7 +656,6 @@ extension ReaderHelpers { return false } - // third item: Likes if topicIsLiked(leftTopic) { return true } @@ -674,10 +671,13 @@ extension ReaderHelpers { return true } - // fourth item: Saved. It's manually inserted after the sorting let savedPosition = min(mutableItems.count, defaultSavedItemPosition) mutableItems.insert(ReaderTabItem(ReaderContent(topic: nil, contentType: .saved)), at: savedPosition) + if FeatureFlag.readerTagsFeed.enabled { + mutableItems.append(ReaderTabItem(ReaderContent(topic: nil, contentType: .tags))) + } + // in case of log in with a self hosted site, prepend a 'dummy' Following tab if !isLoggedIn() { mutableItems.insert(ReaderTabItem(ReaderContent(topic: nil, contentType: .selfHostedFollowing)), at: 0) diff --git a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift index a110dedcdaf2..d6a97376c895 100644 --- a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift +++ b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift @@ -100,6 +100,8 @@ private extension ReaderTabItem { var image: Image? { if content.type == .saved { return Image("reader-menu-saved") + } else if content.type == .tags { + return Image("reader-menu-tags") } switch content.topicType { @@ -126,6 +128,8 @@ private extension ReaderTabItem { if content.type == .saved { return "saved" + } else if content.type == .tags { + return "tags" } switch content.topicType { diff --git a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabItem.swift b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabItem.swift index de8fb60bdd21..344d602a9ac3 100644 --- a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabItem.swift +++ b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabItem.swift @@ -47,6 +47,8 @@ extension ReaderTabItem { return Titles.followingTitle case .saved: return Titles.savedTitle + case .tags: + return Titles.tagsTitle default: return Titles.emptyTitle } @@ -68,6 +70,11 @@ extension ReaderTabItem { value: "Saved", comment: "Reader navigation menu item for the Saved filter" ) + static let tagsTitle = NSLocalizedString( + "reader.navigation.menu.tags", + value: "Your Tags", + comment: "Reader navigation menu item for the Tags filter" + ) static let emptyTitle = "" } } @@ -77,6 +84,7 @@ enum ReaderContentType { case selfHostedFollowing case contentError case saved + case tags case topic } diff --git a/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/Contents.json b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/Contents.json new file mode 100644 index 000000000000..3d939b98b876 --- /dev/null +++ b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "reader-menu-tags.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/reader-menu-tags.svg b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/reader-menu-tags.svg new file mode 100644 index 000000000000..615e8845f5dc --- /dev/null +++ b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-tags.imageset/reader-menu-tags.svg @@ -0,0 +1 @@ + \ No newline at end of file From bd87d49403bc7af0227fe83e526104aaef2e763e Mon Sep 17 00:00:00 2001 From: Chris McGraw <2454408+wargcm@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:44:28 -0400 Subject: [PATCH 2/3] Separate Reader menu items into groups --- .../ReaderNavigationButton.swift | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift index d6a97376c895..e6c707ad54e1 100644 --- a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift +++ b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift @@ -6,23 +6,16 @@ struct ReaderNavigationButton: View { var body: some View { Menu { - ForEach(viewModel.filterItems, id: \.self) { item in - menuButton(for: item) - } - if viewModel.listItems.count > 0 { + ForEach(menuItemGroups, id: \.self) { group in Section { - if viewModel.listItems.count > 2 { - Menu { - ForEach(viewModel.listItems, id: \.self) { item in - menuButton(for: item) - } - } label: { - Text(Strings.lists) - } - } else { - ForEach(viewModel.listItems, id: \.self) { item in - menuButton(for: item) + ForEach(group, id: \.self) { item in + menuButton(for: item) + } + if group == menuItemGroups.last && viewModel.listItems.count > 0 { + if !FeatureFlag.readerTagsFeed.enabled { + Divider() } + listMenuItem } } } @@ -38,6 +31,38 @@ struct ReaderNavigationButton: View { } } + private var menuItemGroups: [[ReaderTabItem]] { + var items: [[ReaderTabItem]] = [[]] + var currentGroup = 0 + for item in viewModel.filterItems { + if item.content.type == .saved || item.content.type == .tags { + currentGroup += 1 + items.append([item]) + continue + } + items[currentGroup].append(item) + } + + return items + } + + @ViewBuilder + private var listMenuItem: some View { + if viewModel.listItems.count > 2 { + Menu { + ForEach(viewModel.listItems, id: \.self) { item in + menuButton(for: item) + } + } label: { + Text(Strings.lists) + } + } else { + ForEach(viewModel.listItems, id: \.self) { item in + menuButton(for: item) + } + } + } + private func menuLabel(for item: ReaderTabItem) -> some View { /// There's a bug/unexpected behavior with how `SwiftUI.Menu`'s label "twitches" when it's animated. /// Using `ZStack` is a hack to prevent the "container" view from twitching during animation. From f9a648c5fc5631a17cad6ef285f9cf13604e6bb4 Mon Sep 17 00:00:00 2001 From: Chris McGraw <2454408+wargcm@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:45:02 -0400 Subject: [PATCH 3/3] Add list menu item icon --- .../Tab Navigation/ReaderNavigationButton.swift | 6 +++++- .../reader-menu-list.imageset/Contents.json | 15 +++++++++++++++ .../reader-menu-list.svg | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/Contents.json create mode 100644 WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/reader-menu-list.svg diff --git a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift index e6c707ad54e1..47c847ca952a 100644 --- a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift +++ b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderNavigationButton.swift @@ -54,7 +54,11 @@ struct ReaderNavigationButton: View { menuButton(for: item) } } label: { - Text(Strings.lists) + HStack { + Text(Strings.lists) + Spacer() + Image("reader-menu-list") + } } } else { ForEach(viewModel.listItems, id: \.self) { item in diff --git a/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/Contents.json b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/Contents.json new file mode 100644 index 000000000000..24088906b422 --- /dev/null +++ b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "reader-menu-list.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/reader-menu-list.svg b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/reader-menu-list.svg new file mode 100644 index 000000000000..c7541872117d --- /dev/null +++ b/WordPress/Jetpack/AppImages.xcassets/Reader/reader-menu-list.imageset/reader-menu-list.svg @@ -0,0 +1 @@ + \ No newline at end of file