add container selection to new tab screen

This commit is contained in:
Fabian Freund
2026-02-03 04:21:58 +01:00
parent ba9865a22e
commit 6b361aaada
@@ -19,6 +19,7 @@
*/ */
import 'dart:async'; import 'dart:async';
import 'package:drift/drift.dart' hide Column;
import 'package:fading_scroll/fading_scroll.dart'; import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
@@ -40,6 +41,9 @@ import 'package:weblibre/features/geckoview/features/search/presentation/widgets
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/full_search_suggestions.dart'; import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/full_search_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/history_suggestions.dart'; import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/history_suggestions.dart';
import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/tab_search.dart'; import 'package:weblibre/features/geckoview/features/search/presentation/widgets/search_modules/tab_search.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart'; import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/presentation/hooks/on_listenable_change_selector.dart'; import 'package:weblibre/presentation/hooks/on_listenable_change_selector.dart';
import 'package:weblibre/presentation/hooks/sampled_value_notifier.dart'; import 'package:weblibre/presentation/hooks/sampled_value_notifier.dart';
@@ -77,6 +81,13 @@ class SearchScreen extends HookConsumerWidget {
final selectedTabType = useState(tabType); final selectedTabType = useState(tabType);
final currentTabTabType = ref.watch(selectedTabTypeProvider); final currentTabTabType = ref.watch(selectedTabTypeProvider);
final selectedContainer = useState<ContainerData?>(null);
ref.listen(selectedContainerDataProvider, (previous, next) {
next.whenData((container) {
selectedContainer.value = container;
});
});
// When editing an existing tab, get its state // When editing an existing tab, get its state
// If tab no longer exists (null), fall back to new tab mode // If tab no longer exists (null), fall back to new tab mode
final existingTabState = tabId != null final existingTabState = tabId != null
@@ -240,6 +251,7 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value(selectedContainer.value),
); );
} }
@@ -264,11 +276,13 @@ class SearchScreen extends HookConsumerWidget {
floating: true, floating: true,
pinned: true, pinned: true,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
toolbarHeight: isEditMode ? 0 : kToolbarHeight, toolbarHeight: isEditMode ? 0 : kToolbarHeight + 56,
title: isEditMode title: isEditMode
? null ? null
: Align( : Column(
child: Focus( mainAxisSize: MainAxisSize.min,
children: [
Focus(
canRequestFocus: false, canRequestFocus: false,
child: SegmentedButton( child: SegmentedButton(
showSelectedIcon: false, showSelectedIcon: false,
@@ -294,15 +308,15 @@ class SearchScreen extends HookConsumerWidget {
onSelectionChanged: (value) { onSelectionChanged: (value) {
selectedTabType.value = value.first; selectedTabType.value = value.first;
// Restore focus to search field after segment change // Restore focus to search field after segment change
WidgetsBinding.instance.addPostFrameCallback(( WidgetsBinding.instance
_, .addPostFrameCallback((_) {
) {
searchFocusNode.requestFocus(); searchFocusNode.requestFocus();
}); });
}, },
style: switch (selectedTabType.value) { style: switch (selectedTabType.value) {
TabType.regular => null, TabType.regular => null,
TabType.private => SegmentedButton.styleFrom( TabType.private =>
SegmentedButton.styleFrom(
selectedBackgroundColor: selectedBackgroundColor:
appColors.privateSelectionOverlay, appColors.privateSelectionOverlay,
), ),
@@ -316,6 +330,30 @@ class SearchScreen extends HookConsumerWidget {
}, },
), ),
), ),
const SizedBox(height: 8),
SizedBox(
height: 48,
child: ContainerChips(
selectedContainer: selectedContainer.value,
onSelected: (container) async {
if (container != null) {
if (await ref
.read(
selectedContainerProvider.notifier,
)
.authenticateContainer(container)) {
selectedContainer.value = container;
}
} else {
selectedContainer.value = container;
}
},
onDeleted: (container) {
selectedContainer.value = null;
},
),
),
],
), ),
bottom: PreferredSize( bottom: PreferredSize(
preferredSize: Size.fromHeight(preferredHeight.value), preferredSize: Size.fromHeight(preferredHeight.value),
@@ -393,6 +431,9 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value(
selectedContainer.value,
),
); );
} }
@@ -446,6 +487,7 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value(selectedContainer.value),
); );
} }