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
@@ -0,0 +1,49 @@
/*
* 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:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/features/popular_sites/data/database/definitions.drift.dart';
import 'package:weblibre/features/popular_sites/domain/repositories/popular_sites.dart';
part 'popular_sites_search.g.dart';
/// Holds the current popular-domain prefix completions for the omnibar
/// "Popular Sites" module. Mirrors the bookmark/tab search-result notifiers:
/// the widget watches the state list and pushes new queries through [search].
@Riverpod()
class PopularSitesSearchResults extends _$PopularSitesSearchResults {
Future<void> search(String query, {int limit = 8}) async {
if (query.trim().isEmpty) {
state = const [];
return;
}
final results = await ref
.read(popularSitesRepositoryProvider.notifier)
.searchByPrefix(query, limit: limit);
if (!ref.mounted) return;
state = results;
}
@override
List<Site> build() {
return const [];
}
}
@@ -0,0 +1,76 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'popular_sites_search.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
/// Holds the current popular-domain prefix completions for the omnibar
/// "Popular Sites" module. Mirrors the bookmark/tab search-result notifiers:
/// the widget watches the state list and pushes new queries through [search].
@ProviderFor(PopularSitesSearchResults)
final popularSitesSearchResultsProvider = PopularSitesSearchResultsProvider._();
/// Holds the current popular-domain prefix completions for the omnibar
/// "Popular Sites" module. Mirrors the bookmark/tab search-result notifiers:
/// the widget watches the state list and pushes new queries through [search].
final class PopularSitesSearchResultsProvider
extends $NotifierProvider<PopularSitesSearchResults, List<Site>> {
/// Holds the current popular-domain prefix completions for the omnibar
/// "Popular Sites" module. Mirrors the bookmark/tab search-result notifiers:
/// the widget watches the state list and pushes new queries through [search].
PopularSitesSearchResultsProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'popularSitesSearchResultsProvider',
isAutoDispose: true,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$popularSitesSearchResultsHash();
@$internal
@override
PopularSitesSearchResults create() => PopularSitesSearchResults();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(List<Site> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<List<Site>>(value),
);
}
}
String _$popularSitesSearchResultsHash() =>
r'107396362aa70acf898b75137df42717ac52f1b3';
/// Holds the current popular-domain prefix completions for the omnibar
/// "Popular Sites" module. Mirrors the bookmark/tab search-result notifiers:
/// the widget watches the state list and pushes new queries through [search].
abstract class _$PopularSitesSearchResults extends $Notifier<List<Site>> {
List<Site> build();
@$mustCallSuper
@override
WhenComplete runBuild() {
final ref = this.ref as $Ref<List<Site>, List<Site>>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<List<Site>, List<Site>>,
List<Site>,
Object?,
Object?
>;
return element.handleCreate(ref, build);
}
}