diff --git a/lib/pangea/practice_activities/emoji_activity_generator.dart b/lib/pangea/practice_activities/emoji_activity_generator.dart index 95056d1f2..3058d4805 100644 --- a/lib/pangea/practice_activities/emoji_activity_generator.dart +++ b/lib/pangea/practice_activities/emoji_activity_generator.dart @@ -1,5 +1,4 @@ import 'package:fluffychat/pangea/constructs/construct_form.dart'; -import 'package:fluffychat/pangea/events/models/pangea_token_model.dart'; import 'package:fluffychat/pangea/lemmas/lemma_info_response.dart'; import 'package:fluffychat/pangea/practice_activities/activity_type_enum.dart'; import 'package:fluffychat/pangea/practice_activities/message_activity_request.dart'; @@ -21,35 +20,26 @@ class EmojiActivityGenerator { MessageActivityRequest req, ) async { final Map> matchInfo = {}; - final List>> tokensWithUserEmojis = []; - final List tokensNeedingServerEmojis = []; - //if user saved emojis, use those, otherwise generate. for (final token in req.targetTokens) { final List userSavedEmojis = token.vocabConstructID.userSetEmoji; - if (userSavedEmojis.isNotEmpty) { - tokensWithUserEmojis.add(MapEntry(token, userSavedEmojis)); + matchInfo[token.vocabForm] = userSavedEmojis; } else { - tokensNeedingServerEmojis.add(token); + matchInfo[token.vocabForm] = []; } } - for (final entry in tokensWithUserEmojis) { - matchInfo[entry.key.vocabForm] = entry.value; - } + final List> lemmaInfoFutures = req.targetTokens + .map((token) => token.vocabConstructID.getLemmaInfo()) + .toList(); - if (tokensNeedingServerEmojis.isNotEmpty) { - final List> lemmaInfoFutures = - tokensNeedingServerEmojis - .map((token) => token.vocabConstructID.getLemmaInfo()) - .toList(); + final List lemmaInfos = + await Future.wait(lemmaInfoFutures); - final List lemmaInfos = - await Future.wait(lemmaInfoFutures); - - for (int i = 0; i < tokensNeedingServerEmojis.length; i++) { - matchInfo[tokensNeedingServerEmojis[i].vocabForm] = lemmaInfos[i].emoji; - } + for (int i = 0; i < req.targetTokens.length; i++) { + final formKey = req.targetTokens[i].vocabForm; + matchInfo[formKey] ??= []; + matchInfo[formKey]!.addAll(lemmaInfos[i].emoji); } return MessageActivityResponse( diff --git a/lib/pangea/practice_activities/practice_match.dart b/lib/pangea/practice_activities/practice_match.dart index 6f94bf7b8..34df11014 100644 --- a/lib/pangea/practice_activities/practice_match.dart +++ b/lib/pangea/practice_activities/practice_match.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; -import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/constructs/construct_form.dart'; import 'package:fluffychat/pangea/practice_activities/practice_choice.dart'; @@ -18,52 +17,35 @@ class PracticeMatchActivity { }) { for (final ith in matchInfo.entries) { debugPrint( - 'Construct: ${ith.key}, Forms: ${ith.value}', + 'Construct: ${ith.key.form}, Forms: ${ith.value}', ); } - // for all the entries in matchInfo, remove an Strings that appear in multiple entries - final Map allForms = {}; - for (final ith in matchInfo.entries) { - for (final form in ith.value) { - if (allForms.containsKey(form)) { - allForms[form] = allForms[form]! + 1; - } else { - allForms[form] = 1; - } - } - } - for (final ith in matchInfo.entries) { - if (ith.value.isEmpty) { - matchInfo.remove(ith.key); - continue; + final List usedForms = []; + for (final matchEntry in matchInfo.entries) { + if (matchEntry.value.isEmpty) { + throw Exception( + "No forms available for construct ${matchEntry.key}", + ); } - choices.add( - PracticeChoice( - choiceContent: ith.value.firstWhere( - (element) => allForms[element] == 1, - orElse: () { - ErrorHandler.logError( - m: "no unique emoji for construct", - data: { - 'construct': ith.key, - 'forms': ith.value, - "practice_match": toJson(), - }, - ); - final String first = ith.value.first; - // remove the element from the other entry to avoid duplicates - for (final ith in matchInfo.entries) { - ith.value.removeWhere((choice) => choice == first); - } - return ith.value.first; - }, - ), - form: ith.key, + + final String choiceContent = matchEntry.value.firstWhere( + (element) => !usedForms.contains(element), + orElse: () => throw Exception( + "No unique form available for construct ${matchEntry.key}", ), ); + + choices.add( + PracticeChoice( + choiceContent: choiceContent, + form: matchEntry.key, + ), + ); + + usedForms.add(choiceContent); debugPrint( - 'Added PracticeChoice Construct: ${ith.key}, Forms: ${ith.value}', + 'Added PracticeChoice Construct: ${matchEntry.key}, Forms: ${matchEntry.value}', ); } diff --git a/lib/pangea/toolbar/widgets/message_selection_positioner.dart b/lib/pangea/toolbar/widgets/message_selection_positioner.dart index b6539a3d3..f43c95687 100644 --- a/lib/pangea/toolbar/widgets/message_selection_positioner.dart +++ b/lib/pangea/toolbar/widgets/message_selection_positioner.dart @@ -173,7 +173,7 @@ class MessageSelectionPositionerState extends State ); double get columnWidth => FluffyThemes.isColumnMode(context) - ? (FluffyThemes.columnWidth + FluffyThemes.navRailWidth + 1.0) + ? (FluffyThemes.columnWidth + FluffyThemes.navRailWidth + 2.0) : 0; double get _toolbarMaxWidth {