fix: fix practice record construct id assignment for morph activities (#5133)

This commit is contained in:
ggurdin 2026-01-08 11:39:30 -05:00 committed by GitHub
parent 8a669b75e9
commit c4adac38f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 14 deletions

View file

@ -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,
);

View file

@ -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 =

View file

@ -303,19 +303,22 @@ class VocabPracticeState extends State<VocabPractice> {
}
}
Future<void> onSelectChoice(String choice) async {
Future<void> 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 {

View file

@ -268,7 +268,8 @@ class _ActivityChoicesWidget extends StatelessWidget {
choiceId: choiceId,
cardHeight: cardHeight,
isEnabled: isEnabled,
onPressed: () => controller.onSelectChoice(choiceId),
onPressed: () =>
controller.onSelectChoice(constructId, choiceId),
);
}).toList(),
),