From afc2069c2c8f543ad649e9971da41b26866d2e2b Mon Sep 17 00:00:00 2001 From: Lumaa Date: Sun, 11 Feb 2024 14:22:41 +0100 Subject: [PATCH] Trending posts --- Threaded/Localizable.xcstrings | 40 ++++++++++++++++++ Threaded/Views/DiscoveryView.swift | 68 +++++++++++++++++++----------- 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/Threaded/Localizable.xcstrings b/Threaded/Localizable.xcstrings index 32a6456..9183a94 100644 --- a/Threaded/Localizable.xcstrings +++ b/Threaded/Localizable.xcstrings @@ -539,6 +539,12 @@ "state" : "translated", "value" : "Found posts" } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Publications trouvées" + } } } }, @@ -549,6 +555,12 @@ "state" : "translated", "value" : "Found tags" } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Tags trouvés" + } } } }, @@ -559,6 +571,12 @@ "state" : "translated", "value" : "Found users" } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Utilisateurs trouvés" + } } } }, @@ -601,6 +619,12 @@ "state" : "translated", "value" : "Tags" } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Tags" + } } } }, @@ -636,6 +660,22 @@ } } }, + "discovery.trending.posts" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Trending Posts" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Publications en vedette" + } + } + } + }, "discovery.trending.tags" : { "localizations" : { "en" : { diff --git a/Threaded/Views/DiscoveryView.swift b/Threaded/Views/DiscoveryView.swift index 60b7140..fe56606 100644 --- a/Threaded/Views/DiscoveryView.swift +++ b/Threaded/Views/DiscoveryView.swift @@ -51,6 +51,13 @@ struct DiscoveryView: View { .padding(.horizontal) tagsView + + Text("discovery.trending.posts") + .multilineTextAlignment(.leading) + .font(.title.bold()) + .padding(.horizontal) + + statusView } } .submitLabel(.search) @@ -129,32 +136,41 @@ struct DiscoveryView: View { } var tagsView: some View { - ScrollView { - VStack(spacing: 7.5) { - ForEach(trendingTags) { tag in - HStack { - VStack(alignment: .leading) { - Text("#\(tag.name)") - .multilineTextAlignment(.leading) - .lineLimit(1) - .bold() - Text("tag.posts-\(tag.totalUses)") - .multilineTextAlignment(.leading) - .lineLimit(1) - .foregroundStyle(Color.gray) - } - - Spacer() - - Button { - // do stuff - } label: { - Text("tag.read") - } - .buttonStyle(LargeButton(filled: true, height: 7.5)) + VStack(spacing: 7.5) { + ForEach(trendingTags) { tag in + HStack { + VStack(alignment: .leading) { + Text("#\(tag.name)") + .multilineTextAlignment(.leading) + .lineLimit(1) + .bold() + Text("tag.posts-\(tag.totalUses)") + .multilineTextAlignment(.leading) + .lineLimit(1) + .foregroundStyle(Color.gray) } - .padding() + + Spacer() + + Button { + navigator.navigate(to: .timeline(timeline: .hashtag(tag: tag.name, accountId: nil))) + } label: { + Text("tag.read") + } + .buttonStyle(LargeButton(filled: true, height: 7.5, disabled: true)) + .disabled(true) } + .padding() + } + } + } + + var statusView: some View { + VStack(spacing: 7.5) { + ForEach(trendingStatuses) { status in + CompactPostView(status: status) + .padding(.vertical) + .environmentObject(navigator) } } } @@ -163,7 +179,7 @@ struct DiscoveryView: View { guard let client = accountManager.getClient(), !searchQuery.isEmpty else { return } do { try await Task.sleep(for: .milliseconds(250)) - var results: SearchResults = try await client.get(endpoint: Search.search(query: searchQuery, type: currentTokens.first?.id, offset: nil, following: nil), forceVersion: .v2) + let results: SearchResults = try await client.get(endpoint: Search.search(query: searchQuery, type: currentTokens.first?.id, offset: nil, following: nil), forceVersion: .v2) // let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: results.accounts.map(\.id))) // results.relationships = relationships withAnimation { @@ -183,6 +199,8 @@ struct DiscoveryView: View { trendingStatuses = data.trendingStatuses trendingLinks = data.trendingLinks + trendingTags = trendingTags.sorted(by: { $0.totalUses > $1.totalUses }) + suggestedAccountsRelationShips = try await client.get(endpoint: Accounts.relationships(ids: suggestedAccounts.map(\.id))) } catch { print(error)