Skip to content

Commit f9eaa16

Browse files
committed
refactor(headlines-feed): assume logged-in user for content preferences
- Remove null checks for current user in countries, sources, and topics filter BLOCS - Simplify user authentication assumption in headlines filter page - Update user-related operations to directly access user properties
1 parent 1131bfd commit f9eaa16

File tree

4 files changed

+4
-51
lines changed

4 files changed

+4
-51
lines changed

lib/headlines-feed/bloc/countries_filter_bloc.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,7 @@ class CountriesFilterBloc
9898
state.copyWith(followedCountriesStatus: CountriesFilterStatus.loading),
9999
);
100100

101-
final currentUser = _appBloc.state.user;
102-
103-
if (currentUser == null) {
104-
emit(
105-
state.copyWith(
106-
followedCountriesStatus: CountriesFilterStatus.failure,
107-
error: const UnauthorizedException(
108-
'User must be logged in to apply followed countries.',
109-
),
110-
),
111-
);
112-
return;
113-
}
101+
final currentUser = _appBloc.state.user!;
114102

115103
try {
116104
final preferences = await _userContentPreferencesRepository.read(

lib/headlines-feed/bloc/sources_filter_bloc.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,7 @@ class SourcesFilterBloc extends Bloc<SourcesFilterEvent, SourcesFilterState> {
204204
),
205205
);
206206

207-
final currentUser = _appBloc.state.user;
208-
209-
if (currentUser == null) {
210-
emit(
211-
state.copyWith(
212-
followedSourcesStatus: SourceFilterDataLoadingStatus.failure,
213-
error: const UnauthorizedException(
214-
'User must be logged in to apply followed sources.',
215-
),
216-
),
217-
);
218-
return;
219-
}
207+
final currentUser = _appBloc.state.user!;
220208

221209
try {
222210
final preferences = await _userContentPreferencesRepository.read(

lib/headlines-feed/bloc/topics_filter_bloc.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,7 @@ class TopicsFilterBloc extends Bloc<TopicsFilterEvent, TopicsFilterState> {
126126
) async {
127127
emit(state.copyWith(followedTopicsStatus: TopicsFilterStatus.loading));
128128

129-
final currentUser = _appBloc.state.user;
130-
131-
if (currentUser == null) {
132-
emit(
133-
state.copyWith(
134-
followedTopicsStatus: TopicsFilterStatus.failure,
135-
error: const UnauthorizedException(
136-
'User must be logged in to apply followed topics.',
137-
),
138-
),
139-
);
140-
return;
141-
}
129+
final currentUser = _appBloc.state.user!;
142130

143131
try {
144132
final preferences = await _userContentPreferencesRepository.read(

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,7 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
8888
});
8989

9090
final appState = context.read<AppBloc>().state;
91-
final currentUser = appState.user;
92-
93-
if (currentUser == null) {
94-
setState(() {
95-
_isLoadingFollowedFilters = false;
96-
_useFollowedFilters = false;
97-
_loadFollowedFiltersError = AppLocalizationsX(
98-
context,
99-
).l10n.mustBeLoggedInToUseFeatureError;
100-
});
101-
return;
102-
}
91+
final currentUser = appState.user!;
10392

10493
try {
10594
final preferencesRepo = context

0 commit comments

Comments
 (0)