From 48ea5746d94a63f210956cc4e4ce1c603f48087a Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 10 Jan 2018 19:33:58 +0900 Subject: [PATCH 1/4] move init function to Main.js --- browser/main/Main.js | 92 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index 3fefdb456..b3b2af3e0 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -14,6 +14,11 @@ import modal from 'browser/main/lib/modal' import InitModal from 'browser/main/modals/InitModal' import mobileAnalytics from 'browser/main/lib/AwsMobileAnalyticsConfig' import eventEmitter from 'browser/main/lib/eventEmitter' +import { hashHistory } from 'react-router' +import store from 'browser/main/store' +const path = require('path') +const electron = require('electron') +const { remote } = electron class Main extends React.Component { @@ -48,6 +53,91 @@ class Main extends React.Component { } } + init () { + dataApi + .addStorage({ + name: 'My Storage', + path: path.join(remote.app.getPath('home'), 'Boostnote1') + }) + .then((data) => { + return data + }) + .then((data) => { + if (data.storage.folders[0] != null) { + return data + } else { + return dataApi + .createFolder(data.storage.key, { + color: '#1278BD', + name: 'Default' + }) + .then((_data) => { + return { + storage: _data.storage, + notes: data.notes + } + }) + } + }) + .then((data) => { + console.log(data) + store.dispatch({ + type: 'ADD_STORAGE', + storage: data.storage, + notes: data.notes + }) + + const defaultSnippetNote = dataApi + .createNote(data.storage.key, { + type: 'SNIPPET_NOTE', + folder: data.storage.folders[0].key, + title: 'Snippet note example', + description: 'Snippet note example\nYou can store a series of snippets as a single note, like Gist.', + snippets: [ + { + name: 'example.html', + mode: 'html', + content: '\n\n

Enjoy Boostnote!

\n\n' + }, + { + name: 'example.js', + mode: 'javascript', + content: 'var boostnote = document.getElementById(\'enjoy\').innerHTML\n\nconsole.log(boostnote)' + } + ] + }) + .then((note) => { + store.dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + }) + const defaultMarkdownNote = dataApi + .createNote(data.storage.key, { + type: 'MARKDOWN_NOTE', + folder: data.storage.folders[0].key, + title: 'Welcome to Boostnote!', + content: '# Welcome to Boostnote!\n## Click here to edit markdown :wave:\n\n\n\n## Docs :memo:\n- [Boostnote | Boost your happiness, productivity and creativity.](https://hackernoon.com/boostnote-boost-your-happiness-productivity-and-creativity-315034efeebe)\n- [Cloud Syncing & Backups](https://github.com/BoostIO/Boostnote/wiki/Cloud-Syncing-and-Backup)\n- [How to sync your data across Desktop and Mobile apps](https://github.com/BoostIO/Boostnote/wiki/Sync-Data-Across-Desktop-and-Mobile-apps)\n- [Convert data from **Evernote** to Boostnote.](https://github.com/BoostIO/Boostnote/wiki/Evernote)\n- [Keyboard Shortcuts](https://github.com/BoostIO/Boostnote/wiki/Keyboard-Shortcuts)\n- [Keymaps in Editor mode](https://github.com/BoostIO/Boostnote/wiki/Keymaps-in-Editor-mode)\n- [How to set syntax highlight in Snippet note](https://github.com/BoostIO/Boostnote/wiki/Syntax-Highlighting)\n\n---\n\n## Article Archive :books:\n- [Reddit English](http://bit.ly/2mOJPu7)\n- [Reddit Spanish](https://www.reddit.com/r/boostnote_es/)\n- [Reddit Chinese](https://www.reddit.com/r/boostnote_cn/)\n- [Reddit Japanese](https://www.reddit.com/r/boostnote_jp/)\n\n---\n\n## Community :beers:\n- [GitHub](http://bit.ly/2AWWzkD)\n- [Twitter](http://bit.ly/2z8BUJZ)\n- [Facebook Group](http://bit.ly/2jcca8t)' + }) + .then((note) => { + store.dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + }) + + return Promise.resolve(defaultSnippetNote) + .then(defaultMarkdownNote) + .then(() => data.storage) + }) + .then((storage) => { + hashHistory.push('/storages/' + storage.key) + }) + .catch((err) => { + throw err + }) + } + componentDidMount () { const { dispatch, config } = this.props @@ -71,7 +161,7 @@ class Main extends React.Component { }) if (data.storages.length < 1) { - modal.open(InitModal) + this.init() } }) From a28ec752e8dba2087256f1dc8a2bd95ffc3c87c1 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 10 Jan 2018 19:36:13 +0900 Subject: [PATCH 2/4] remove InitModalComponent --- browser/main/modals/InitModal.js | 254 ----------------------------- browser/main/modals/InitModal.styl | 76 --------- 2 files changed, 330 deletions(-) delete mode 100644 browser/main/modals/InitModal.js delete mode 100644 browser/main/modals/InitModal.styl diff --git a/browser/main/modals/InitModal.js b/browser/main/modals/InitModal.js deleted file mode 100644 index 024c6f425..000000000 --- a/browser/main/modals/InitModal.js +++ /dev/null @@ -1,254 +0,0 @@ -import React from 'react' -import CSSModules from 'browser/lib/CSSModules' -import styles from './InitModal.styl' -import dataApi from 'browser/main/lib/dataApi' -import store from 'browser/main/store' -import { hashHistory } from 'react-router' -import _ from 'lodash' - -const CSON = require('@rokt33r/season') -const path = require('path') -const electron = require('electron') -const { remote } = electron - -function browseFolder () { - const dialog = remote.dialog - - const defaultPath = remote.app.getPath('home') - return new Promise((resolve, reject) => { - dialog.showOpenDialog({ - title: 'Select Directory', - defaultPath, - properties: ['openDirectory', 'createDirectory'] - }, function (targetPaths) { - if (targetPaths == null) return resolve('') - resolve(targetPaths[0]) - }) - }) -} - -class InitModal extends React.Component { - constructor (props) { - super(props) - - this.state = { - path: path.join(remote.app.getPath('home'), 'Boostnote'), - migrationRequested: true, - isLoading: true, - data: null, - legacyStorageExists: false, - isSending: false - } - } - - handlePathChange (e) { - this.setState({ - path: e.target.value - }) - } - - componentDidMount () { - let data = null - try { - data = CSON.readFileSync(path.join(remote.app.getPath('userData'), 'local.json')) - } catch (err) { - console.error(err) - } - const newState = { - isLoading: false - } - if (data != null) { - newState.legacyStorageExists = true - newState.data = data - } - this.setState(newState, () => { - this.refs.createButton.focus() - }) - } - - handlePathBrowseButtonClick (e) { - browseFolder() - .then((targetPath) => { - if (targetPath.length > 0) { - this.setState({ - path: targetPath - }) - } - }) - .catch((err) => { - console.error('BrowseFAILED') - console.error(err) - }) - } - - handleSubmitButtonClick (e) { - this.setState({ - isSending: true - }, () => { - dataApi - .addStorage({ - name: 'My Storage', - path: this.state.path - }) - .then((data) => { - if (this.state.migrationRequested && _.isObject(this.state.data) && _.isArray(this.state.data.folders) && _.isArray(this.state.data.articles)) { - return dataApi.migrateFromV5Storage(data.storage.key, this.state.data) - } - return data - }) - .then((data) => { - if (data.storage.folders[0] != null) { - return data - } else { - return dataApi - .createFolder(data.storage.key, { - color: '#1278BD', - name: 'Default' - }) - .then((_data) => { - return { - storage: _data.storage, - notes: data.notes - } - }) - } - }) - .then((data) => { - console.log(data) - store.dispatch({ - type: 'ADD_STORAGE', - storage: data.storage, - notes: data.notes - }) - - const defaultSnippetNote = dataApi - .createNote(data.storage.key, { - type: 'SNIPPET_NOTE', - folder: data.storage.folders[0].key, - title: 'Snippet note example', - description: 'Snippet note example\nYou can store a series of snippets as a single note, like Gist.', - snippets: [ - { - name: 'example.html', - mode: 'html', - content: '\n\n

Enjoy Boostnote!

\n\n' - }, - { - name: 'example.js', - mode: 'javascript', - content: 'var boostnote = document.getElementById(\'enjoy\').innerHTML\n\nconsole.log(boostnote)' - } - ] - }) - .then((note) => { - store.dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - }) - const defaultMarkdownNote = dataApi - .createNote(data.storage.key, { - type: 'MARKDOWN_NOTE', - folder: data.storage.folders[0].key, - title: 'Welcome to Boostnote!', - content: '# Welcome to Boostnote!\n## Click here to edit markdown :wave:\n\n\n\n## Docs :memo:\n- [Boostnote | Boost your happiness, productivity and creativity.](https://hackernoon.com/boostnote-boost-your-happiness-productivity-and-creativity-315034efeebe)\n- [Cloud Syncing & Backups](https://github.com/BoostIO/Boostnote/wiki/Cloud-Syncing-and-Backup)\n- [How to sync your data across Desktop and Mobile apps](https://github.com/BoostIO/Boostnote/wiki/Sync-Data-Across-Desktop-and-Mobile-apps)\n- [Convert data from **Evernote** to Boostnote.](https://github.com/BoostIO/Boostnote/wiki/Evernote)\n- [Keyboard Shortcuts](https://github.com/BoostIO/Boostnote/wiki/Keyboard-Shortcuts)\n- [Keymaps in Editor mode](https://github.com/BoostIO/Boostnote/wiki/Keymaps-in-Editor-mode)\n- [How to set syntax highlight in Snippet note](https://github.com/BoostIO/Boostnote/wiki/Syntax-Highlighting)\n\n---\n\n## Article Archive :books:\n- [Reddit English](http://bit.ly/2mOJPu7)\n- [Reddit Spanish](https://www.reddit.com/r/boostnote_es/)\n- [Reddit Chinese](https://www.reddit.com/r/boostnote_cn/)\n- [Reddit Japanese](https://www.reddit.com/r/boostnote_jp/)\n\n---\n\n## Community :beers:\n- [GitHub](http://bit.ly/2AWWzkD)\n- [Twitter](http://bit.ly/2z8BUJZ)\n- [Facebook Group](http://bit.ly/2jcca8t)' - }) - .then((note) => { - store.dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - }) - - return Promise.resolve(defaultSnippetNote) - .then(defaultMarkdownNote) - .then(() => data.storage) - }) - .then((storage) => { - hashHistory.push('/storages/' + storage.key) - this.props.close() - }) - .catch((err) => { - this.setState({ - isSending: false - }) - throw err - }) - }) - } - - handleMigrationRequestedChange (e) { - this.setState({ - migrationRequested: e.target.checked - }) - } - - handleKeyDown (e) { - if (e.keyCode === 27) { - this.props.close() - } - } - - render () { - if (this.state.isLoading) { - return
- -
Preparing initialization...
-
- } - return ( -
this.handleKeyDown(e)} - > -
-
- Welcome to Boostnote! -
-
- Please select a directory for data storage. -
-
- this.handlePathChange(e)} - /> - -
- - {this.state.legacyStorageExists && -
- -
- } - -
- -
-
- -
- ) - } -} - -InitModal.propTypes = { -} - -export default CSSModules(InitModal, styles) diff --git a/browser/main/modals/InitModal.styl b/browser/main/modals/InitModal.styl deleted file mode 100644 index 62e02b682..000000000 --- a/browser/main/modals/InitModal.styl +++ /dev/null @@ -1,76 +0,0 @@ -.root - modal() - background-color #fff - max-width 100vw - max-height 100vh - overflow hidden - margin 0 - padding 150px 0 - position relative -.root--loading - @extend .root - text-align center -.spinner - font-size 100px - margin 35px auto - color $ui-text-color -.loadingMessage - color $ui-text-color - margin 15px auto 35px - -.body - padding 30px - -.body-welcome - text-align center - margin-bottom 25px - font-size 32px - color $ui-text-color - -.body-description - font-size 16px - color $ui-text-color - text-align center - margin-bottom 25px - -.body-path - margin 0 auto 25px - width 330px - -.body-path-input - height 40px - vertical-align middle - width 300px - font-size 14px - border-style solid - border-width 1px 0 1px 1px - border-color $border-color - border-top-left-radius 2px - border-bottom-left-radius 2px - padding 0 5px - -.body-path-button - height 42px - width 30px - font-size 16px - font-weight 600 - border none - border-top-right-radius 2px - border-bottom-right-radius 2px - colorPrimaryButton() - vertical-align middle -.body-migration - margin 0 auto 25px - text-align center - -.body-control - text-align center - -.body-control-createButton - colorPrimaryButton() - font-size 14px - font-weight 600 - border none - border-radius 2px - height 40px - padding 0 25px From f6bcef078999164be17b0863552e59f51ff2576e Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 10 Jan 2018 19:36:45 +0900 Subject: [PATCH 3/4] remove unnecessary variables --- browser/main/Main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index b3b2af3e0..8c4e217f2 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -10,8 +10,6 @@ import Detail from './Detail' import dataApi from 'browser/main/lib/dataApi' import _ from 'lodash' import ConfigManager from 'browser/main/lib/ConfigManager' -import modal from 'browser/main/lib/modal' -import InitModal from 'browser/main/modals/InitModal' import mobileAnalytics from 'browser/main/lib/AwsMobileAnalyticsConfig' import eventEmitter from 'browser/main/lib/eventEmitter' import { hashHistory } from 'react-router' From d44d220c55e5ea274785b8daaf79fa2bfaaa1310 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 10 Jan 2018 19:40:04 +0900 Subject: [PATCH 4/4] change default storage name from debugging to production --- browser/main/Main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/Main.js b/browser/main/Main.js index 8c4e217f2..f9be60856 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -55,7 +55,7 @@ class Main extends React.Component { dataApi .addStorage({ name: 'My Storage', - path: path.join(remote.app.getPath('home'), 'Boostnote1') + path: path.join(remote.app.getPath('home'), 'Boostnote') }) .then((data) => { return data