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,45 @@
/*
* 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/data/providers.dart';
part 'popular_sites.g.dart';
@Riverpod(keepAlive: true)
class PopularSitesRepository extends _$PopularSitesRepository {
/// Popular registrable domains whose start matches [prefix], ordered by
/// popularity. Returns empty for a blank prefix so the omnibar suggestion
/// module stays quiet until the user types.
Future<List<Site>> searchByPrefix(String prefix, {int limit = 8}) {
if (prefix.trim().isEmpty) {
return Future.value(const []);
}
return ref
.read(sitesDatabaseProvider)
.siteDao
.searchByPrefix(prefix, limit: limit)
.get();
}
@override
void build() {}
}
@@ -0,0 +1,63 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'popular_sites.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(PopularSitesRepository)
final popularSitesRepositoryProvider = PopularSitesRepositoryProvider._();
final class PopularSitesRepositoryProvider
extends $NotifierProvider<PopularSitesRepository, void> {
PopularSitesRepositoryProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'popularSitesRepositoryProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$popularSitesRepositoryHash();
@$internal
@override
PopularSitesRepository create() => PopularSitesRepository();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(void value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<void>(value),
);
}
}
String _$popularSitesRepositoryHash() =>
r'9825dc634b2ae9ea48a33eac8387a3e138c17b9f';
abstract class _$PopularSitesRepository extends $Notifier<void> {
void build();
@$mustCallSuper
@override
WhenComplete runBuild() {
final ref = this.ref as $Ref<void, void>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<void, void>,
void,
Object?,
Object?
>;
return element.handleCreate(ref, build);
}
}