diff --git a/lib/pangea/models/span_data.dart b/lib/pangea/models/span_data.dart index 186e2834e..d420e1ffd 100644 --- a/lib/pangea/models/span_data.dart +++ b/lib/pangea/models/span_data.dart @@ -4,9 +4,8 @@ // SpanChoice of text in message from options // Call to server for additional/followup info -import 'package:flutter/material.dart'; - import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; import '../enum/span_choice_type.dart'; import '../enum/span_data_type.dart'; @@ -105,6 +104,7 @@ class SpanChoice { required this.type, this.feedback, this.selected = false, + this.timestamp, }); factory SpanChoice.fromJson(Map json) { return SpanChoice( @@ -117,6 +117,8 @@ class SpanChoice { : SpanChoiceType.bestCorrection, feedback: json['feedback'], selected: json['selected'] ?? false, + timestamp: + json['timestamp'] != null ? DateTime.parse(json['timestamp']) : null, ); } @@ -124,12 +126,14 @@ class SpanChoice { SpanChoiceType type; bool selected; String? feedback; + DateTime? timestamp; Map toJson() => { 'value': value, 'type': type.name, 'selected': selected, 'feedback': feedback, + 'timestamp': timestamp?.toIso8601String(), }; String feedbackToDisplay(BuildContext context) { diff --git a/lib/pangea/widgets/igc/span_card.dart b/lib/pangea/widgets/igc/span_card.dart index 4f0b22dfe..09fdba4dd 100644 --- a/lib/pangea/widgets/igc/span_card.dart +++ b/lib/pangea/widgets/igc/span_card.dart @@ -55,6 +55,7 @@ class SpanCardState extends State { // debugger(when: kDebugMode); super.initState(); getSpanDetails(); + fetchSelected(); } //get selected choice @@ -67,6 +68,23 @@ class SpanCardState extends State { return widget.scm.pangeaMatch?.match.choices?[selectedChoiceIndex!]; } + void fetchSelected() { + if (widget.scm.pangeaMatch?.match.choices == null) { + return; + } + if (selectedChoiceIndex == null) { + DateTime? mostRecent; + for (int i = 0; i < widget.scm.pangeaMatch!.match.choices!.length; i++) { + final choice = widget.scm.pangeaMatch?.match.choices![i]; + if (choice!.timestamp != null && + (mostRecent == null || choice.timestamp!.isAfter(mostRecent))) { + mostRecent = choice.timestamp; + selectedChoiceIndex = i; + } + } + } + } + Future getSpanDetails() async { try { if (widget.scm.pangeaMatch?.isITStart ?? false) return; @@ -110,6 +128,16 @@ class WordMatchContent extends StatelessWidget { Future onChoiceSelect(int index) async { controller.selectedChoiceIndex = index; + controller + .widget + .scm + .choreographer + .igc + .igcTextData + ?.matches[controller.widget.scm.matchIndex] + .match + .choices?[index] + .timestamp = DateTime.now(); controller .widget .scm @@ -152,6 +180,7 @@ class WordMatchContent extends StatelessWidget { offset: controller.widget.scm.pangeaMatch?.match.offset, ); } + final MatchCopy matchCopy = MatchCopy( context, controller.widget.scm.pangeaMatch!,