Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions mobile-app/lib/models/learn/curriculum_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,27 @@ class SuperBlock {
}
}

enum BlockType {
lecture,
workshop,
lab,
review,
quiz,
exam,
legacy,
enum BlockLabel {
lecture('lecture'),
workshop('workshop'),
lab('lab'),
review('review'),
quiz('quiz'),
exam('exam'),
warmup('warm-up'),
learn('learn'),
practice('practice'),
legacy('legacy');

final String value;
const BlockLabel(this.value);

static BlockLabel fromValue(String value) {
return BlockLabel.values.firstWhere(
(blockLabel) => blockLabel.value == value,
orElse: () => BlockLabel.legacy,
);
}
}

enum BlockLayout {
Expand All @@ -141,7 +154,7 @@ class Block {
final String dashedName;
final SuperBlock superBlock;
final BlockLayout layout;
final BlockType type;
final BlockLabel label;
final List description;
// Blocks in chapter-based super blocks don't have `order`.
final int? order;
Expand All @@ -152,7 +165,7 @@ class Block {
Block({
required this.superBlock,
required this.layout,
required this.type,
required this.label,
required this.name,
required this.dashedName,
required this.description,
Expand Down Expand Up @@ -192,11 +205,8 @@ class Block {
}
}

BlockType blockTypeFromString(String type) {
return BlockType.values.firstWhere(
(e) => e.name.toLowerCase() == type.toLowerCase(),
orElse: () => BlockType.legacy, // or return null if preferred
);
BlockLabel blockLabelFromString(String type) {
return BlockLabel.fromValue(type);
}

return Block(
Expand All @@ -205,9 +215,10 @@ class Block {
name: superBlockName,
),
layout: handleLayout(data['blockLayout']),
type: data['blockType'] != null
? blockTypeFromString(data['blockType'])
: BlockType.legacy,
// Support both blockLabel and blockType for backward compatibility
label: (data['blockLabel'] ?? data['blockType']) != null
? blockLabelFromString(data['blockLabel'] ?? data['blockType'])
: BlockLabel.legacy,
name: data['name'],
dashedName: dashedName,
description: description,
Expand Down
2 changes: 1 addition & 1 deletion mobile-app/lib/models/learn/daily_challenge_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DailyChallengeBlock {
name: 'Daily Challenges',
),
layout: BlockLayout.challengeGrid,
type: BlockType.legacy,
label: BlockLabel.legacy,
description: [description],
challenges: challenges
.map((overview) => ChallengeOrder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BlockTemplateView extends StatelessWidget {
model,
child,
) {
final (icon, color) = model.getIconData(block.type);
final (icon, color) = model.getIconData(block.label);

return Padding(
padding: const EdgeInsets.only(bottom: 16.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,27 @@ class BlockTemplateViewModel extends BaseViewModel {
}
}

(IconData?, Color) getIconData(BlockType type) {
(IconData?, Color) getIconData(BlockLabel type) {
switch (type) {
case BlockType.lecture:
case BlockLabel.lecture:
return (Icons.menu_book_outlined, FccColors.blue30);
case BlockType.quiz:
case BlockLabel.quiz:
return (Icons.help_outline, FccColors.orange30);
case BlockType.lab:
case BlockLabel.lab:
return (Icons.science_outlined, FccColors.green40);
case BlockType.workshop:
case BlockLabel.workshop:
return (Icons.build_outlined, FccColors.purple10);
case BlockType.exam:
case BlockLabel.exam:
return (Icons.school, FccColors.red15);
case BlockType.review:
case BlockLabel.review:
return (Icons.edit_document, FccColors.yellow10);
default: // BlockType.legacy or unknown
case BlockLabel.warmup:
return (Icons.fitbit_outlined, FccColors.blue30);
case BlockLabel.learn:
return (Icons.school_outlined, FccColors.green40);
case BlockLabel.practice:
return (Icons.edit_outlined, FccColors.purple10);
default: // BlockLabel.legacy or unknown
return (null, FccColors.blue05);
}
}
Expand Down
2 changes: 1 addition & 1 deletion mobile-app/test/unit/challenge_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main() {
return Block(
superBlock: SuperBlock(dashedName: 'superblock', name: 'Super Block'),
layout: BlockLayout.challengeList,
type: BlockType.lecture,
label: BlockLabel.lecture,
name: 'Block 1',
dashedName: 'block-1',
description: [],
Expand Down
Loading