From cd9d64410f984bd279c99f7591dceebfad62a91d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 16 Apr 2023 14:45:15 -0400 Subject: [PATCH] Add hashtag pinned timeline search improvements Closes #348 --- Tusker.xcodeproj/project.pbxproj | 2 +- .../AddHashtagPinnedTimelineView.swift | 63 ++++++++++++------- .../CustomizeTimelinesView.swift | 2 +- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 75881005..21bc14ca 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -974,9 +974,9 @@ D641C787213DD862004B4513 /* Compose */, D641C785213DD83B004B4513 /* Conversation */, D6F2E960249E772F005846BB /* Crash Reporter */, + D61F759729384D4200C0B37F /* Customize Timelines */, D627943C23A5635D00D38C68 /* Explore */, D6A4DCC92553666600D9DE31 /* Fast Account Switcher */, - D61F759729384D4200C0B37F /* Customize Timelines */, D641C788213DD86D004B4513 /* Large Image */, D627944B23A9A02400D38C68 /* Lists */, D627944823A6AD5100D38C68 /* Local Predicate Statuses List */, diff --git a/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift b/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift index 11156dc8..060f8002 100644 --- a/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift +++ b/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift @@ -32,6 +32,7 @@ struct AddHashtagPinnedTimelineView: View { @State private var searchTask: Task? @State private var isSearching = false @State private var searchResults: [String] = [] + @State private var trendingTags: [String] = [] private var savedAndFollowedHashtags: [String] { var tags = Set() @@ -42,17 +43,19 @@ struct AddHashtagPinnedTimelineView: View { for followed in mastodonController.followedHashtags { tags.insert(followed.name) } - return Array(tags).sorted(using: SemiCaseSensitiveComparator()) + return tags.sorted(using: SemiCaseSensitiveComparator()) } var body: some View { NavigationView { list - .listStyle(.grouped) .appGroupedListBackground(container: AddHashtagPinnedTimelineRepresentable.UIViewControllerType.self) + .listStyle(.grouped) .navigationTitle("Add Hashtag") .navigationBarTitleDisplayMode(.inline) .searchable(text: $viewModel.searchQuery, placement: .navigationBarDrawer(displayMode: .always), prompt: Text("Search for hashtags")) + .autocorrectionDisabled() + .textInputAutocapitalization(.never) .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { @@ -71,35 +74,45 @@ struct AddHashtagPinnedTimelineView: View { try? await updateSearchResults() } }) + .task { + await fetchTrendingTags() + } } - @ViewBuilder private var list: some View { - let list = List { - Section { - if viewModel.searchQuery.isEmpty { - forEachTag(savedAndFollowedHashtags) - } else { - forEachTag(searchResults) - } - } header: { + List { + if !viewModel.searchQuery.isEmpty { + Section { ProgressView() .progressViewStyle(.circular) .opacity(isSearching ? 1 : 0) + .animation(.linear(duration: 0.1), value: isSearching) .frame(maxWidth: .infinity, alignment: .center) .listRowBackground(EmptyView()) .listRowSeparator(.hidden) + + forEachTag(searchResults) + } + .appGroupedListRowBackground() + } + + if !savedAndFollowedHashtags.isEmpty { + Section { + forEachTag(savedAndFollowedHashtags) + } header: { + Text("Saved and Followed Hashtags") + } + .appGroupedListRowBackground() + } + + if !trendingTags.isEmpty { + Section { + forEachTag(trendingTags) + } header: { + Text("Trending Hashtags") + } + .appGroupedListRowBackground() } - .appGroupedListRowBackground() - } - .listStyle(.grouped) - - if #available(iOS 16.0, *) { - list - .scrollContentBackground(.hidden) - .background(Color.appGroupedBackground) - } else { - list } } @@ -126,6 +139,14 @@ struct AddHashtagPinnedTimelineView: View { searchResults = results.hashtags.map(\.name) isSearching = false } + + private func fetchTrendingTags() async { + guard mastodonController.instanceFeatures.trends else { return } + let req = Client.getTrendingHashtags() + if let (results, _) = try? await mastodonController.run(req) { + trendingTags = results.map(\.name) + } + } } private class SearchViewModel: ObservableObject { diff --git a/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift b/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift index 703fdb05..84b96b46 100644 --- a/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift +++ b/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift @@ -89,7 +89,7 @@ struct CustomizeTimelinesList: View { } } .listStyle(.insetGrouped) - .appGroupedListBackground(container: UIHostingController.self) + .appGroupedListBackground(container: UIHostingController.self) .navigationTitle(Text("Customize Timelines")) .navigationBarTitleDisplayMode(.inline) .toolbar {