feat: always show emoji activity, enable use to update emoji choice (#1355)

This commit is contained in:
ggurdin 2025-01-06 09:39:49 -05:00 committed by GitHub
parent 5b186f2580
commit 0203aaf209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 49 additions and 5 deletions

View file

@ -36,6 +36,10 @@ class ChoicesArray extends StatefulWidget {
final String Function(String)? getDisplayCopy;
/// activity has multiple correct answers, so user can still
/// select choices once the correct choice has been selected
final bool enableMultiSelect;
const ChoicesArray({
super.key,
required this.isLoading,
@ -50,6 +54,7 @@ class ChoicesArray extends StatefulWidget {
this.onLongPress,
this.getDisplayCopy,
this.id,
this.enableMultiSelect = false,
});
@override
@ -66,7 +71,7 @@ class ChoicesArrayState extends State<ChoicesArray> {
}
void enableInteractions() {
if (_hasSelectedCorrectChoice) return;
if (_hasSelectedCorrectChoice && !widget.enableMultiSelect) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) setState(() => interactionDisabled = false);
});

View file

@ -131,8 +131,6 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
}
}
if (constructs.isEmpty) return;
final level = _pangeaController.getAnalytics.constructListModel.level;
_addLocalMessage(eventID, constructs).then(

View file

@ -313,7 +313,7 @@ class PangeaToken {
return _didActivitySuccessfully(ActivityTypeEnum.wordMeaning) &&
daysSinceLastUseByType(a) > 7;
case ActivityTypeEnum.emoji:
return getEmoji() == null;
return true;
case ActivityTypeEnum.morphId:
if (morphFeature == null || morphTag == null) {
debugger(when: kDebugMode);

View file

@ -81,6 +81,10 @@ class PracticeActivityRecordModel {
}
}
void clearResponses() {
responses.clear();
}
/// Returns a list of [OneConstructUse] objects representing the uses of the practice activity.
///
/// The [practiceActivity] parameter is the parent event, representing the activity itself.
@ -172,6 +176,8 @@ class ActivityRecordResponse {
if (practiceActivity.activityType == ActivityTypeEnum.emoji) {
final token = practiceActivity.targetTokens!.first;
// if the emoji is already set, don't give points
if (token.getEmoji() != null) return [];
return [
OneConstructUse(
lemma: token.lemma.text,

View file

@ -1,4 +1,5 @@
import 'dart:developer';
import 'dart:math';
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
import 'package:fluffychat/pangea/models/pangea_token_model.dart';
@ -16,6 +17,12 @@ class EmojiActivityGenerator {
final PangeaToken token = req.targetTokens.first;
final List<String> emojis = await token.getEmojiChoices();
final tokenEmoji = token.getEmoji();
if (tokenEmoji != null && !emojis.contains(tokenEmoji)) {
final Random random = Random();
final int randomIndex = random.nextInt(emojis.length);
emojis[randomIndex] = tokenEmoji;
}
// TODO - modify MultipleChoiceActivity flow to allow no correct answer
return MessageActivityResponse(

View file

@ -31,7 +31,6 @@ class EmojiPracticeButton extends StatelessWidget {
: Text(emoji),
isSelected: isSelected,
onPressed: onPressed,
opacity: _shouldDoActivity ? 0.5 : 1,
)
: const SizedBox(width: 40);
}

View file

@ -25,6 +25,8 @@ class MultipleChoiceActivity extends StatefulWidget {
final Event event;
final VoidCallback? onError;
final MessageOverlayController overlayController;
final String? initialSelectedChoice;
final bool clearResponsesOnUpdate;
const MultipleChoiceActivity({
super.key,
@ -32,6 +34,8 @@ class MultipleChoiceActivity extends StatefulWidget {
required this.currentActivity,
required this.event,
required this.overlayController,
this.initialSelectedChoice,
this.clearResponsesOnUpdate = false,
this.onError,
});
@ -45,6 +49,17 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
PracticeActivityRecordModel? get currentRecordModel =>
widget.practiceCardController.currentCompletionRecord;
@override
void initState() {
super.initState();
if (widget.initialSelectedChoice != null) {
currentRecordModel?.addResponse(
text: widget.initialSelectedChoice,
score: 1,
);
}
}
@override
void didUpdateWidget(covariant MultipleChoiceActivity oldWidget) {
super.didUpdateWidget(oldWidget);
@ -89,6 +104,10 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
return;
}
if (widget.clearResponsesOnUpdate) {
currentRecordModel?.clearResponses();
}
currentRecordModel?.addResponse(
text: value,
score: isCorrect ? 1 : 0,
@ -229,6 +248,8 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
tts: practiceActivity.activityType.includeTTSOnClick ? tts : null,
enableAudio: !widget.overlayController.isPlayingAudio,
getDisplayCopy: _getDisplayCopy,
enableMultiSelect:
widget.currentActivity.activityType == ActivityTypeEnum.emoji,
),
],
);

View file

@ -303,12 +303,20 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
case ActivityTypeEnum.lemmaId:
case ActivityTypeEnum.emoji:
case ActivityTypeEnum.morphId:
final selectedChoice =
currentActivity?.activityType == ActivityTypeEnum.emoji &&
(currentActivity?.targetTokens?.isNotEmpty ?? false)
? currentActivity?.targetTokens?.first.getEmoji()
: null;
return MultipleChoiceActivity(
practiceCardController: this,
currentActivity: currentActivity!,
event: widget.pangeaMessageEvent.event,
onError: _onError,
overlayController: widget.overlayController,
initialSelectedChoice: selectedChoice,
clearResponsesOnUpdate:
currentActivity?.activityType == ActivityTypeEnum.emoji,
);
}
}