Skip to content

Commit b0814be

Browse files
authored
Merge pull request #476 from OpenPecha/refactor/series-detail-enrollment-apis
Refactor/series detail enrollment apis
2 parents 6aaaf42 + edc72a4 commit b0814be

5 files changed

Lines changed: 235 additions & 203 deletions

File tree

lib/core/config/locale/locale_notifier.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ final localeProvider = StateNotifierProvider<LocaleNotifier, Locale>((ref) {
9999

100100
/// Language code sent to backend APIs for translatable content.
101101
///
102-
/// UI may be hi/mn/ne, but the API only serves en/zh/bo — unsupported locales
103-
/// fall back to English via [AppConfig.resolveContentLanguage].
102+
/// Mirrors the user's selected app locale when supported; unknown codes fall
103+
/// back to English via [AppConfig.resolveContentLanguage].
104104
final contentLanguageProvider = Provider<String>((ref) {
105105
return AppConfig.resolveContentLanguage(
106106
ref.watch(localeProvider).languageCode,

lib/core/constants/app_config.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,11 @@ class AppConfig {
4040
'ne',
4141
];
4242

43-
/// Languages the backend can serve translatable content in.
44-
static const List<String> backendContentLanguages = [
45-
englishLanguageCode,
46-
chineseLanguageCode,
47-
tibetanLanguageCode,
48-
];
49-
5043
/// Maps a UI locale to the language code sent to content APIs.
51-
/// Falls back to English when the backend does not support the locale.
44+
/// Returns the locale when it is a supported app language; otherwise English.
5245
static String resolveContentLanguage(String localeCode) {
5346
final code = localeCode.toLowerCase();
54-
if (backendContentLanguages.contains(code)) return code;
47+
if (supportedLanguages.contains(code)) return code;
5548
return englishLanguageCode;
5649
}
5750

lib/features/home/presentation/screens/home_screen.dart

Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -303,79 +303,37 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
303303
}
304304

305305
Widget _buildBody(BuildContext context, AppLocalizations localizations) {
306-
final seriesAsync = ref.watch(seriesListFutureProvider);
307-
final fontSize = getLocalizedFontSize(AppTextSize.title);
308-
309306
return Expanded(
310307
child: RefreshIndicator(
311308
onRefresh: _onRefresh,
312-
child: seriesAsync.when(
313-
data: (seriesEither) {
314-
return seriesEither.fold(
315-
(failure) => _buildScrollableMessage(
316-
ErrorStateWidget(error: failure, onRetry: _refetchSeries),
317-
),
318-
(seriesList) {
319-
if (seriesList.isEmpty) {
320-
return _buildScrollableMessage(
321-
Padding(
322-
padding: const EdgeInsets.all(
323-
HomeScreenConstants.emptyStatePadding,
324-
),
325-
child: Text(
326-
localizations.no_feature_content,
327-
style: TextStyle(fontSize: fontSize),
328-
textAlign: TextAlign.center,
329-
),
330-
),
331-
);
332-
}
333-
334-
return CustomScrollView(
335-
physics: const AlwaysScrollableScrollPhysics(),
336-
slivers: [
337-
SliverToBoxAdapter(
338-
child: Column(
339-
mainAxisSize: MainAxisSize.min,
340-
children: [
341-
const SizedBox(
342-
height: HomeScreenConstants.cardSpacing,
343-
),
344-
_buildVerseOfDaySection(),
345-
const SizedBox(
346-
height: HomeScreenConstants.cardSpacing,
347-
),
348-
HomeShortcutsRow(
349-
onTimerTap: () => _openGatedFeature('/home/timers'),
350-
onMalaTap: () => _openGatedFeature('/mala'),
351-
),
352-
const SizedBox(
353-
height: HomeScreenConstants.cardSpacing,
354-
),
355-
_buildMyPracticesSection(),
356-
const SizedBox(
357-
height: HomeScreenConstants.cardSpacing,
358-
),
359-
FeaturedPlanSection(
360-
onSeriesTap: (series) {
361-
_log.info('Featured series tapped: ${series.id}');
362-
_navigateToSeries(series);
363-
},
364-
),
365-
],
366-
),
367-
),
368-
const SliverToBoxAdapter(child: HomeSharePrompt()),
369-
],
370-
);
371-
},
372-
);
373-
},
374-
loading: () => const SizedBox.shrink(),
375-
error:
376-
(error, stackTrace) => _buildScrollableMessage(
377-
ErrorStateWidget(error: error, onRetry: _refetchSeries),
309+
child: CustomScrollView(
310+
physics: const AlwaysScrollableScrollPhysics(),
311+
slivers: [
312+
SliverToBoxAdapter(
313+
child: Column(
314+
mainAxisSize: MainAxisSize.min,
315+
children: [
316+
const SizedBox(height: HomeScreenConstants.cardSpacing),
317+
_buildVerseOfDaySection(),
318+
const SizedBox(height: HomeScreenConstants.cardSpacing),
319+
HomeShortcutsRow(
320+
onTimerTap: () => _openGatedFeature('/home/timers'),
321+
onMalaTap: () => _openGatedFeature('/mala'),
322+
),
323+
const SizedBox(height: HomeScreenConstants.cardSpacing),
324+
_buildMyPracticesSection(),
325+
const SizedBox(height: HomeScreenConstants.cardSpacing),
326+
FeaturedPlanSection(
327+
onSeriesTap: (series) {
328+
_log.info('Featured series tapped: ${series.id}');
329+
_navigateToSeries(series);
330+
},
331+
),
332+
],
378333
),
334+
),
335+
const SliverToBoxAdapter(child: HomeSharePrompt()),
336+
],
379337
),
380338
),
381339
);

lib/features/home/presentation/screens/series_detail_screen.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:flutter_pecha/features/home/domain/entities/series.dart';
1212
import 'package:flutter_pecha/features/home/presentation/providers/series_provider.dart';
1313
import 'package:flutter_pecha/features/home/presentation/widgets/plan_list_view.dart';
1414
import 'package:flutter_pecha/features/home/presentation/widgets/series_more_bottom_sheet.dart';
15-
import 'package:flutter_pecha/features/plans/presentation/providers/user_plans_provider.dart';
1615
import 'package:flutter_pecha/features/practice/data/datasource/bookmark_remote_datasource.dart';
1716
import 'package:flutter_pecha/features/practice/presentation/providers/bookmark_providers.dart';
1817
import 'package:flutter_pecha/shared/utils/helper_functions.dart';
@@ -43,9 +42,6 @@ class SeriesDetailScreen extends ConsumerWidget {
4342

4443
@override
4544
Widget build(BuildContext context, WidgetRef ref) {
46-
ref.watch(
47-
myPlansPaginatedProvider,
48-
); // pre-warm so enrolled state is ready when list items render
4945
final seriesAsync = ref.watch(seriesByIdProvider(seriesId));
5046
final localizations = AppLocalizations.of(context)!;
5147

0 commit comments

Comments
 (0)