Skip to content

Commit

Permalink
fix filter out empty lines on text import
Browse files Browse the repository at this point in the history
  • Loading branch information
avidrucker committed Dec 24, 2023
1 parent e810117 commit f6ffccf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/tasksIO.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { addTask } from './tasksManager';

// convert tasks list to JSON string
export const exportTasksToJSON = (tasks) => {
try {
Expand Down Expand Up @@ -42,3 +44,14 @@ export const importTasksFromJSON = (jsonString) => {
return null;
}
};

export function importTasksFromString(oldTasks, importString) {
let lines = importString.split("\n");
// filter out lines that are empty or whitespace only
lines = lines.filter(line => line.trim() !== "");
let updatedTasks = oldTasks;
for(let i = 0; i < lines.length; i++) {
updatedTasks = addTask(updatedTasks, lines[i]);
}
return updatedTasks;
}

0 comments on commit f6ffccf

Please sign in to comment.