Skip to content

Commit ae723df

Browse files
committed
feat(feed): source filter preserves state
- Pass and return full filter state - Retry reloads all sources/countries
1 parent e665de4 commit ae723df

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

lib/headlines-feed/view/source_filter_page.dart

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:ht_data_repository/ht_data_repository.dart';
66
import 'package:ht_main/headlines-feed/bloc/sources_filter_bloc.dart';
7+
import 'package:ht_main/headlines-feed/view/headlines_filter_page.dart'
8+
show keySelectedCountryIsoCodes, keySelectedSourceTypes, keySelectedSources;
79
import 'package:ht_main/l10n/l10n.dart';
810
import 'package:ht_main/shared/constants/app_spacing.dart';
911
import 'package:ht_main/shared/widgets/failure_state_widget.dart';
1012
import 'package:ht_main/shared/widgets/loading_state_widget.dart';
11-
import 'package:ht_shared/ht_shared.dart' show Country, Source;
13+
import 'package:ht_shared/ht_shared.dart' show Country, Source, SourceType;
14+
15+
// Keys are defined in headlines_filter_page.dart and imported by router.dart
16+
// const String keySelectedSources = 'selectedSources'; // REMOVED
17+
// const String keySelectedCountryIsoCodes = 'selectedCountryIsoCodes'; // REMOVED
18+
// const String keySelectedSourceTypes = 'selectedSourceTypes'; // REMOVED
1219

1320
class SourceFilterPage extends StatelessWidget {
14-
const SourceFilterPage({super.key, this.initialSelectedSources = const []});
21+
const SourceFilterPage({
22+
super.key,
23+
this.initialSelectedSources = const [],
24+
this.initialSelectedCountryIsoCodes = const {},
25+
this.initialSelectedSourceTypes = const {},
26+
});
1527

1628
final List<Source> initialSelectedSources;
29+
final Set<String> initialSelectedCountryIsoCodes;
30+
final Set<SourceType> initialSelectedSourceTypes;
1731

1832
@override
1933
Widget build(BuildContext context) {
@@ -25,6 +39,8 @@ class SourceFilterPage extends StatelessWidget {
2539
)..add(
2640
LoadSourceFilterData(
2741
initialSelectedSources: initialSelectedSources,
42+
initialSelectedCountryIsoCodes: initialSelectedCountryIsoCodes,
43+
initialSelectedSourceTypes: initialSelectedSourceTypes,
2844
),
2945
),
3046
child: const _SourceFilterView(),
@@ -63,7 +79,12 @@ class _SourceFilterView extends StatelessWidget {
6379
(s) => state.finallySelectedSourceIds.contains(s.id),
6480
)
6581
.toList();
66-
Navigator.of(context).pop(selectedSources);
82+
// Pop with a map containing all relevant filter state
83+
Navigator.of(context).pop({
84+
keySelectedSources: selectedSources,
85+
keySelectedCountryIsoCodes: state.selectedCountryIsoCodes,
86+
keySelectedSourceTypes: state.selectedSourceTypes,
87+
});
6788
},
6889
),
6990
],
@@ -91,10 +112,15 @@ class _SourceFilterView extends StatelessWidget {
91112
message: state.errorMessage ?? l10n.headlinesFeedFilterErrorCriteria,
92113
onRetry: () {
93114
context.read<SourcesFilterBloc>().add(
94-
LoadSourceFilterData(
95-
initialSelectedSources:
96-
ModalRoute.of(context)?.settings.arguments as List<Source>? ??
97-
const [],
115+
// When retrying, we don't have initial capsule states from arguments
116+
// So, we pass empty sets, BLoC will load all sources and countries.
117+
// User can then re-apply capsule filters if needed.
118+
// Or, we could try to persist/retrieve the last known good capsule state.
119+
// For now, simple retry reloads all.
120+
const LoadSourceFilterData(
121+
initialSelectedSources: [], // Or pass current selections if needed
122+
initialSelectedCountryIsoCodes: {},
123+
initialSelectedSourceTypes: {},
98124
),
99125
);
100126
},

0 commit comments

Comments
 (0)