Skip to content

Commit fc596f3

Browse files
feat: make chapter navigation compatible with multiple chapter based superblocks (#1683)
* feat: make chapter navigation compatible with multiple chapter based superblocks * feat: update ChapterView and related models to use superBlock names instead of chapterBasedSuperBlock * Update mobile-app/lib/ui/views/learn/utils/learn_globals.dart Co-authored-by: Huyen Nguyen <[email protected]> --------- Co-authored-by: Huyen Nguyen <[email protected]>
1 parent 35ce943 commit fc596f3

File tree

7 files changed

+98
-19
lines changed

7 files changed

+98
-19
lines changed

mobile-app/lib/app/app.router.dart

Lines changed: 57 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile-app/lib/models/learn/curriculum_model.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const chapterBasedSuperBlocks = ['full-stack-developer'];
1+
import 'package:freecodecamp/ui/views/learn/utils/learn_globals.dart';
22

33
enum SuperBlocks {
44
respWebDesignV9('responsive-web-design-v9'),
@@ -320,7 +320,8 @@ class Chapter {
320320

321321
enum ModuleType {
322322
review('review'),
323-
exam('exam');
323+
exam('exam'),
324+
certProject('cert-project');
324325

325326
static ModuleType fromValue(String value) {
326327
return ModuleType.values.firstWhere(

mobile-app/lib/ui/views/learn/chapter/chapter_view.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import 'package:freecodecamp/ui/views/learn/chapter/chapter_viewmodel.dart';
55
import 'package:stacked/stacked.dart';
66

77
class ChapterView extends StatelessWidget {
8-
const ChapterView({super.key});
8+
const ChapterView({
9+
super.key,
10+
required this.superBlockDashedName,
11+
required this.superBlockName,
12+
});
13+
14+
final String superBlockDashedName;
15+
final String superBlockName;
916

1017
@override
1118
Widget build(BuildContext context) {
1219
return ViewModelBuilder<ChapterViewModel>.reactive(
1320
viewModelBuilder: () => ChapterViewModel(),
14-
onViewModelReady: (model) => model.init(),
21+
onViewModelReady: (model) => model.init(
22+
superBlockDashedName,
23+
superBlockName,
24+
),
1525
builder: (context, model, child) {
1626
return Scaffold(
1727
backgroundColor: FccColors.gray90,
1828
appBar: AppBar(
19-
title: Text('Chapters'),
29+
title: Text(superBlockName),
2030
),
2131
body: StreamBuilder(
2232
stream: model.auth.progress.stream,

mobile-app/lib/ui/views/learn/chapter/chapter_viewmodel.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class ChapterViewModel extends BaseViewModel {
2626
notifyListeners();
2727
}
2828

29-
void init() async {
30-
superBlockFuture = requestChapters();
29+
void init(String superBlockDashedName, superBlockName) async {
30+
superBlockFuture = requestChapters(superBlockDashedName, superBlockName);
3131
developmentMode();
3232
}
3333

@@ -63,15 +63,18 @@ class ChapterViewModel extends BaseViewModel {
6363
return false;
6464
}
6565

66-
Future<SuperBlock?> requestChapters() async {
66+
Future<SuperBlock?> requestChapters(
67+
String superBlockDashedName, String superBlockName) async {
6768
String baseUrl = LearnService.baseUrl;
6869

69-
final Response res = await _dio.get('$baseUrl/full-stack-developer.json');
70+
final Response res = await _dio.get(
71+
'$baseUrl/$superBlockDashedName.json',
72+
);
7073
if (res.statusCode == 200) {
7174
return SuperBlock.fromJson(
7275
res.data,
73-
'full-stack-developer',
74-
'Certified Full Stack Developer Curriculum',
76+
superBlockDashedName,
77+
superBlockName,
7578
);
7679
}
7780

mobile-app/lib/ui/views/learn/landing/landing_viewmodel.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:freecodecamp/service/learn/daily_challenge_service.dart';
2020
import 'package:freecodecamp/service/learn/learn_offline_service.dart';
2121
import 'package:freecodecamp/service/learn/learn_service.dart';
2222
import 'package:freecodecamp/ui/views/learn/landing/landing_view.dart';
23+
import 'package:freecodecamp/ui/views/learn/utils/learn_globals.dart';
2324
import 'package:freecodecamp/ui/widgets/setup_dialog_ui.dart';
2425
import 'package:shared_preferences/shared_preferences.dart';
2526
import 'package:stacked/stacked.dart';
@@ -290,8 +291,14 @@ class LearnLandingViewModel extends BaseViewModel {
290291
}
291292

292293
void routeToSuperBlock(String dashedName, String name) async {
293-
if (dashedName == 'full-stack-developer') {
294-
_navigationService.navigateTo(Routes.chapterView);
294+
if (chapterBasedSuperBlocks.contains(dashedName)) {
295+
_navigationService.navigateTo(
296+
Routes.chapterView,
297+
arguments: ChapterViewArguments(
298+
superBlockDashedName: dashedName,
299+
superBlockName: name,
300+
),
301+
);
295302
} else {
296303
_navigationService.navigateTo(
297304
Routes.superBlockView,

mobile-app/lib/ui/views/learn/superblock/superblock_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class SuperBlockView extends StatelessWidget {
100100
}
101101

102102
if (snapshot.hasError) {
103-
return Text(context.t.error);
103+
return Center(child: Text(context.t.error));
104104
}
105105

106106
return const Center(

mobile-app/lib/ui/views/learn/utils/learn_globals.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ List<String> hasDialogue = [
77
'a2-english-for-developers',
88
'b1-english-for-developers',
99
];
10+
11+
const chapterBasedSuperBlocks = [
12+
'responsive-web-design-v9',
13+
'javascript-v9',
14+
'python-v9'
15+
];

0 commit comments

Comments
 (0)