fix warning "no-loop-func"
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user