diff --git a/mobile-app/lib/models/learn/curriculum_model.dart b/mobile-app/lib/models/learn/curriculum_model.dart index e5989d92f..9cb29adbb 100644 --- a/mobile-app/lib/models/learn/curriculum_model.dart +++ b/mobile-app/lib/models/learn/curriculum_model.dart @@ -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 { @@ -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; @@ -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, @@ -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( @@ -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, diff --git a/mobile-app/lib/models/learn/daily_challenge_model.dart b/mobile-app/lib/models/learn/daily_challenge_model.dart index f08a769f3..e42fff33f 100644 --- a/mobile-app/lib/models/learn/daily_challenge_model.dart +++ b/mobile-app/lib/models/learn/daily_challenge_model.dart @@ -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( diff --git a/mobile-app/lib/ui/views/learn/block/block_template_view.dart b/mobile-app/lib/ui/views/learn/block/block_template_view.dart index 0c493d803..f8b0b7bc6 100644 --- a/mobile-app/lib/ui/views/learn/block/block_template_view.dart +++ b/mobile-app/lib/ui/views/learn/block/block_template_view.dart @@ -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), diff --git a/mobile-app/lib/ui/views/learn/block/block_template_viewmodel.dart b/mobile-app/lib/ui/views/learn/block/block_template_viewmodel.dart index f82d78fda..37dc761d5 100644 --- a/mobile-app/lib/ui/views/learn/block/block_template_viewmodel.dart +++ b/mobile-app/lib/ui/views/learn/block/block_template_viewmodel.dart @@ -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); } } diff --git a/mobile-app/test/unit/challenge_utils_test.dart b/mobile-app/test/unit/challenge_utils_test.dart index 23794fb1e..68ee9c99b 100644 --- a/mobile-app/test/unit/challenge_utils_test.dart +++ b/mobile-app/test/unit/challenge_utils_test.dart @@ -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: [],