show tab count filtered by selected container
This commit is contained in:
+46
-11
@@ -1,6 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/tab_list.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
|
||||
|
||||
class TabsActionButton extends HookConsumerWidget {
|
||||
final bool isActive;
|
||||
@@ -20,9 +23,8 @@ class TabsActionButton extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final tabCount = ref.watch(
|
||||
tabListProvider.select((tabs) => tabs.value.length),
|
||||
);
|
||||
final tabCount = ref.watch(selectedContainerTabCountProvider);
|
||||
final lastTabCount = useRef<int?>(null);
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
@@ -42,13 +44,46 @@ class TabsActionButton extends HookConsumerWidget {
|
||||
),
|
||||
constraints: const BoxConstraints(minWidth: 25.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
tabCount.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14.0,
|
||||
color: isActive ? theme.colorScheme.primary : null,
|
||||
),
|
||||
child: tabCount.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (count) {
|
||||
lastTabCount.value = count;
|
||||
|
||||
return Text(
|
||||
count.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14.0,
|
||||
color: isActive ? theme.colorScheme.primary : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => (lastTabCount.value != null)
|
||||
? Text(
|
||||
lastTabCount.value.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14.0,
|
||||
color: isActive ? theme.colorScheme.primary : null,
|
||||
),
|
||||
)
|
||||
: const Skeletonizer(child: Text('00')),
|
||||
error: (error, stackTrace) {
|
||||
logger.e(
|
||||
'Could not determine tab count',
|
||||
error: error,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
|
||||
return Text(
|
||||
'-1',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14.0,
|
||||
color: isActive ? theme.colorScheme.primary : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -49,6 +49,13 @@ Stream<List<String>> containerTabIds(Ref ref, ContainerFilter containerFilter) {
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Future<int> containerTabCount(Ref ref, ContainerFilter containerFilter) {
|
||||
return ref.watch(
|
||||
containerTabIdsProvider(containerFilter).selectAsync((tabs) => tabs.length),
|
||||
);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<List<TabTreesResult>> tabTrees(Ref ref) {
|
||||
final db = ref.watch(tabDatabaseProvider);
|
||||
|
||||
@@ -303,6 +303,129 @@ class _ContainerTabIdsProviderElement
|
||||
(origin as ContainerTabIdsProvider).containerFilter;
|
||||
}
|
||||
|
||||
String _$containerTabCountHash() => r'586e83429b527b546d43232a58453635ab860d69';
|
||||
|
||||
/// See also [containerTabCount].
|
||||
@ProviderFor(containerTabCount)
|
||||
const containerTabCountProvider = ContainerTabCountFamily();
|
||||
|
||||
/// See also [containerTabCount].
|
||||
class ContainerTabCountFamily extends Family<AsyncValue<int>> {
|
||||
/// See also [containerTabCount].
|
||||
const ContainerTabCountFamily();
|
||||
|
||||
/// See also [containerTabCount].
|
||||
ContainerTabCountProvider call(ContainerFilter containerFilter) {
|
||||
return ContainerTabCountProvider(containerFilter);
|
||||
}
|
||||
|
||||
@override
|
||||
ContainerTabCountProvider getProviderOverride(
|
||||
covariant ContainerTabCountProvider provider,
|
||||
) {
|
||||
return call(provider.containerFilter);
|
||||
}
|
||||
|
||||
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'containerTabCountProvider';
|
||||
}
|
||||
|
||||
/// See also [containerTabCount].
|
||||
class ContainerTabCountProvider extends AutoDisposeFutureProvider<int> {
|
||||
/// See also [containerTabCount].
|
||||
ContainerTabCountProvider(ContainerFilter containerFilter)
|
||||
: this._internal(
|
||||
(ref) =>
|
||||
containerTabCount(ref as ContainerTabCountRef, containerFilter),
|
||||
from: containerTabCountProvider,
|
||||
name: r'containerTabCountProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$containerTabCountHash,
|
||||
dependencies: ContainerTabCountFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
ContainerTabCountFamily._allTransitiveDependencies,
|
||||
containerFilter: containerFilter,
|
||||
);
|
||||
|
||||
ContainerTabCountProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.containerFilter,
|
||||
}) : super.internal();
|
||||
|
||||
final ContainerFilter containerFilter;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
FutureOr<int> Function(ContainerTabCountRef provider) create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: ContainerTabCountProvider._internal(
|
||||
(ref) => create(ref as ContainerTabCountRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
containerFilter: containerFilter,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeFutureProviderElement<int> createElement() {
|
||||
return _ContainerTabCountProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ContainerTabCountProvider &&
|
||||
other.containerFilter == containerFilter;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, containerFilter.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
mixin ContainerTabCountRef on AutoDisposeFutureProviderRef<int> {
|
||||
/// The parameter `containerFilter` of this provider.
|
||||
ContainerFilter get containerFilter;
|
||||
}
|
||||
|
||||
class _ContainerTabCountProviderElement
|
||||
extends AutoDisposeFutureProviderElement<int>
|
||||
with ContainerTabCountRef {
|
||||
_ContainerTabCountProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
ContainerFilter get containerFilter =>
|
||||
(origin as ContainerTabCountProvider).containerFilter;
|
||||
}
|
||||
|
||||
String _$tabTreesHash() => r'b7b7f7136827207dd01a7894a915be3d17b1ae63';
|
||||
|
||||
/// See also [tabTrees].
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:riverpod/riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/entities/container_filter.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/providers.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart';
|
||||
@@ -138,3 +139,14 @@ Stream<ContainerData?> selectedContainerData(Ref ref) {
|
||||
|
||||
return Stream.value(null);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
AsyncValue<int> selectedContainerTabCount(Ref ref) {
|
||||
final selectedContainer = ref.watch(selectedContainerProvider);
|
||||
final tabCount = ref.watch(
|
||||
// ignore: provider_parameters
|
||||
containerTabCountProvider(ContainerFilter.from(selectedContainer)),
|
||||
);
|
||||
|
||||
return tabCount;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,25 @@ final selectedContainerDataProvider =
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef SelectedContainerDataRef = AutoDisposeStreamProviderRef<ContainerData?>;
|
||||
String _$selectedContainerTabCountHash() =>
|
||||
r'60218b4a9058738dfd43628d5e3c55f93080732f';
|
||||
|
||||
/// See also [selectedContainerTabCount].
|
||||
@ProviderFor(selectedContainerTabCount)
|
||||
final selectedContainerTabCountProvider =
|
||||
AutoDisposeProvider<AsyncValue<int>>.internal(
|
||||
selectedContainerTabCount,
|
||||
name: r'selectedContainerTabCountProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectedContainerTabCountHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef SelectedContainerTabCountRef = AutoDisposeProviderRef<AsyncValue<int>>;
|
||||
String _$selectedContainerHash() => r'34457f0adc45d437a9ab817387be4b1664cd2e7a';
|
||||
|
||||
/// See also [SelectedContainer].
|
||||
|
||||
Reference in New Issue
Block a user