Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Store: the tab keeps your place when you switch away and back

deebf6732da8ea9
diff --git a/desktop/lib/store/store_screen.dart b/desktop/lib/store/store_screen.dart
index 1b7086262..5abd9050b 100644
--- a/desktop/lib/store/store_screen.dart
+++ b/desktop/lib/store/store_screen.dart
@@ -89,13 +89,44 @@ class _Category extends _Shelf {
final String name;
}
+/// Where a person was in the store, kept per window (the app has one store
+/// tab). Only the visible tab is built, so switching away disposed the store's
+/// state: coming back reset it to Discover, with the search and the open
+/// product page gone. A tab should keep its place, as a browser tab does.
+class _StorePlace {
+ _Shelf shelf = const _Discover();
+ String? selected;
+ String query = '';
+}
+
+final _storePlaces = Expando<_StorePlace>('store place');
+
class _StoreTabState extends State<StoreTab> {
late final StoreController _store = StoreController(
widget.api ?? ApiStoreApi(widget.notifier.api),
);
- _Shelf _shelf = const _Discover();
- late String? _selected = widget.initialHarness;
- final _search = TextEditingController();
+ late final _StorePlace _place = _storePlaces[widget.notifier] ??=
+ _StorePlace();
+ late _Shelf _shelf = widget.initialHarness == null
+ ? _place.shelf
+ : const _Discover();
+ late String? _selected = widget.initialHarness ?? _place.selected;
+ late final _search = TextEditingController(
+ text: widget.initialHarness == null ? _place.query : '',
+ );
+
+ void _remember() {
+ _place
+ ..shelf = _shelf
+ ..selected = _selected
+ ..query = _search.text;
+ }
+
+ @override
+ void setState(VoidCallback fn) {
+ super.setState(fn);
+ _remember();
+ }
@override
void initState() {
diff --git a/desktop/test/store_screen_test.dart b/desktop/test/store_screen_test.dart
index c41ea631b..4e3e50229 100644
--- a/desktop/test/store_screen_test.dart
+++ b/desktop/test/store_screen_test.dart
@@ -354,6 +354,50 @@ void main() {
},
);
+ testWidgets(
+ 'leaving the store tab and coming back keeps the search and the open page',
+ (tester) async {
+ final (notifier, store) = await open(tester);
+ Future<void> mountAgain() async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: StoreTab(notifier: notifier, api: store, source: 'test'),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ }
+
+ await tester.enterText(find.byKey(const ValueKey('store-search')), 'typ');
+ await tester.pumpAndSettle();
+ await tester.tap(
+ find.byKey(const ValueKey('store-card:autonomous/typst')).first,
+ );
+ await tester.pumpAndSettle();
+ expect(
+ find.byKey(const ValueKey('store-page:autonomous/typst')),
+ findsOneWidget,
+ );
+
+ // Another tab is shown: the store tab is not built at all.
+ await tester.pumpWidget(const SizedBox());
+ await mountAgain();
+ expect(
+ find.byKey(const ValueKey('store-page:autonomous/typst')),
+ findsOneWidget,
+ );
+ expect(
+ tester
+ .widget<TextField>(find.byKey(const ValueKey('store-search')))
+ .controller!
+ .text,
+ 'typ',
+ );
+ expect(tester.takeException(), isNull);
+ },
+ );
+
testWidgets('the catalog keeps real ratings and hides viewer dependencies', (
tester,
) async {