Skip to content

Commit 5c3b158

Browse files
authored
refactor: replace BlockType with BlockLabel for consistency across models (#1677)
* refactor: replace BlockType with BlockLabel for consistency across models * refactor: rename BlockLabel type to label for consistency across models
1 parent 0eaa44a commit 5c3b158

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,27 @@ class SuperBlock {
118118
}
119119
}
120120

121-
enum BlockType {
122-
lecture,
123-
workshop,
124-
lab,
125-
review,
126-
quiz,
127-
exam,
128-
legacy,
121+
enum BlockLabel {
122+
lecture('lecture'),
123+
workshop('workshop'),
124+
lab('lab'),
125+
review('review'),
126+
quiz('quiz'),
127+
exam('exam'),
128+
warmup('warm-up'),
129+
learn('learn'),
130+
practice('practice'),
131+
legacy('legacy');
132+
133+
final String value;
134+
const BlockLabel(this.value);
135+
136+
static BlockLabel fromValue(String value) {
137+
return BlockLabel.values.firstWhere(
138+
(blockLabel) => blockLabel.value == value,
139+
orElse: () => BlockLabel.legacy,
140+
);
141+
}
129142
}
130143

131144
enum BlockLayout {
@@ -141,7 +154,7 @@ class Block {
141154
final String dashedName;
142155
final SuperBlock superBlock;
143156
final BlockLayout layout;
144-
final BlockType type;
157+
final BlockLabel label;
145158
final List description;
146159
// Blocks in chapter-based super blocks don't have `order`.
147160
final int? order;
@@ -152,7 +165,7 @@ class Block {
152165
Block({
153166
required this.superBlock,
154167
required this.layout,
155-
required this.type,
168+
required this.label,
156169
required this.name,
157170
required this.dashedName,
158171
required this.description,
@@ -192,11 +205,8 @@ class Block {
192205
}
193206
}
194207

195-
BlockType blockTypeFromString(String type) {
196-
return BlockType.values.firstWhere(
197-
(e) => e.name.toLowerCase() == type.toLowerCase(),
198-
orElse: () => BlockType.legacy, // or return null if preferred
199-
);
208+
BlockLabel blockLabelFromString(String type) {
209+
return BlockLabel.fromValue(type);
200210
}
201211

202212
return Block(
@@ -205,9 +215,10 @@ class Block {
205215
name: superBlockName,
206216
),
207217
layout: handleLayout(data['blockLayout']),
208-
type: data['blockType'] != null
209-
? blockTypeFromString(data['blockType'])
210-
: BlockType.legacy,
218+
// Support both blockLabel and blockType for backward compatibility
219+
label: (data['blockLabel'] ?? data['blockType']) != null
220+
? blockLabelFromString(data['blockLabel'] ?? data['blockType'])
221+
: BlockLabel.legacy,
211222
name: data['name'],
212223
dashedName: dashedName,
213224
description: description,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class DailyChallengeBlock {
115115
name: 'Daily Challenges',
116116
),
117117
layout: BlockLayout.challengeGrid,
118-
type: BlockType.legacy,
118+
label: BlockLabel.legacy,
119119
description: [description],
120120
challenges: challenges
121121
.map((overview) => ChallengeOrder(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BlockTemplateView extends StatelessWidget {
2929
model,
3030
child,
3131
) {
32-
final (icon, color) = model.getIconData(block.type);
32+
final (icon, color) = model.getIconData(block.label);
3333

3434
return Padding(
3535
padding: const EdgeInsets.only(bottom: 16.0),

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,27 @@ class BlockTemplateViewModel extends BaseViewModel {
147147
}
148148
}
149149

150-
(IconData?, Color) getIconData(BlockType type) {
150+
(IconData?, Color) getIconData(BlockLabel type) {
151151
switch (type) {
152-
case BlockType.lecture:
152+
case BlockLabel.lecture:
153153
return (Icons.menu_book_outlined, FccColors.blue30);
154-
case BlockType.quiz:
154+
case BlockLabel.quiz:
155155
return (Icons.help_outline, FccColors.orange30);
156-
case BlockType.lab:
156+
case BlockLabel.lab:
157157
return (Icons.science_outlined, FccColors.green40);
158-
case BlockType.workshop:
158+
case BlockLabel.workshop:
159159
return (Icons.build_outlined, FccColors.purple10);
160-
case BlockType.exam:
160+
case BlockLabel.exam:
161161
return (Icons.school, FccColors.red15);
162-
case BlockType.review:
162+
case BlockLabel.review:
163163
return (Icons.edit_document, FccColors.yellow10);
164-
default: // BlockType.legacy or unknown
164+
case BlockLabel.warmup:
165+
return (Icons.fitbit_outlined, FccColors.blue30);
166+
case BlockLabel.learn:
167+
return (Icons.school_outlined, FccColors.green40);
168+
case BlockLabel.practice:
169+
return (Icons.edit_outlined, FccColors.purple10);
170+
default: // BlockLabel.legacy or unknown
165171
return (null, FccColors.blue05);
166172
}
167173
}

mobile-app/test/unit/challenge_utils_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
return Block(
3030
superBlock: SuperBlock(dashedName: 'superblock', name: 'Super Block'),
3131
layout: BlockLayout.challengeList,
32-
type: BlockType.lecture,
32+
label: BlockLabel.lecture,
3333
name: 'Block 1',
3434
dashedName: 'block-1',
3535
description: [],

0 commit comments

Comments
 (0)