Trending posts

This commit is contained in:
Lumaa 2024-02-11 14:22:41 +01:00
parent 79bf9a0486
commit afc2069c2c
2 changed files with 83 additions and 25 deletions

View File

@ -539,6 +539,12 @@
"state" : "translated", "state" : "translated",
"value" : "Found posts" "value" : "Found posts"
} }
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Publications trouvées"
}
} }
} }
}, },
@ -549,6 +555,12 @@
"state" : "translated", "state" : "translated",
"value" : "Found tags" "value" : "Found tags"
} }
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Tags trouvés"
}
} }
} }
}, },
@ -559,6 +571,12 @@
"state" : "translated", "state" : "translated",
"value" : "Found users" "value" : "Found users"
} }
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Utilisateurs trouvés"
}
} }
} }
}, },
@ -601,6 +619,12 @@
"state" : "translated", "state" : "translated",
"value" : "Tags" "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" : { "discovery.trending.tags" : {
"localizations" : { "localizations" : {
"en" : { "en" : {

View File

@ -51,6 +51,13 @@ struct DiscoveryView: View {
.padding(.horizontal) .padding(.horizontal)
tagsView tagsView
Text("discovery.trending.posts")
.multilineTextAlignment(.leading)
.font(.title.bold())
.padding(.horizontal)
statusView
} }
} }
.submitLabel(.search) .submitLabel(.search)
@ -129,32 +136,41 @@ struct DiscoveryView: View {
} }
var tagsView: some View { var tagsView: some View {
ScrollView { VStack(spacing: 7.5) {
VStack(spacing: 7.5) { ForEach(trendingTags) { tag in
ForEach(trendingTags) { tag in HStack {
HStack { VStack(alignment: .leading) {
VStack(alignment: .leading) { Text("#\(tag.name)")
Text("#\(tag.name)") .multilineTextAlignment(.leading)
.multilineTextAlignment(.leading) .lineLimit(1)
.lineLimit(1) .bold()
.bold() Text("tag.posts-\(tag.totalUses)")
Text("tag.posts-\(tag.totalUses)") .multilineTextAlignment(.leading)
.multilineTextAlignment(.leading) .lineLimit(1)
.lineLimit(1) .foregroundStyle(Color.gray)
.foregroundStyle(Color.gray)
}
Spacer()
Button {
// do stuff
} label: {
Text("tag.read")
}
.buttonStyle(LargeButton(filled: true, height: 7.5))
} }
.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 } guard let client = accountManager.getClient(), !searchQuery.isEmpty else { return }
do { do {
try await Task.sleep(for: .milliseconds(250)) 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))) // let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: results.accounts.map(\.id)))
// results.relationships = relationships // results.relationships = relationships
withAnimation { withAnimation {
@ -183,6 +199,8 @@ struct DiscoveryView: View {
trendingStatuses = data.trendingStatuses trendingStatuses = data.trendingStatuses
trendingLinks = data.trendingLinks trendingLinks = data.trendingLinks
trendingTags = trendingTags.sorted(by: { $0.totalUses > $1.totalUses })
suggestedAccountsRelationShips = try await client.get(endpoint: Accounts.relationships(ids: suggestedAccounts.map(\.id))) suggestedAccountsRelationShips = try await client.get(endpoint: Accounts.relationships(ids: suggestedAccounts.map(\.id)))
} catch { } catch {
print(error) print(error)