-
Notifications
You must be signed in to change notification settings - Fork 559
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 SimplenoteImporter #975
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add SimplenoteImporter
- Loading branch information
commit 03d4f1cd52a3819094fd4823de1ec25418543e72
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { EventEmitter } from 'events'; | ||
import CoreImporter from '../'; | ||
import { endsWith, isEmpty } from 'lodash'; | ||
|
||
class SimplenoteImporter extends EventEmitter { | ||
constructor({ noteBucket, tagBucket, options }) { | ||
super(); | ||
this.noteBucket = noteBucket; | ||
this.tagBucket = tagBucket; | ||
this.options = options; | ||
} | ||
|
||
importNotes = filesArray => { | ||
const coreImporter = new CoreImporter({ | ||
noteBucket: this.noteBucket, | ||
tagBucket: this.tagBucket, | ||
}); | ||
|
||
if (isEmpty(filesArray)) { | ||
this.emit('status', 'error', 'No file to import.'); | ||
return; | ||
} | ||
|
||
const file = filesArray[0]; | ||
|
||
if (!endsWith(file.name.toLowerCase(), '.json')) { | ||
this.emit('status', 'error', 'File name does not end in ".json".'); | ||
return; | ||
} | ||
|
||
// Limit file size we will read to 2mb | ||
if (file.size > 2000000) { | ||
this.emit('status', 'error', 'File should be less than 2 MB.'); | ||
return; | ||
} | ||
|
||
const fileReader = new FileReader(); | ||
|
||
fileReader.onload = event => { | ||
const fileContent = event.target.result; | ||
|
||
if (!fileContent) { | ||
this.emit('status', 'error', 'File was empty.'); | ||
return; | ||
} | ||
|
||
const dataObj = JSON.parse(fileContent); | ||
const noteCount = | ||
dataObj.activeNotes.length + dataObj.trashedNotes.length; | ||
|
||
coreImporter.importNotes(dataObj, this.options); | ||
this.emit('status', 'complete', noteCount); | ||
}; | ||
|
||
fileReader.readAsText(file); | ||
}; | ||
} | ||
|
||
export default SimplenoteImporter; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I have a Simplenote export file with 1,600 notes that is just over 2mb. Maybe we should set a 5mb limit? Not sure if you tested it with a large export or not.
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.
Today I tested with export files of varying sizes (80KB – 4MB). While large files did not choke the app in terms of memory, it did degrade the experience in non-trivial ways:
onClick
is firing, but the redux dispatch is being deferred until a certain point... I'm not immediately sure what is causing this.With these constraints, I felt like a 500-note (~400KB) export file was as far as I wanted to go... 😵 And since these issues are occurring after the CoreImporter is done, I'm guessing the other importers will encounter them too.
I'll see if there are some easy things we can do to address at least 1 and 2.
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.
^ Addressed in #986 #987 #988