Merge pull request #310 from pangeachat/save-selection

Save span card selection
pull/1183/head
ggurdin 1 year ago committed by GitHub
commit 81ec46ed4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,9 +4,8 @@
// SpanChoice of text in message from options // SpanChoice of text in message from options
// Call to server for additional/followup info // Call to server for additional/followup info
import 'package:flutter/material.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import '../enum/span_choice_type.dart'; import '../enum/span_choice_type.dart';
import '../enum/span_data_type.dart'; import '../enum/span_data_type.dart';
@ -105,6 +104,7 @@ class SpanChoice {
required this.type, required this.type,
this.feedback, this.feedback,
this.selected = false, this.selected = false,
this.timestamp,
}); });
factory SpanChoice.fromJson(Map<String, dynamic> json) { factory SpanChoice.fromJson(Map<String, dynamic> json) {
return SpanChoice( return SpanChoice(
@ -117,6 +117,8 @@ class SpanChoice {
: SpanChoiceType.bestCorrection, : SpanChoiceType.bestCorrection,
feedback: json['feedback'], feedback: json['feedback'],
selected: json['selected'] ?? false, selected: json['selected'] ?? false,
timestamp:
json['timestamp'] != null ? DateTime.parse(json['timestamp']) : null,
); );
} }
@ -124,12 +126,14 @@ class SpanChoice {
SpanChoiceType type; SpanChoiceType type;
bool selected; bool selected;
String? feedback; String? feedback;
DateTime? timestamp;
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'value': value, 'value': value,
'type': type.name, 'type': type.name,
'selected': selected, 'selected': selected,
'feedback': feedback, 'feedback': feedback,
'timestamp': timestamp?.toIso8601String(),
}; };
String feedbackToDisplay(BuildContext context) { String feedbackToDisplay(BuildContext context) {

@ -55,6 +55,7 @@ class SpanCardState extends State<SpanCard> {
// debugger(when: kDebugMode); // debugger(when: kDebugMode);
super.initState(); super.initState();
getSpanDetails(); getSpanDetails();
fetchSelected();
} }
//get selected choice //get selected choice
@ -67,6 +68,23 @@ class SpanCardState extends State<SpanCard> {
return widget.scm.pangeaMatch?.match.choices?[selectedChoiceIndex!]; 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<void> getSpanDetails() async { Future<void> getSpanDetails() async {
try { try {
if (widget.scm.pangeaMatch?.isITStart ?? false) return; if (widget.scm.pangeaMatch?.isITStart ?? false) return;
@ -110,6 +128,16 @@ class WordMatchContent extends StatelessWidget {
Future<void> onChoiceSelect(int index) async { Future<void> onChoiceSelect(int index) async {
controller.selectedChoiceIndex = index; controller.selectedChoiceIndex = index;
controller
.widget
.scm
.choreographer
.igc
.igcTextData
?.matches[controller.widget.scm.matchIndex]
.match
.choices?[index]
.timestamp = DateTime.now();
controller controller
.widget .widget
.scm .scm
@ -152,6 +180,7 @@ class WordMatchContent extends StatelessWidget {
offset: controller.widget.scm.pangeaMatch?.match.offset, offset: controller.widget.scm.pangeaMatch?.match.offset,
); );
} }
final MatchCopy matchCopy = MatchCopy( final MatchCopy matchCopy = MatchCopy(
context, context,
controller.widget.scm.pangeaMatch!, controller.widget.scm.pangeaMatch!,

Loading…
Cancel
Save