fix: give XP to clicked choice in audio practice

Or, upon wrong click give XP to chosen activity token
This commit is contained in:
Ava Shilling 2026-02-11 16:46:38 -05:00
parent 526681255e
commit a05796e6de
3 changed files with 47 additions and 2 deletions

View file

@ -592,9 +592,17 @@ class AnalyticsPracticeState extends State<AnalyticsPractice>
}
// 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,
);

View file

@ -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 = <PangeaToken>[];
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(),

View file

@ -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<String, dynamic> toJson() {
final json = super.toJson();