Skip to content

Commit b7fb59e

Browse files
committed
refactor: remove isStepBased property from SuperBlockView and Block model; update BlockListView and BlockLinkView to accept new parameters
1 parent 7f6d0c5 commit b7fb59e

File tree

8 files changed

+287
-116
lines changed

8 files changed

+287
-116
lines changed

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

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,32 @@ enum BlockLayout {
5353
challengeGrid,
5454
challengeLink,
5555
project,
56-
legacyChallengeList,
57-
legacyChallengeGrid,
58-
legacyChallengeLink
5956
}
6057

6158
class Block {
6259
final String name;
6360
final String dashedName;
6461
final SuperBlock superBlock;
62+
final BlockLayout layout;
63+
final BlockType type;
6564
final List description;
66-
final bool isStepBased;
6765
final int order;
6866

6967
final List<ChallengeOrder> challenges;
7068
final List<ChallengeListTile> challengeTiles;
7169

7270
Block({
7371
required this.superBlock,
72+
required this.layout,
73+
required this.type,
7474
required this.name,
7575
required this.dashedName,
7676
required this.description,
77-
required this.isStepBased,
7877
required this.order,
7978
required this.challenges,
8079
required this.challengeTiles,
8180
});
8281

83-
static bool checkIfStepBased(String superblock) {
84-
List<String> stepbased = [
85-
'2022/responsive-web-design',
86-
'a2-english-for-developers',
87-
'b1-english-for-developers'
88-
];
89-
90-
return stepbased.contains(superblock);
91-
}
92-
9382
factory Block.fromJson(
9483
Map<String, dynamic> data,
9584
List description,
@@ -102,18 +91,34 @@ class Block {
10291

10392
data['challengeTiles'] = [];
10493

94+
BlockLayout handleLayout(String? layout) {
95+
switch (layout) {
96+
case 'project-list':
97+
case 'challenge-list':
98+
case 'legacy-challenge-list':
99+
return BlockLayout.challengeList;
100+
case 'challenge-grid':
101+
case 'legacy-challenge-grid':
102+
return BlockLayout.challengeGrid;
103+
case 'link':
104+
case 'legacy-link':
105+
return BlockLayout.challengeLink;
106+
default:
107+
return BlockLayout.challengeGrid;
108+
}
109+
}
110+
105111
return Block(
106112
superBlock: SuperBlock(
107113
dashedName: superBlockDashedName,
108114
name: superBlockName,
109115
),
116+
layout: handleLayout(data['blockLayout']),
117+
type: BlockType.legacy,
110118
name: data['name'],
111119
dashedName: key,
112120
description: description,
113121
order: data['order'],
114-
isStepBased: checkIfStepBased(
115-
superBlockDashedName,
116-
),
117122
challenges: (data['challengeOrder'] as List)
118123
.map<ChallengeOrder>(
119124
(dynamic challenge) => ChallengeOrder(
@@ -137,22 +142,6 @@ class Block {
137142
.toList(),
138143
);
139144
}
140-
141-
static Map<String, dynamic> toCachedObject(Block block) {
142-
return {
143-
'superBlock': {
144-
'dashedName': block.superBlock.dashedName,
145-
'name': block.superBlock.name,
146-
},
147-
'name': block.name,
148-
'dashedName': block.dashedName,
149-
'description': block.description,
150-
'order': block.order,
151-
'isStepBased': block.isStepBased,
152-
'challengeOrder': block.challenges,
153-
'challengeTiles': block.challenges,
154-
};
155-
}
156145
}
157146

158147
class ChallengeListTile {

mobile-app/lib/service/learn/learn_offline_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class LearnOfflineService {
267267
try {
268268
SharedPreferences prefs = await SharedPreferences.getInstance();
269269

270-
Map<String, dynamic> blockToJson = Block.toCachedObject(block);
270+
Map<String, dynamic> blockToJson = {};
271271
List<String>? storedBlocks = prefs.getStringList('storedBlocks');
272272

273273
if (storedBlocks == null) {
Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import 'package:flutter/material.dart';
22
import 'package:freecodecamp/models/learn/curriculum_model.dart';
33
import 'package:freecodecamp/ui/views/learn/block/block_viewmodel.dart';
4+
import 'package:freecodecamp/ui/views/learn/block/templates/grid/grid_view.dart';
5+
import 'package:freecodecamp/ui/views/learn/block/templates/link/link_view.dart';
6+
import 'package:freecodecamp/ui/views/learn/block/templates/list/list_view.dart';
47
import 'package:stacked/stacked.dart';
58

69
class BlockTemplateView extends StatelessWidget {
710
final Block block;
811
final bool isOpen;
9-
final bool isStepBased;
1012

1113
const BlockTemplateView({
1214
Key? key,
1315
required this.block,
1416
required this.isOpen,
15-
required this.isStepBased,
1617
}) : super(key: key);
1718

1819
@override
@@ -28,73 +29,79 @@ class BlockTemplateView extends StatelessWidget {
2829
model,
2930
child,
3031
) {
31-
// double progress = model.challengesCompleted / block.challenges.length;
32-
3332
return Padding(
3433
padding: const EdgeInsets.only(bottom: 16.0),
3534
child: Container(
36-
decoration: BoxDecoration(
37-
borderRadius: BorderRadius.circular(10),
38-
border: Border.all(
39-
color: const Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
40-
),
41-
color: const Color.fromRGBO(0x1b, 0x1b, 0x32, 1),
35+
decoration: BoxDecoration(
36+
borderRadius: BorderRadius.circular(10),
37+
border: Border.all(
38+
color: const Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
4239
),
43-
padding: const EdgeInsets.all(8),
44-
width: MediaQuery.of(context).size.width,
45-
child: Container()),
46-
);
47-
},
48-
);
49-
}
50-
}
51-
52-
class ChallengeTile extends StatelessWidget {
53-
const ChallengeTile({
54-
Key? key,
55-
required this.block,
56-
required this.model,
57-
required this.step,
58-
required this.isDowloaded,
59-
required this.challengeId,
60-
}) : super(key: key);
61-
62-
final Block block;
63-
final BlockTemplateViewModel model;
64-
final int step;
65-
final bool isDowloaded;
66-
final String challengeId;
67-
68-
@override
69-
Widget build(BuildContext context) {
70-
bool isCompleted = model.completedChallenge(challengeId);
71-
72-
return TextButton(
73-
onPressed: () {
74-
model.routeToChallengeView(
75-
block,
76-
challengeId,
40+
color: const Color.fromRGBO(0x1b, 0x1b, 0x32, 1),
41+
),
42+
padding: const EdgeInsets.all(8),
43+
width: MediaQuery.of(context).size.width,
44+
child: Row(
45+
crossAxisAlignment: CrossAxisAlignment.start,
46+
children: [
47+
const Column(
48+
children: [
49+
Padding(
50+
padding: EdgeInsets.all(8.0),
51+
child: Column(
52+
children: [
53+
Icon(
54+
Icons.monitor,
55+
color: Color.fromRGBO(0x19, 0x8e, 0xee, 1),
56+
)
57+
],
58+
),
59+
),
60+
],
61+
),
62+
Expanded(
63+
child: Column(
64+
crossAxisAlignment: CrossAxisAlignment.start,
65+
children: [
66+
Text(
67+
block.name,
68+
style: const TextStyle(
69+
wordSpacing: 0,
70+
letterSpacing: 0,
71+
fontSize: 18,
72+
fontWeight: FontWeight.bold,
73+
),
74+
),
75+
Row(
76+
children: [
77+
Builder(
78+
builder: (BuildContext context) {
79+
switch (block.layout) {
80+
case BlockLayout.challengeGrid:
81+
return BlockGridView(
82+
block: block, model: model);
83+
case BlockLayout.challengeList:
84+
return BlockListView(
85+
block: block, model: model);
86+
case BlockLayout.challengeLink:
87+
return BlockLinkView(
88+
block: block, model: model);
89+
default:
90+
return BlockGridView(
91+
block: block, model: model);
92+
}
93+
},
94+
),
95+
],
96+
),
97+
],
98+
),
99+
),
100+
],
101+
),
102+
),
77103
);
78104
},
79-
style: TextButton.styleFrom(
80-
backgroundColor: isCompleted
81-
? const Color.fromRGBO(0x00, 0x2e, 0xad, 0.3)
82-
: const Color.fromRGBO(0x2a, 0x2a, 0x40, 1),
83-
shape: RoundedRectangleBorder(
84-
borderRadius: BorderRadius.circular(5),
85-
side: isCompleted
86-
? const BorderSide(
87-
width: 1,
88-
color: Color.fromRGBO(0xbc, 0xe8, 0xf1, 1),
89-
)
90-
: const BorderSide(
91-
color: Color.fromRGBO(0x3b, 0x3b, 0x4f, 1),
92-
),
93-
),
94-
),
95-
child: Text(
96-
step.toString(),
97-
),
98105
);
99106
}
100107
}

mobile-app/lib/ui/views/learn/block/block_viewmodel.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import 'dart:async';
2-
3-
import 'package:flutter/material.dart';
42
import 'package:freecodecamp/app/app.locator.dart';
53
import 'package:freecodecamp/app/app.router.dart';
64
import 'package:freecodecamp/models/learn/completed_challenge_model.dart';
@@ -119,11 +117,4 @@ class BlockTemplateViewModel extends BaseViewModel {
119117

120118
return false;
121119
}
122-
123-
Icon getIcon(bool completed) {
124-
if (completed) {
125-
return const Icon(Icons.check_circle);
126-
}
127-
return const Icon(Icons.circle_outlined);
128-
}
129120
}

0 commit comments

Comments
 (0)