diff --git a/lib/pangea/practice_activities/practice_activity_model.dart b/lib/pangea/practice_activities/practice_activity_model.dart index b6016be5f..d884e1315 100644 --- a/lib/pangea/practice_activities/practice_activity_model.dart +++ b/lib/pangea/practice_activities/practice_activity_model.dart @@ -6,6 +6,7 @@ import 'package:collection/collection.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart'; +import 'package:fluffychat/pangea/constructs/construct_identifier.dart'; import 'package:fluffychat/pangea/events/models/pangea_token_model.dart'; import 'package:fluffychat/pangea/morphs/morph_features_enum.dart'; import 'package:fluffychat/pangea/practice_activities/activity_type_enum.dart'; @@ -53,7 +54,8 @@ class PracticeActivityModel { ); bool onMultipleChoiceSelect( - String choiceContent, + ConstructIdentifier choiceConstruct, + String choice, ) { if (multipleChoiceContent == null) { debugger(when: kDebugMode); @@ -67,23 +69,23 @@ class PracticeActivityModel { if (practiceTarget.isComplete || practiceTarget.record.alreadyHasMatchResponse( - targetTokens.first.vocabConstructID, - choiceContent, + choiceConstruct, + choice, )) { // the user has already selected this choice // so we don't want to record it again return false; } - final bool isCorrect = multipleChoiceContent!.isCorrect(choiceContent); + final bool isCorrect = multipleChoiceContent!.isCorrect(choice); // NOTE: the response is associated with the contructId of the choice, not the selected token // example: the user selects the word "cat" to match with the emoji 🐶 // the response is associated with correct word "dog", not the word "cat" practiceTarget.record.addResponse( - cId: targetTokens.first.vocabConstructID, + cId: choiceConstruct, target: practiceTarget, - text: choiceContent, + text: choice, score: isCorrect ? 1 : 0, ); diff --git a/lib/pangea/toolbar/message_practice/practice_controller.dart b/lib/pangea/toolbar/message_practice/practice_controller.dart index 58835a72e..d672f415b 100644 --- a/lib/pangea/toolbar/message_practice/practice_controller.dart +++ b/lib/pangea/toolbar/message_practice/practice_controller.dart @@ -153,9 +153,8 @@ class PracticeController with ChangeNotifier { if (_activity == null) return; final isCorrect = _activity!.activityType == ActivityTypeEnum.morphId - ? _activity!.onMultipleChoiceSelect( - choice.choiceContent, - ) + ? _activity! + .onMultipleChoiceSelect(choice.form.cId, choice.choiceContent) : _activity!.onMatch(token, choice); final targetId = diff --git a/lib/pangea/vocab_practice/vocab_practice_page.dart b/lib/pangea/vocab_practice/vocab_practice_page.dart index 0c05d1092..0f290d102 100644 --- a/lib/pangea/vocab_practice/vocab_practice_page.dart +++ b/lib/pangea/vocab_practice/vocab_practice_page.dart @@ -303,19 +303,22 @@ class VocabPracticeState extends State { } } - Future onSelectChoice(String choice) async { + Future onSelectChoice( + ConstructIdentifier choiceConstruct, + String choiceContent, + ) async { if (currentActivity == null) return; final activity = currentActivity!; - activity.onMultipleChoiceSelect(choice); - final correct = activity.multipleChoiceContent!.isCorrect(choice); + activity.onMultipleChoiceSelect(choiceConstruct, choiceContent); + final correct = activity.multipleChoiceContent!.isCorrect(choiceContent); // Submit answer immediately (records use and gives XP) sessionLoader.value!.submitAnswer(activity, correct); await VocabPracticeSessionRepo.updateSession(sessionLoader.value!); final transformTargetId = - 'vocab-choice-card-${choice.replaceAll(' ', '_')}'; + 'vocab-choice-card-${choiceContent.replaceAll(' ', '_')}'; if (correct) { OverlayUtil.showPointsGained(transformTargetId, 5, context); } else { diff --git a/lib/pangea/vocab_practice/vocab_practice_view.dart b/lib/pangea/vocab_practice/vocab_practice_view.dart index 7d854828b..258251bd0 100644 --- a/lib/pangea/vocab_practice/vocab_practice_view.dart +++ b/lib/pangea/vocab_practice/vocab_practice_view.dart @@ -268,7 +268,8 @@ class _ActivityChoicesWidget extends StatelessWidget { choiceId: choiceId, cardHeight: cardHeight, isEnabled: isEnabled, - onPressed: () => controller.onSelectChoice(choiceId), + onPressed: () => + controller.onSelectChoice(constructId, choiceId), ); }).toList(), ),