diff --git a/lib/pangea/analytics_practice/analytics_practice_page.dart b/lib/pangea/analytics_practice/analytics_practice_page.dart index 989c4c922..618c3efb4 100644 --- a/lib/pangea/analytics_practice/analytics_practice_page.dart +++ b/lib/pangea/analytics_practice/analytics_practice_page.dart @@ -592,9 +592,17 @@ class AnalyticsPracticeState extends State } // Update activity record + // For audio activities, find the token that matches the clicked word + final tokenForChoice = isAudioActivity + ? activity.tokens.firstWhere( + (t) => t.text.content.toLowerCase() == choiceContent.toLowerCase(), + orElse: () => activity.tokens.first, + ) + : activity.tokens.first; + PracticeRecordController.onSelectChoice( choiceContent, - activity.tokens.first, + tokenForChoice, activity, ); diff --git a/lib/pangea/analytics_practice/vocab_audio_activity_generator.dart b/lib/pangea/analytics_practice/vocab_audio_activity_generator.dart index 8b794944a..3f2f7e489 100644 --- a/lib/pangea/analytics_practice/vocab_audio_activity_generator.dart +++ b/lib/pangea/analytics_practice/vocab_audio_activity_generator.dart @@ -1,4 +1,5 @@ import 'package:fluffychat/pangea/analytics_practice/analytics_practice_session_model.dart'; +import 'package:fluffychat/pangea/events/models/pangea_token_model.dart'; import 'package:fluffychat/pangea/practice_activities/lemma_activity_generator.dart'; import 'package:fluffychat/pangea/practice_activities/message_activity_request.dart'; import 'package:fluffychat/pangea/practice_activities/multiple_choice_activity_model.dart'; @@ -51,9 +52,21 @@ class VocabAudioActivityGenerator { final allChoices = [...choicesList, ...answers]; allChoices.shuffle(); + final allTokens = audioExample?.tokens ?? req.target.tokens; + final answerTokens = []; + + answerTokens.add(token); + if (audioExample != null) { + for (final t in allTokens) { + if (t != token && answers.contains(t.text.content.toLowerCase())) { + answerTokens.add(t); + } + } + } + return MessageActivityResponse( activity: VocabAudioPracticeActivityModel( - tokens: req.target.tokens, + tokens: answerTokens, langCode: req.userL2, multipleChoiceContent: MultipleChoiceActivity( choices: allChoices.toSet(), diff --git a/lib/pangea/practice_activities/practice_activity_model.dart b/lib/pangea/practice_activities/practice_activity_model.dart index 29dc56791..76fe845e6 100644 --- a/lib/pangea/practice_activities/practice_activity_model.dart +++ b/lib/pangea/practice_activities/practice_activity_model.dart @@ -358,6 +358,30 @@ class VocabAudioPracticeActivityModel required this.exampleMessage, }); + @override + OneConstructUse constructUse(String choiceContent) { + final correct = multipleChoiceContent.isCorrect(choiceContent); + final useType = correct + ? activityType.correctUse + : activityType.incorrectUse; + + // For audio activities, find the token that matches the clicked word + final matchingToken = tokens.firstWhere( + (t) => t.text.content.toLowerCase() == choiceContent.toLowerCase(), + orElse: () => tokens.first, + ); + + return OneConstructUse( + useType: useType, + constructType: ConstructTypeEnum.vocab, + metadata: ConstructUseMetaData(roomId: null, timeStamp: DateTime.now()), + category: matchingToken.pos, + lemma: matchingToken.lemma.text, + form: matchingToken.lemma.text, + xp: useType.pointValue, + ); + } + @override Map toJson() { final json = super.toJson();