added popular sites module

This commit is contained in:
Fabian Freund
2026-06-29 08:55:43 +02:00
parent da7712bc80
commit a1ed66b392
24 changed files with 1441 additions and 5 deletions
@@ -44,7 +44,7 @@ final class EngineSettingsReplicationServiceProvider
}
String _$engineSettingsReplicationServiceHash() =>
r'00439944023e8336dc879c70bb578120e221676d';
r'a3d7628b7662ca8b828586e3fcf4e8925adbe062';
abstract class _$EngineSettingsReplicationService extends $Notifier<void> {
void build();
@@ -28,6 +28,7 @@ const _$SearchModuleTypeEnumMap = {
SearchModuleType.history: 'history',
SearchModuleType.localHistory: 'localHistory',
SearchModuleType.combinedHistory: 'combinedHistory',
SearchModuleType.popularSites: 'popularSites',
SearchModuleType.historyHighlights: 'historyHighlights',
SearchModuleType.topSites: 'topSites',
SearchModuleType.recentHistory: 'recentHistory',
@@ -49,6 +49,13 @@ enum SearchModuleType {
/// enabling [history] and [localHistory] separately.
combinedHistory,
/// Popular-domain prefix completions from the bundled Tranco-derived
/// `sites.db` asset (filtered against adult/gambling + tracker/CDN lists).
/// Static popularity data, ranked below history and bookmarks so
/// visited/saved sites always win. Domain autocomplete: typing "git"
/// suggests github.com even with no local history.
popularSites,
historyHighlights,
topSites,
recentHistory,
@@ -67,6 +74,7 @@ enum SearchModuleType {
history => 'History (engine)',
localHistory => 'Local content',
combinedHistory => 'History',
popularSites => 'Popular Sites',
historyHighlights => 'History Highlights',
topSites => 'Top Sites',
recentHistory => 'Recent History',
@@ -100,6 +108,7 @@ enum SearchModuleGroup {
SearchModuleType.bookmarks,
SearchModuleType.articles,
SearchModuleType.combinedHistory,
SearchModuleType.popularSites,
],
);
@@ -125,7 +134,8 @@ extension SearchModuleTypeGroup on SearchModuleType {
SearchModuleType.articles ||
SearchModuleType.history ||
SearchModuleType.localHistory ||
SearchModuleType.combinedHistory => SearchModuleGroup.search,
SearchModuleType.combinedHistory ||
SearchModuleType.popularSites => SearchModuleGroup.search,
};
}
@@ -59,6 +59,7 @@ import 'package:weblibre/features/geckoview/features/search/presentation/widgets
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/feed_search.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/history_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/local_history_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/popular_sites_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/search_providers_section.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/search_term_suggestions_section.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/tab_search.dart';
@@ -613,6 +614,10 @@ class SearchScreen extends HookConsumerWidget {
searchTextListenable: sampledSearchText,
onUriSelected: openUriInTab,
),
SearchModuleType.popularSites: PopularSitesSuggestions(
searchTextListenable: sampledSearchText,
onUriSelected: openUriInTab,
),
};
bool canShowSearchModule(SearchModuleType type) {
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/features/search/domain/providers/search_modules_view.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/search_module_section.dart';
import 'package:weblibre/features/popular_sites/domain/providers/popular_sites_search.dart';
import 'package:weblibre/presentation/hooks/on_listenable_change_selector.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
/// Omnibar module offering popular-domain completions from the bundled
/// Tranco-derived `sites.db`. Ranked below history and bookmarks so a user's
/// own visited/saved sites always win; this fills the long tail with
/// well-known destinations (typing "git" -> github.com) even with no history.
class PopularSitesSuggestions extends HookConsumerWidget {
final ValueListenable<TextEditingValue> searchTextListenable;
final void Function(Uri uri) onUriSelected;
const PopularSitesSuggestions({
super.key,
required this.searchTextListenable,
required this.onUriSelected,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final results = ref.watch(popularSitesSearchResultsProvider);
useOnListenableChangeSelector(
searchTextListenable,
() => searchTextListenable.value.text,
() async {
await ref
.read(popularSitesSearchResultsProvider.notifier)
.search(searchTextListenable.value.text);
},
);
if (results.isEmpty) {
return const SliverToBoxAdapter(child: SizedBox.shrink());
}
return SearchModuleSection(
title: 'Popular Sites',
moduleType: SearchModuleType.popularSites,
totalCount: results.length,
contentSliverBuilder:
({required bool isCollapsed, required int visibleCount}) => [
if (!isCollapsed)
SliverList.builder(
itemCount: visibleCount,
itemBuilder: (context, index) {
final site = results[index];
final uri = Uri.parse('https://${site.domain}');
return ListTile(
key: ValueKey(site.domain),
leading: RepaintBoundary(
child: UrlIcon([uri], iconSize: 24),
),
title: Text(
site.domain,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
onTap: () => onUriSelected(uri),
);
},
),
],
);
}
}