For an Ionic app that works with Blockly, the task should be persisted.
This works well when a task has been completed successfully. However, this ends as soon as I go backwards in the navigation.
For saving the state of a successfully completed task I use the function updateTask
.
How can the task be persisted when I move backwards in the navigation ?
The processing of the task takes place in the solveTask
function.
async solveTask() {
let solvedCorrectly = false;
let result;
let solution;
if (solvedCorrectly) {
this.task.solution = solution;
this.task.solved = true;
}
await this.storage.updateTask(this.task);
if (solvedCorrectly) {
await this.openSuccessAlert();
} else {
await this.openFailureAlert();
}
}
The
updateTask
persists with success with the state. However, it does not work when navigating backwards.
public async updateTask(task: Task) {
const path = this.navParams.getPath();
const indexToUpdate = path.tasks.findIndex(oldTask => oldTask.title === task.title && oldTask.description === task.description);
path.tasks[indexToUpdate] = task;
if (!path.inProgress && task.solved) {
path.inProgress = true;
}
this.updatePath(path);
}