Skip to content

Commit 29bd04d

Browse files
authored
Experimental: Show trending packages on landing page (dart-lang#8755)
1 parent 5b2568a commit 29bd04d

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

app/lib/frontend/handlers/landing.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Future<shelf.Response> indexLandingHandler(shelf.Request request) async {
4343
mostPopularPackages: topPackages.mostPopular(),
4444
topFlutterPackages: topPackages.topFlutter(),
4545
topDartPackages: topPackages.topDart(),
46+
trendingPackages: topPackages.trending(),
4647
topPoWVideos: youtubeBackend.getTopPackageOfWeekVideos(count: 4),
4748
);
4849
}

app/lib/frontend/templates/landing.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ String renderLandingPage({
1414
List<PackageView>? mostPopularPackages,
1515
List<PackageView>? topFlutterPackages,
1616
List<PackageView>? topDartPackages,
17+
List<PackageView>? trendingPackages,
1718
List<PkgOfWeekVideo>? topPoWVideos,
1819
}) {
1920
final content = landingPageNode(
2021
ffPackages: ffPackages,
2122
mostPopularPackages: mostPopularPackages,
2223
topFlutterPackages: topFlutterPackages,
2324
topDartPackages: topDartPackages,
25+
trendingPackages: trendingPackages,
2426
topPoWVideos: topPoWVideos,
2527
);
2628
return renderLayoutPage(

app/lib/frontend/templates/views/landing/page.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:_pub_shared/search/search_form.dart';
66
import 'package:_pub_shared/search/tags.dart';
7+
import 'package:pub_dev/frontend/request_context.dart';
78

89
import '../../../../package/models.dart';
910
import '../../../../service/youtube/backend.dart';
@@ -20,6 +21,7 @@ d.Node landingPageNode({
2021
List<PackageView>? mostPopularPackages,
2122
List<PackageView>? topFlutterPackages,
2223
List<PackageView>? topDartPackages,
24+
List<PackageView>? trendingPackages,
2325
List<PkgOfWeekVideo>? topPoWVideos,
2426
}) {
2527
return d.fragment([
@@ -34,7 +36,23 @@ d.Node landingPageNode({
3436
viewAllEvent: 'landing-flutter-favorites-view-all',
3537
viewAllTitle: 'Search Flutter Favorites packages',
3638
),
37-
if (_isNotEmptyList(mostPopularPackages))
39+
if (requestContext.experimentalFlags.showTrending &&
40+
_isNotEmptyList(trendingPackages))
41+
_block(
42+
shortId: 'mp',
43+
image: d.Image.decorative(
44+
src: staticUrls.getAssetUrl('/static/img/landing-01.webp'),
45+
width: 351,
46+
height: 240,
47+
),
48+
title: 'Trending packages',
49+
info: d.text('Some of the packages trending in the last 30 days'),
50+
content: miniListNode('most-trending', trendingPackages!),
51+
viewAllUrl: urls.listingByTrending(),
52+
viewAllEvent: 'landing-trending-view-all',
53+
viewAllTitle: 'Search trending packages',
54+
)
55+
else if (_isNotEmptyList(mostPopularPackages))
3856
_block(
3957
shortId: 'mp',
4058
image: d.Image.decorative(

app/lib/search/top_packages.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class TopPackages {
3030
);
3131
final _mostPopular =
3232
_cachedValue('top-packages-most-popular', order: SearchOrder.downloads);
33+
final _trending =
34+
_cachedValue('top-packages-trending', order: SearchOrder.trending);
3335
final _topDart = _cachedValue('top-packages-top-dart', query: SdkTag.sdkDart);
3436
final _topFlutter =
3537
_cachedValue('top-packages-top-flutter', query: SdkTag.sdkFlutter);
@@ -89,6 +91,10 @@ class TopPackages {
8991
return _randomSelection(_topFlutter, 6);
9092
}
9193

94+
List<PackageView> trending() {
95+
return _randomSelection(_trending, 6);
96+
}
97+
9298
List<PackageView> _randomSelection(
9399
CachedValue<List<PackageView>> cachedValue, int count) {
94100
if (!cachedValue.isAvailable) {

app/lib/shared/urls.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ String searchUrl({
206206
String listingByDownloadCounts() =>
207207
SearchForm(order: SearchOrder.downloads).toSearchLink();
208208

209+
String listingByTrending() =>
210+
SearchForm(order: SearchOrder.trending).toSearchLink();
211+
209212
String dartSdkMainUrl(String version) {
210213
final isDev = version.contains('dev');
211214
final channel = isDev ? 'dev' : 'stable';

0 commit comments

Comments
 (0)