fix warning "no-loop-func"

This commit is contained in:
Delucse
2020-09-25 13:22:09 +02:00
parent 5044b09701
commit 1d3f356fe7
3 changed files with 29 additions and 29 deletions
+15 -16
View File
@@ -5,30 +5,29 @@ import tutorials from '../data/tutorials.json';
const initialStatus = () => {
if(window.localStorage.getItem('status')){
var status = JSON.parse(window.localStorage.getItem('status'));
var existingTutorialIds = [];
for(var i = 0; i < tutorials.length; i++){
var tutorialsId = tutorials[i].id
existingTutorialIds.push(tutorialsId);
if(status.findIndex(status => status.id === tutorialsId) > -1){
var tasks = tutorials[i].steps.filter(step => step.type === 'task');
var existingTaskIds = [];
for(var j = 0; j < tasks.length; j++){
var tasksId = tasks[j].id;
existingTaskIds.push(tasksId);
if(status[i].tasks.findIndex(task => task.id === tasksId) === -1){
var existingTutorialIds = tutorials.map((tutorial, i) => {
var tutorialsId = tutorial.id;
var statusIndex = status.findIndex(status => status.id === tutorialsId);
if(statusIndex > -1){
var tasks = tutorial.steps.filter(step => step.type === 'task');
var existingTaskIds = tasks.map((task, j) => {
var tasksId = task.id;
if(status[statusIndex].tasks.findIndex(task => task.id === tasksId) === -1){
// task does not exist
status[i].tasks.push({id: tasksId});
status[statusIndex].tasks.push({id: tasksId});
}
}
return tasksId;
});
// deleting old tasks which do not longer exist
if(existingTaskIds.length > 0){
status[i].tasks = status[i].tasks.filter(task => existingTaskIds.indexOf(task.id) > -1);
status[statusIndex].tasks = status[statusIndex].tasks.filter(task => existingTaskIds.indexOf(task.id) > -1);
}
}
else{
status.push({id: tutorialsId, tasks: new Array(tutorials[i].steps.filter(step => step.type === 'task').length).fill({})});
status.push({id: tutorialsId, tasks: new Array(tutorial.steps.filter(step => step.type === 'task').length).fill({})});
}
}
return tutorialsId;
});
// deleting old tutorials which do not longer exist
if(existingTutorialIds.length > 0){
status = status.filter(status => existingTutorialIds.indexOf(status.id) > -1);