From b515264c341656a84d59705932a9e1f1abe118ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20=E2=80=9CBeau=E2=80=9D=20Collins?= Date: Tue, 1 Oct 2019 13:19:14 -0700 Subject: [PATCH] Fix ESLint Errors (#1596) * Fixes eslint errors * Include new file * jsx files can have eslint problems too fix import --- lib/boot.js | 4 ++-- lib/dialogs/import/dropzone/index.jsx | 34 +++++++++++++-------------- lib/simperium/bucket-store.js | 31 +----------------------- lib/simperium/index.js | 4 ++-- lib/simperium/local-queue-store.js | 9 +++++-- lib/simperium/store-provider.js | 30 +++++++++++++++++++++++ lib/utils/import/simplenote/index.js | 4 ++-- lib/utils/note-utils.js | 4 ++-- lib/utils/sync/nudge-unsynced.js | 4 ++-- 9 files changed, 65 insertions(+), 59 deletions(-) create mode 100644 lib/simperium/store-provider.js diff --git a/lib/boot.js b/lib/boot.js index b6a182c2c..d063e1663 100644 --- a/lib/boot.js +++ b/lib/boot.js @@ -219,12 +219,12 @@ let props = { }; // If we sign in with a different username, ensure storage is reset -const resetStorageIfAccountChanged = newAccountName => { +function resetStorageIfAccountChanged(newAccountName) { const accountName = get(store.getState(), 'settings.accountName', ''); if (accountName !== newAccountName) { client.reset(); } -}; +} // Set account email if app engine provided it if (cookie.email && config.is_app_engine) { diff --git a/lib/dialogs/import/dropzone/index.jsx b/lib/dialogs/import/dropzone/index.jsx index 0862a72f4..31caf339f 100644 --- a/lib/dialogs/import/dropzone/index.jsx +++ b/lib/dialogs/import/dropzone/index.jsx @@ -17,6 +17,23 @@ function ImporterDropzone({ const [acceptedFile, setAcceptedFile] = useState(); const [errorMessage, setErrorMessage] = useState(); + const handleAccept = acceptedFiles => { + const fileCount = acceptedFiles.length; + const label = fileCount > 1 ? `${fileCount} files` : acceptedFiles[0].name; + setAcceptedFile(label); + onAccept(acceptedFiles); + }; + + const handleReject = rejectedFiles => { + if (!multiple && rejectedFiles.length > 1) { + setErrorMessage('Choose a single file'); + } else { + setErrorMessage('File type is incorrect'); + } + setAcceptedFile(undefined); + onReset(); + }; + const onDrop = useCallback((acceptedFiles, rejectedFiles) => { if (acceptedFiles.length === 0) { handleReject(rejectedFiles); @@ -32,13 +49,6 @@ function ImporterDropzone({ onDrop, }); - const handleAccept = acceptedFiles => { - const fileCount = acceptedFiles.length; - const label = fileCount > 1 ? `${fileCount} files` : acceptedFiles[0].name; - setAcceptedFile(label); - onAccept(acceptedFiles); - }; - useEffect(() => { if (!errorMessage) { return; @@ -47,16 +57,6 @@ function ImporterDropzone({ return () => clearTimeout(timer); }, [errorMessage]); - const handleReject = rejectedFiles => { - if (!multiple && rejectedFiles.length > 1) { - setErrorMessage('Choose a single file'); - } else { - setErrorMessage('File type is incorrect'); - } - setAcceptedFile(undefined); - onReset(); - }; - const text = errorMessage ? errorMessage : 'Drag a file, or click to choose'; const DropzonePlaceholder = () => ( diff --git a/lib/simperium/bucket-store.js b/lib/simperium/bucket-store.js index 670c4db41..95c7cb192 100644 --- a/lib/simperium/bucket-store.js +++ b/lib/simperium/bucket-store.js @@ -1,31 +1,4 @@ -class StoreProvider { - constructor(config) { - this.setup = new Promise((resolve, reject) => config(resolve, reject)); - } - - provider = () => bucket => new BucketStore(bucket, this.setup); - - reset = () => - this.setup - .then(db => - Promise.all( - Array.prototype.map.call( - db.objectStoreNames, - name => - new Promise((resolve, reject) => { - const tx = db.transaction(name, 'readwrite'); - const request = tx.objectStore(name).clear(); - - request.onsuccess = () => resolve(name); - request.onerror = e => reject(e); - }) - ) - ) - ) - .catch(e => console.error('Failed to reset stores', e)); // eslint-disable-line no-console -} - -class BucketStore { +export class BucketStore { constructor(bucket, setup) { this.bucket = bucket; this.setup = setup; @@ -85,5 +58,3 @@ class BucketStore { request.onerror = e => callback(e); }); } - -export default config => new StoreProvider(config); diff --git a/lib/simperium/index.js b/lib/simperium/index.js index 917a9df36..2c43d8367 100644 --- a/lib/simperium/index.js +++ b/lib/simperium/index.js @@ -1,5 +1,5 @@ import simperium, { Client } from 'simperium'; -import bucket_store from './bucket-store'; +import store_provider from './store-provider'; import ghost_store from './ghost-store'; import localQueueStore from './local-queue-store'; import util from 'util'; @@ -25,7 +25,7 @@ function BrowserClient({ appID, token, bucketConfig, database, version }) { this.databaseName = database || 'simperium-objects'; this.databaseVersion = version || 1; let config = (this.bucketConfig = bucketConfig); - this.bucketDB = bucket_store(this.configureDb.bind(this)); + this.bucketDB = store_provider(this.configureDb.bind(this)); this.buckets = {}; let objectStoreProvider = this.bucketDB.provider(); diff --git a/lib/simperium/local-queue-store.js b/lib/simperium/local-queue-store.js index 141938297..b3a7cd139 100644 --- a/lib/simperium/local-queue-store.js +++ b/lib/simperium/local-queue-store.js @@ -32,8 +32,13 @@ function restoreTo(bucket) { ); } -export const getKey = bucket => `localQueue:${bucket.name}`; -export const getLocalQueue = bucket => bucket.channel.localQueue; +export function getKey(bucket) { + return `localQueue:${bucket.name}`; +} + +export function getLocalQueue(bucket) { + return bucket.channel.localQueue; +} const localQueueStore = { persist, restoreTo }; diff --git a/lib/simperium/store-provider.js b/lib/simperium/store-provider.js new file mode 100644 index 000000000..a2fb77ee6 --- /dev/null +++ b/lib/simperium/store-provider.js @@ -0,0 +1,30 @@ +import { BucketStore } from './bucket-store'; + +export class StoreProvider { + constructor(config) { + this.setup = new Promise((resolve, reject) => config(resolve, reject)); + } + + provider = () => bucket => new BucketStore(bucket, this.setup); + + reset = () => + this.setup + .then(db => + Promise.all( + Array.prototype.map.call( + db.objectStoreNames, + name => + new Promise((resolve, reject) => { + const tx = db.transaction(name, 'readwrite'); + const request = tx.objectStore(name).clear(); + + request.onsuccess = () => resolve(name); + request.onerror = e => reject(e); + }) + ) + ) + ) + .catch(e => console.error('Failed to reset stores', e)); // eslint-disable-line no-console +} + +export default config => new StoreProvider(config); diff --git a/lib/utils/import/simplenote/index.js b/lib/utils/import/simplenote/index.js index 00bfba07d..afb7fbc9a 100644 --- a/lib/utils/import/simplenote/index.js +++ b/lib/utils/import/simplenote/index.js @@ -61,7 +61,7 @@ class SimplenoteImporter extends EventEmitter { }; } -export const convertModificationDates = notes => { +export function convertModificationDates(notes) { return notes.map(({ lastModified, ...note }) => { // Account for Simplenote's exported `lastModified` date let modificationDate = note.modificationDate || lastModified; @@ -76,6 +76,6 @@ export const convertModificationDates = notes => { } return resultNote; }); -}; +} export default SimplenoteImporter; diff --git a/lib/utils/note-utils.js b/lib/utils/note-utils.js index e3d202f07..2d8a25841 100644 --- a/lib/utils/note-utils.js +++ b/lib/utils/note-utils.js @@ -69,9 +69,9 @@ export const noteTitleAndPreview = note => { return { title, preview }; }; -export const isMarkdown = note => { +export function isMarkdown(note) { return note && note.data && note.data.systemTags.includes('markdown'); -}; +} /** * Clean the text so it is ready to be sorted alphabetically. diff --git a/lib/utils/sync/nudge-unsynced.js b/lib/utils/sync/nudge-unsynced.js index 8dcd2b94e..e9ccaece5 100644 --- a/lib/utils/sync/nudge-unsynced.js +++ b/lib/utils/sync/nudge-unsynced.js @@ -29,7 +29,7 @@ const nudgeUnsynced = ({ noteBucket, notes, client }) => { }); }; -const updateUnsyncedNotes = ({ noteBucket, notes }) => { +function updateUnsyncedNotes({ noteBucket, notes }) { const noteHasSynced = note => new Promise(resolve => noteBucket.getVersion(note.id, (e, v) => { @@ -48,6 +48,6 @@ const updateUnsyncedNotes = ({ noteBucket, notes }) => { debug(`${unsyncedNotes.length} unsynced notes`); unsyncedNotes.forEach(note => noteBucket.update(note.id, note.data)); }); -}; +} export default nudgeUnsynced;