prepare history api

This commit is contained in:
Fabian Freund
2025-09-17 17:53:06 +02:00
parent d24d612635
commit 9676ccae3d
10 changed files with 850 additions and 209 deletions
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024-2025 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_mozilla_components/flutter_mozilla_components.dart';
import 'package:riverpod/riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'providers.g.dart';
@Riverpod()
Future<List<VisitInfo>> browsingHistory(
Ref red, {
required DateTime start,
required DateTime end,
required Set<VisitType> types,
}) {
final service = GeckoHistoryService();
return service.getDetailedVisits(start, end, types);
}
@@ -0,0 +1,191 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'providers.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$browsingHistoryHash() => r'1f644757c60473f00dd94c9d312647baeaec525a';
/// Copied from Dart SDK
class _SystemHash {
_SystemHash._();
static int combine(int hash, int value) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + value);
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
static int finish(int hash) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
// ignore: parameter_assignments
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
}
/// See also [browsingHistory].
@ProviderFor(browsingHistory)
const browsingHistoryProvider = BrowsingHistoryFamily();
/// See also [browsingHistory].
class BrowsingHistoryFamily extends Family<AsyncValue<List<VisitInfo>>> {
/// See also [browsingHistory].
const BrowsingHistoryFamily();
/// See also [browsingHistory].
BrowsingHistoryProvider call({
required DateTime start,
required DateTime end,
required Set<VisitType> types,
}) {
return BrowsingHistoryProvider(start: start, end: end, types: types);
}
@override
BrowsingHistoryProvider getProviderOverride(
covariant BrowsingHistoryProvider provider,
) {
return call(
start: provider.start,
end: provider.end,
types: provider.types,
);
}
static const Iterable<ProviderOrFamily>? _dependencies = null;
@override
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
@override
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
_allTransitiveDependencies;
@override
String? get name => r'browsingHistoryProvider';
}
/// See also [browsingHistory].
class BrowsingHistoryProvider
extends AutoDisposeFutureProvider<List<VisitInfo>> {
/// See also [browsingHistory].
BrowsingHistoryProvider({
required DateTime start,
required DateTime end,
required Set<VisitType> types,
}) : this._internal(
(ref) => browsingHistory(
ref as BrowsingHistoryRef,
start: start,
end: end,
types: types,
),
from: browsingHistoryProvider,
name: r'browsingHistoryProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$browsingHistoryHash,
dependencies: BrowsingHistoryFamily._dependencies,
allTransitiveDependencies:
BrowsingHistoryFamily._allTransitiveDependencies,
start: start,
end: end,
types: types,
);
BrowsingHistoryProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.start,
required this.end,
required this.types,
}) : super.internal();
final DateTime start;
final DateTime end;
final Set<VisitType> types;
@override
Override overrideWith(
FutureOr<List<VisitInfo>> Function(BrowsingHistoryRef provider) create,
) {
return ProviderOverride(
origin: this,
override: BrowsingHistoryProvider._internal(
(ref) => create(ref as BrowsingHistoryRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
start: start,
end: end,
types: types,
),
);
}
@override
AutoDisposeFutureProviderElement<List<VisitInfo>> createElement() {
return _BrowsingHistoryProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is BrowsingHistoryProvider &&
other.start == start &&
other.end == end &&
other.types == types;
}
@override
int get hashCode {
var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, start.hashCode);
hash = _SystemHash.combine(hash, end.hashCode);
hash = _SystemHash.combine(hash, types.hashCode);
return _SystemHash.finish(hash);
}
}
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
mixin BrowsingHistoryRef on AutoDisposeFutureProviderRef<List<VisitInfo>> {
/// The parameter `start` of this provider.
DateTime get start;
/// The parameter `end` of this provider.
DateTime get end;
/// The parameter `types` of this provider.
Set<VisitType> get types;
}
class _BrowsingHistoryProviderElement
extends AutoDisposeFutureProviderElement<List<VisitInfo>>
with BrowsingHistoryRef {
_BrowsingHistoryProviderElement(super.provider);
@override
DateTime get start => (origin as BrowsingHistoryProvider).start;
@override
DateTime get end => (origin as BrowsingHistoryProvider).end;
@override
Set<VisitType> get types => (origin as BrowsingHistoryProvider).types;
}
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/features/geckoview/features/history/domain/providers.dart';
class HistoryScreen extends HookConsumerWidget {
const HistoryScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final history = ref.watch(
browsingHistoryProvider(
start: DateTime(0),
end: DateTime.now(),
types: {
VisitType.link,
VisitType.redirectPermanent,
VisitType.redirectTemporary,
VisitType.typed,
},
),
);
}
}