refactor container tab repo

This commit is contained in:
Fabian Freund
2025-07-20 14:11:18 +02:00
parent fd1e71343a
commit b8b417103d
15 changed files with 174 additions and 13 deletions
@@ -15,6 +15,7 @@ import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
import 'package:weblibre/features/geckoview/domain/providers.dart';
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
import 'package:weblibre/features/geckoview/features/find_in_page/domain/repositories/find_in_page.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
import 'package:weblibre/features/geckoview/utils/image_helper.dart';
part 'tab_state.g.dart';
@@ -216,3 +217,13 @@ TabType? selectedTabType(Ref ref) {
(isCurrentPrivate) => isCurrentPrivate ? TabType.private : TabType.regular,
);
}
@Riverpod(keepAlive: true)
AsyncValue<String?> selectedTabContainerId(Ref ref) {
final tabId = ref.watch(selectedTabProvider);
if (tabId != null) {
return ref.watch(watchContainerTabIdProvider(tabId));
}
return const AsyncData(null);
}
@@ -175,6 +175,24 @@ final selectedTabTypeProvider = AutoDisposeProvider<TabType?>.internal(
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef SelectedTabTypeRef = AutoDisposeProviderRef<TabType?>;
String _$selectedTabContainerIdHash() =>
r'9f0246a02a069b1a66211a3924f32e9d75f0f344';
/// See also [selectedTabContainerId].
@ProviderFor(selectedTabContainerId)
final selectedTabContainerIdProvider = Provider<AsyncValue<String?>>.internal(
selectedTabContainerId,
name: r'selectedTabContainerIdProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$selectedTabContainerIdHash,
dependencies: null,
allTransitiveDependencies: null,
);
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef SelectedTabContainerIdRef = ProviderRef<AsyncValue<String?>>;
String _$tabStatesHash() => r'e4d2f2b4ddd65beac8a1fd0d22bad1e0a26b41bd';
/// See also [TabStates].
@@ -114,7 +114,7 @@ class TabRepository extends _$TabRepository {
Future<bool> selectTab(String tabId) async {
final containerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tabId);
.getContainerTabId(tabId);
final containerData = await containerId.mapNotNull(
(containerId) => ref
@@ -156,7 +156,7 @@ class TabRepository extends _$TabRepository {
final currentContainerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tabId);
.getContainerTabId(tabId);
final sameContainerTabs = await ref
.read(containerRepositoryProvider.notifier)
@@ -6,7 +6,7 @@ part of 'tab.dart';
// RiverpodGenerator
// **************************************************************************
String _$tabRepositoryHash() => r'94e67307d67c8873b2ebd8cfadcd71258782987a';
String _$tabRepositoryHash() => r'4b0dc3bbfd3635398009d655d811a4a35dbfb503';
/// See also [TabRepository].
@ProviderFor(TabRepository)
@@ -231,7 +231,9 @@ class WebPageDialog extends HookConsumerWidget {
),
builder: (context, ref, child) {
final containerId = ref.watch(
selectedContainerProvider,
selectedTabContainerIdProvider.select(
(value) => value.valueOrNull,
),
);
return Visibility(
@@ -433,7 +433,7 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
filteredTabEntities.value[oldIndex].tabId;
final containerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tabId);
.getContainerTabId(tabId);
final String key;
if (newIndex <= 0) {
@@ -237,7 +237,7 @@ class SingleTabPreview extends HookConsumerWidget {
onDeleteAll: (host) async {
final containerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tab.id);
.getContainerTabId(tab.id);
await ref
.read(tabDataRepositoryProvider.notifier)
@@ -77,3 +77,12 @@ Stream<List<TabData>> containerTabsData(Ref ref, String containerId) {
final db = ref.watch(tabDatabaseProvider);
return db.containerDao.getContainerTabsData(containerId).watch();
}
@Riverpod()
Stream<String?> watchContainerTabId(Ref ref, String tabId) {
return ref
.read(tabDatabaseProvider)
.tabDao
.getTabContainerId(tabId)
.watchSingleOrNull();
}
@@ -687,5 +687,126 @@ class _ContainerTabsDataProviderElement
String get containerId => (origin as ContainerTabsDataProvider).containerId;
}
String _$watchContainerTabIdHash() =>
r'b8f107e462f417b128221240242167a0754f040f';
/// See also [watchContainerTabId].
@ProviderFor(watchContainerTabId)
const watchContainerTabIdProvider = WatchContainerTabIdFamily();
/// See also [watchContainerTabId].
class WatchContainerTabIdFamily extends Family<AsyncValue<String?>> {
/// See also [watchContainerTabId].
const WatchContainerTabIdFamily();
/// See also [watchContainerTabId].
WatchContainerTabIdProvider call(String tabId) {
return WatchContainerTabIdProvider(tabId);
}
@override
WatchContainerTabIdProvider getProviderOverride(
covariant WatchContainerTabIdProvider provider,
) {
return call(provider.tabId);
}
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'watchContainerTabIdProvider';
}
/// See also [watchContainerTabId].
class WatchContainerTabIdProvider extends AutoDisposeStreamProvider<String?> {
/// See also [watchContainerTabId].
WatchContainerTabIdProvider(String tabId)
: this._internal(
(ref) => watchContainerTabId(ref as WatchContainerTabIdRef, tabId),
from: watchContainerTabIdProvider,
name: r'watchContainerTabIdProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$watchContainerTabIdHash,
dependencies: WatchContainerTabIdFamily._dependencies,
allTransitiveDependencies:
WatchContainerTabIdFamily._allTransitiveDependencies,
tabId: tabId,
);
WatchContainerTabIdProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.tabId,
}) : super.internal();
final String tabId;
@override
Override overrideWith(
Stream<String?> Function(WatchContainerTabIdRef provider) create,
) {
return ProviderOverride(
origin: this,
override: WatchContainerTabIdProvider._internal(
(ref) => create(ref as WatchContainerTabIdRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
tabId: tabId,
),
);
}
@override
AutoDisposeStreamProviderElement<String?> createElement() {
return _WatchContainerTabIdProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is WatchContainerTabIdProvider && other.tabId == tabId;
}
@override
int get hashCode {
var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, tabId.hashCode);
return _SystemHash.finish(hash);
}
}
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
mixin WatchContainerTabIdRef on AutoDisposeStreamProviderRef<String?> {
/// The parameter `tabId` of this provider.
String get tabId;
}
class _WatchContainerTabIdProviderElement
extends AutoDisposeStreamProviderElement<String?>
with WatchContainerTabIdRef {
_WatchContainerTabIdProviderElement(super.provider);
@override
String get tabId => (origin as WatchContainerTabIdProvider).tabId;
}
// 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
@@ -102,7 +102,7 @@ class SelectedContainer extends _$SelectedContainer {
if (next != null) {
final tabContainerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(next);
.getContainerTabId(next);
if (tabContainerId != stateOrNull) {
if (tabContainerId != null) {
@@ -44,7 +44,7 @@ final selectedContainerTabCountProvider =
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef SelectedContainerTabCountRef = AutoDisposeProviderRef<AsyncValue<int>>;
String _$selectedContainerHash() => r'34457f0adc45d437a9ab817387be4b1664cd2e7a';
String _$selectedContainerHash() => r'0441c56a22fd8cab71fec4906d3c22f40553b327';
/// See also [SelectedContainer].
@ProviderFor(SelectedContainer)
@@ -15,7 +15,7 @@ class TabDataRepository extends _$TabDataRepository {
) async {
final currentContainerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tabId);
.getContainerTabId(tabId);
final currentContainerData = await currentContainerId.mapNotNull(
(containerId) => ref
@@ -81,7 +81,7 @@ class TabDataRepository extends _$TabDataRepository {
}
}
Future<String?> containerTabId(String tabId) {
Future<String?> getContainerTabId(String tabId) {
return ref
.read(tabDatabaseProvider)
.tabDao
@@ -6,7 +6,7 @@ part of 'tab.dart';
// RiverpodGenerator
// **************************************************************************
String _$tabDataRepositoryHash() => r'c9a551adc4eff3b6680fee90be141e10a161db81';
String _$tabDataRepositoryHash() => r'be1bb8a8118c7bfd90d0f1ac89a04c0a2149a0b0';
/// See also [TabDataRepository].
@ProviderFor(TabDataRepository)
@@ -68,7 +68,7 @@ Future<WebPageInfo> pageInfo(
if (tabId != null) {
final containerId = await ref
.read(tabDataRepositoryProvider.notifier)
.containerTabId(tabId);
.getContainerTabId(tabId);
final containerData = await containerId.mapNotNull(
(containerId) => ref
@@ -6,7 +6,7 @@ part of 'website_title.dart';
// RiverpodGenerator
// **************************************************************************
String _$pageInfoHash() => r'a57b4b72b16b63f5f366e014bb56cd0f021bcfa8';
String _$pageInfoHash() => r'46eec6236555d37b5bbb4d8d887c5ee6ee0336e3';
/// Copied from Dart SDK
class _SystemHash {