-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Text File Importer #952
Conversation
Cleaner (and fixed!) check for no activeNotes or trashedNotes props.
… be marked deleted. Probably a better way to do this?
…r the note came from.
…it. Fixed bug where creationDate could be `NaN`.
Fixed date parsing to get correct timestamp.
…stead of throwing.
…browser 👍 The class now expects an array of `File`s to be passed into it.
for (const file of filesArray) { | ||
importTextFile(file); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we emit a 'complete'
status event at the end of this, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is async so I need to find a way to know when we've reached the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a solution in 2bdc4bf. I'm not in love with it since it may fire early due to the async nature of FileReader
, but it will probably suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw this is exactly where Promises come in handy ✨
Simplified example:
const importTextFile = file => {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = event => {
// import note here...
this.emit('status', 'progress', importedNoteCount);
resolve();
};
fileReader.readAsText(file);
});
};
Promise.all(filesArray.map(importTextFile))
.then(() => {
this.emit('status', 'complete', importedNoteCount);
});
(Not a blocker, the lastFileName strategy is probably good enough and we can promisify it later!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! I haven't worked with Promises before. 👍
* Pass object of buckets to the core importer constructor.
Co-Authored-By: roundhill <dan@automattic.com>
…lenote-electron into feature/text-file-parser
I think we may want to see if the title of the file is contained in the text. I have an export from apple notes that puts the title of the note in the file title, but not in the content: If the title isn't the first part of the content, we should use it as the title. |
Added via 876c7be |
@roundhill thanks so much for this! Is going to save me a ton of time in my life. |
Building on #922 with an importer for text files in a folder. You simply construct a
TextFileImporter
with the note and tag bucket, and then pass along an array ofFile
objects toimportNotes()
:It will only pull in files that end in .txt that are less than 1mb in size.
Refs #916