Merge pull request #964 from pangeachat/958-handle-error-in-audio-of-practice-activity

958 handle error in audio of practice activity
This commit is contained in:
ggurdin 2024-11-13 11:42:16 -05:00 committed by GitHub
commit fc8ad94687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 5 deletions

View file

@ -121,6 +121,12 @@ class MessageAnalyticsEntry {
isFirstTimeComputing = false;
}
void revealAllTokens() {
for (final token in tokensWithXp) {
token.targetTypes.remove(ActivityTypeEnum.hiddenWordListening);
}
}
bool get shouldHideToken => tokensWithXp.any(
(token) =>
token.targetTypes.contains(ActivityTypeEnum.hiddenWordListening),

View file

@ -22,6 +22,7 @@ class MessageAudioCard extends StatefulWidget {
final PangeaTokenText? selection;
final TtsController tts;
final Function(bool) setIsPlayingAudio;
final VoidCallback? onError;
const MessageAudioCard({
super.key,
@ -30,6 +31,7 @@ class MessageAudioCard extends StatefulWidget {
required this.tts,
required this.setIsPlayingAudio,
this.selection,
this.onError,
});
@override
@ -162,10 +164,8 @@ class MessageAudioCardState extends State<MessageAudioCard> {
setSectionStartAndEndFromSelection();
if (mounted) setState(() => _isLoading = false);
} catch (e, s) {
widget.onError?.call();
debugger(when: kDebugMode);
debugPrint(StackTrace.current.toString());
if (!mounted) return;
setState(() => _isLoading = false);
ErrorHandler.logError(
e: e,
s: s,
@ -175,6 +175,7 @@ class MessageAudioCardState extends State<MessageAudioCard> {
widget.messageEvent.messageDisplayLangCode,
},
);
if (mounted) setState(() => _isLoading = false);
}
}

View file

@ -22,6 +22,7 @@ class MultipleChoiceActivity extends StatefulWidget {
final PracticeActivityModel currentActivity;
final TtsController tts;
final String eventID;
final VoidCallback? onError;
const MultipleChoiceActivity({
super.key,
@ -29,6 +30,7 @@ class MultipleChoiceActivity extends StatefulWidget {
required this.currentActivity,
required this.tts,
required this.eventID,
this.onError,
});
@override
@ -143,6 +145,7 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
tts: widget.practiceCardController.widget.overlayController.tts,
setIsPlayingAudio: widget.practiceCardController.widget
.overlayController.setIsPlayingAudio,
onError: widget.onError,
),
ChoicesArray(
isLoading: false,

View file

@ -292,12 +292,11 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
_setPracticeActivity(result.last as PracticeActivityModel?);
} catch (e, s) {
_setPracticeActivity(null);
_onError();
debugger(when: kDebugMode);
ErrorHandler.logError(
e: e,
s: s,
m: 'Failed to get new activity',
data: {
'activity': currentActivity,
'record': currentCompletionRecord,
@ -306,6 +305,11 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
}
}
void _onError() {
messageAnalyticsEntry?.revealAllTokens();
_setPracticeActivity(null);
}
/// clear the current activity, record, and selection
/// fetch a new activity, including the offending activity in the request
Future<void> submitFeedback(String feedback) async {
@ -373,6 +377,7 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
currentActivity: currentActivity!,
tts: widget.ttsController,
eventID: widget.pangeaMessageEvent.eventId,
onError: _onError,
);
}
}