Add scope bar for search in explore screen

This commit is contained in:
Thomas Ricouard 2023-07-18 08:52:10 +02:00
parent 4943a1708c
commit 47cf849f21
21 changed files with 102 additions and 3 deletions

View file

@ -346,6 +346,10 @@
"explore.section.trending.posts" = "Трэндавыя допісы";
"explore.section.trending.tags" = "Трэндавыя тэгі";
"explore.section.users" = "Карыстальнікі";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Адзін голас";

View file

@ -340,6 +340,10 @@
"explore.section.trending.posts" = "Publicacions populars";
"explore.section.trending.tags" = "Etiquetes populars";
"explore.section.users" = "Usuaris";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Vot únic";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Beiträge im Trend";
"explore.section.trending.tags" = "Hashtags im Trend";
"explore.section.users" = "Profile";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Einfache Auswahl";

View file

@ -343,6 +343,10 @@
"explore.section.trending.posts" = "Trending Posts";
"explore.section.trending.tags" = "Trending Tags";
"explore.section.users" = "Users";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "One Vote";

View file

@ -342,6 +342,10 @@
"explore.section.trending.posts" = "Trending Posts";
"explore.section.trending.tags" = "Trending Tags";
"explore.section.users" = "Users";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "One Vote";

View file

@ -342,6 +342,10 @@
"explore.section.trending.posts" = "Publicaciones que son tendencia";
"explore.section.trending.tags" = "Etiquetas que son tendencia";
"explore.section.users" = "Usuarios";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Un voto";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Bogan dauden bidalketak";
"explore.section.trending.tags" = "Pil-pilean dauden traolak";
"explore.section.users" = "Erabiltzaileak";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Boto bakarra";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Publications tendance";
"explore.section.trending.tags" = "Étiquettes tendance";
"explore.section.users" = "Utilisateurs";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Un vote";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Post di tendenza";
"explore.section.trending.tags" = "Tag di tendenza";
"explore.section.users" = "Utenti";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Voto singolo";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "人気の投稿";
"explore.section.trending.tags" = "人気のタグ";
"explore.section.users" = "ユーザー";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "単一投票";

View file

@ -343,6 +343,10 @@
"explore.section.trending.posts" = "뜨고 있는 글";
"explore.section.trending.tags" = "뜨고 있는 태그";
"explore.section.users" = "사용자";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "하나만 선택 가능";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Trendende innlegg";
"explore.section.trending.tags" = "Trendende tagger";
"explore.section.users" = "Brukere";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Én stemme";

View file

@ -339,6 +339,10 @@
"explore.section.trending.posts" = "Trending posts";
"explore.section.trending.tags" = "Trending hashtags";
"explore.section.users" = "Gebruikers";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Eén stem";

View file

@ -338,6 +338,10 @@
"explore.section.trending.posts" = "Popularne posty";
"explore.section.trending.tags" = "Popularne hasztagi";
"explore.section.users" = "Osoby";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Jeden głos";

View file

@ -341,6 +341,10 @@
"explore.section.trending.posts" = "Postagens em Tendência";
"explore.section.trending.tags" = "Hashtags em Tendência";
"explore.section.users" = "Usuários";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Um Voto";

View file

@ -337,6 +337,10 @@
"explore.section.trending.posts" = "Yükselişteki Gönderiler";
"explore.section.trending.tags" = "Yükselişteki Etiketler";
"explore.section.users" = "Kullanıcılar";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Bir oy";

View file

@ -342,6 +342,10 @@
"explore.section.trending.posts" = "Популярні дописи";
"explore.section.trending.tags" = "Популярні хештеґи";
"explore.section.users" = "Користувачі";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "Лише один варіант";

View file

@ -340,6 +340,10 @@
"explore.section.trending.posts" = "当下流行的嘟文";
"explore.section.trending.tags" = "当下流行的标签";
"explore.section.users" = "用户";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "单个投票";

View file

@ -343,6 +343,10 @@
"explore.section.trending.posts" = "流行嘟文";
"explore.section.trending.tags" = "流行標籤";
"explore.section.users" = "用戶";
"explore.scope.all" = "All";
"explore.scope.people" = "People";
"explore.scope.hashtags" = "Hashtags";
"explore.scope.posts" = "Posts";
// MARK: Package: Env
"env.poll-vote-frequency.one" = "單一選擇";

View file

@ -84,6 +84,11 @@ public struct ExploreView: View {
.searchable(text: $viewModel.searchQuery,
placement: .navigationBarDrawer(displayMode: .always),
prompt: Text("explore.search.prompt"))
.searchScopes($viewModel.searchScope) {
ForEach(ExploreViewModel.SearchScope.allCases, id: \.self) { scope in
Text(scope.localizedString)
}
}
}
private var quickAccessView: some View {
@ -121,7 +126,7 @@ public struct ExploreView: View {
@ViewBuilder
private func makeSearchResultsView(results: SearchResults) -> some View {
if !results.accounts.isEmpty {
if !results.accounts.isEmpty && (viewModel.searchScope == .all || viewModel.searchScope == .people) {
Section("explore.section.users") {
ForEach(results.accounts) { account in
if let relationship = results.relationships.first(where: { $0.id == account.id }) {
@ -131,7 +136,7 @@ public struct ExploreView: View {
}
}
}
if !results.hashtags.isEmpty {
if !results.hashtags.isEmpty && (viewModel.searchScope == .all || viewModel.searchScope == .hashtags) {
Section("explore.section.tags") {
ForEach(results.hashtags) { tag in
TagRowView(tag: tag)
@ -140,7 +145,7 @@ public struct ExploreView: View {
}
}
}
if !results.statuses.isEmpty {
if !results.statuses.isEmpty && (viewModel.searchScope == .all || viewModel.searchScope == .posts) {
Section("explore.section.posts") {
ForEach(results.statuses) { status in
StatusRowView(viewModel: { .init(status: status, client: client, routerPath: routerPath) })

View file

@ -5,6 +5,23 @@ import SwiftUI
@MainActor
class ExploreViewModel: ObservableObject {
enum SearchScope: String, CaseIterable {
case all, people, hashtags, posts
var localizedString: LocalizedStringKey {
switch self {
case .all:
return .init("explore.scope.all")
case .people:
return .init("explore.scope.people")
case .hashtags:
return .init("explore.scope.hashtags")
case .posts:
return .init("explore.scope.posts")
}
}
}
var client: Client? {
didSet {
if oldValue != client {
@ -36,6 +53,7 @@ class ExploreViewModel: ObservableObject {
@Published var trendingTags: [Tag] = []
@Published var trendingStatuses: [Status] = []
@Published var trendingLinks: [Card] = []
@Published var searchScope: SearchScope = .all
private var searchTask: Task<Void, Never>?
private var cancellables = Set<AnyCancellable>()