synchronize container selection

This commit is contained in:
Fabian Freund
2026-02-13 19:45:57 +01:00
parent 1c31dc7884
commit de345d5d72
@@ -41,7 +41,6 @@ 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/domain/providers/selected_container.dart';
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.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';
@@ -81,12 +80,9 @@ 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); final selectedContainer = ref.watch(
ref.listen(selectedContainerDataProvider, (previous, next) { selectedContainerDataProvider.select((value) => value.value),
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
@@ -251,7 +247,7 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value(selectedContainer.value), container: Value(selectedContainer),
); );
} }
@@ -337,12 +333,30 @@ class SearchScreen extends HookConsumerWidget {
child: SizedBox( child: SizedBox(
height: 48, height: 48,
child: ContainerChips( child: ContainerChips(
selectedContainer: selectedContainer.value, selectedContainer: selectedContainer,
onSelected: (container) { onSelected: (container) async {
selectedContainer.value = container; if (container != null) {
await ref
.read(
selectedContainerProvider
.notifier,
)
.setContainerId(container.id);
} else {
ref
.read(
selectedContainerProvider
.notifier,
)
.clearContainer();
}
}, },
onDeleted: (container) { onDeleted: (container) {
selectedContainer.value = null; ref
.read(
selectedContainerProvider.notifier,
)
.clearContainer();
}, },
), ),
), ),
@@ -425,9 +439,7 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value( container: Value(selectedContainer),
selectedContainer.value,
),
); );
} }
@@ -481,7 +493,7 @@ class SearchScreen extends HookConsumerWidget {
: null, : null,
launchedFromIntent: launchedFromIntent, launchedFromIntent: launchedFromIntent,
selectTab: true, selectTab: true,
container: Value(selectedContainer.value), container: Value(selectedContainer),
); );
} }