added popular sites module
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user