mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Merge remote-tracking branch 'origin/master' into windows
Conflicts: browser/main/HomePage.js browser/main/HomePage/ArticleNavigator.js webpack.config.js
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,5 @@
|
||||
.env
|
||||
node_modules/*
|
||||
!node_modules/boost
|
||||
Boost-darwin-x64/
|
||||
backup/
|
||||
dist/
|
||||
compiled
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var BrowserWindow = require('browser-window')
|
||||
var path = require('path')
|
||||
const electron = require('electron')
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
const path = require('path')
|
||||
|
||||
var finderWindow = new BrowserWindow({
|
||||
width: 640,
|
||||
@@ -18,7 +19,7 @@ var finderWindow = new BrowserWindow({
|
||||
|
||||
var url = path.resolve(__dirname, '../browser/finder/index.html')
|
||||
|
||||
finderWindow.loadUrl('file://' + url)
|
||||
finderWindow.loadURL('file://' + url)
|
||||
|
||||
finderWindow.on('blur', function () {
|
||||
finderWindow.hide()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var BrowserWindow = require('browser-window')
|
||||
var path = require('path')
|
||||
const electron = require('electron')
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
const path = require('path')
|
||||
|
||||
var mainWindow = new BrowserWindow({
|
||||
width: 1080,
|
||||
@@ -11,11 +12,9 @@ var mainWindow = new BrowserWindow({
|
||||
'standard-window': false
|
||||
})
|
||||
|
||||
var url = path.resolve(__dirname, '../browser/main/index.html')
|
||||
const url = path.resolve(__dirname, '../browser/main/index.html')
|
||||
|
||||
mainWindow.loadUrl('file://' + url)
|
||||
|
||||
mainWindow.setVisibleOnAllWorkspaces(true)
|
||||
mainWindow.loadURL('file://' + url)
|
||||
|
||||
mainWindow.webContents.on('new-window', function (e) {
|
||||
e.preventDefault()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
var BrowserWindow = require('browser-window')
|
||||
const electron = require('electron')
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
const shell = electron.shell
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
@@ -91,10 +93,13 @@ module.exports = [
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle DevTools',
|
||||
accelerator: 'Alt+Command+I',
|
||||
click: function () {
|
||||
BrowserWindow.getFocusedWindow().toggleDevTools()
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: (function () {
|
||||
if (process.platform === 'darwin') return 'Alt+Command+I'
|
||||
else return 'Ctrl+Shift+I'
|
||||
})(),
|
||||
click: function (item, focusedWindow) {
|
||||
if (focusedWindow) BrowserWindow.getFocusedWindow().toggleDevTools()
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -123,6 +128,24 @@ module.exports = [
|
||||
},
|
||||
{
|
||||
label: 'Help',
|
||||
submenu: []
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Boost official site',
|
||||
click: function () { shell.openExternal('https://b00st.io/') }
|
||||
},
|
||||
{
|
||||
label: 'Tutorial page',
|
||||
click: function () { shell.openExternal('https://b00st.io/tutorial.html') }
|
||||
},
|
||||
{
|
||||
label: 'Discussions',
|
||||
click: function () { shell.openExternal('https://github.com/BoostIO/boost-app-discussions/issues') }
|
||||
},
|
||||
{
|
||||
label: 'Changelog',
|
||||
click: function () { shell.openExternal('https://github.com/BoostIO/boost-releases/blob/master/changelog.md') }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
var autoUpdater = require('auto-updater')
|
||||
var nn = require('node-notifier')
|
||||
var app = require('app')
|
||||
var path = require('path')
|
||||
|
||||
var version = app.getVersion()
|
||||
var versionText = (version == null || version.length === 0) ? 'DEV version' : 'v' + version
|
||||
var versionNotified = false
|
||||
autoUpdater
|
||||
.on('error', function (err, message) {
|
||||
console.error(err)
|
||||
console.error(message)
|
||||
console.log(path.resolve(__dirname, '../resources/favicon-230x230.png'))
|
||||
nn.notify({
|
||||
title: 'Error! ' + versionText,
|
||||
icon: path.resolve(__dirname, '../resources/favicon-230x230.png'),
|
||||
message: message
|
||||
})
|
||||
})
|
||||
// .on('checking-for-update', function () {
|
||||
// // Connecting
|
||||
// console.log('checking...')
|
||||
// })
|
||||
.on('update-available', function () {
|
||||
nn.notify({
|
||||
title: 'Update is available!! ' + versionText,
|
||||
icon: path.resolve(__dirname, '../resources/favicon-230x230.png'),
|
||||
message: 'Download started.. wait for the update ready.'
|
||||
})
|
||||
})
|
||||
.on('update-not-available', function () {
|
||||
if (!versionNotified) {
|
||||
nn.notify({
|
||||
title: 'Latest Build!! ' + versionText,
|
||||
icon: path.resolve(__dirname, '../resources/favicon-230x230.png'),
|
||||
message: 'Hope you to enjoy our app :D'
|
||||
})
|
||||
versionNotified = true
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = autoUpdater
|
||||
@@ -16,11 +16,8 @@ export function searchArticle (input) {
|
||||
}
|
||||
}
|
||||
|
||||
export function refreshData () {
|
||||
export function refreshData (data) {
|
||||
console.log('refreshing data')
|
||||
let data = JSON.parse(localStorage.getItem('local'))
|
||||
if (data == null) return null
|
||||
|
||||
let { folders, articles } = data
|
||||
|
||||
return {
|
||||
@@ -31,3 +28,12 @@ export function refreshData () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
SELECT_ARTICLE,
|
||||
SEARCH_ARTICLE,
|
||||
REFRESH_DATA,
|
||||
selectArticle,
|
||||
searchArticle,
|
||||
refreshData
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<link rel="stylesheet" href="../../node_modules/font-awesome/css/font-awesome.min.css" media="screen" charset="utf-8">
|
||||
<link rel="stylesheet" href="../../node_modules/devicon/devicon.min.css">
|
||||
<link rel="stylesheet" href="../../node_modules/highlight.js/styles/xcode.css">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
|
||||
<style>
|
||||
@@ -27,7 +28,8 @@
|
||||
<div id="content"></div>
|
||||
<script src="../../submodules/ace/src-min/ace.js"></script>
|
||||
<script>
|
||||
require('web-frame').setZoomLevelLimits(1, 1)
|
||||
const electron = require('electron')
|
||||
electron.webFrame.setZoomLevelLimits(1, 1)
|
||||
var scriptUrl = process.env.BOOST_ENV === 'development'
|
||||
? 'http://localhost:8080/assets/finder.js'
|
||||
: '../../compiled/finder.js'
|
||||
|
||||
@@ -6,18 +6,17 @@ import { createStore } from 'redux'
|
||||
import FinderInput from './FinderInput'
|
||||
import FinderList from './FinderList'
|
||||
import FinderDetail from './FinderDetail'
|
||||
import { selectArticle, searchArticle, refreshData } from './actions'
|
||||
import actions, { selectArticle, searchArticle } from './actions'
|
||||
import _ from 'lodash'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
import dataStore from 'boost/dataStore'
|
||||
|
||||
const electron = require('electron')
|
||||
const { remote, clipboard, ipcRenderer } = electron
|
||||
|
||||
import remote from 'remote'
|
||||
var hideFinder = remote.getGlobal('hideFinder')
|
||||
import clipboard from 'clipboard'
|
||||
|
||||
var notifier = require('node-notifier')
|
||||
var path = require('path')
|
||||
function getIconPath () {
|
||||
return path.resolve(global.__dirname, '../../resources/favicon-230x230.png')
|
||||
function notify (...args) {
|
||||
return new window.Notification(...args)
|
||||
}
|
||||
|
||||
require('../styles/finder/index.styl')
|
||||
@@ -33,11 +32,20 @@ class FinderMain extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.keyDownHandler = e => this.handleKeyDown(e)
|
||||
document.addEventListener('keydown', this.keyDownHandler)
|
||||
ReactDOM.findDOMNode(this.refs.finderInput.refs.input).focus()
|
||||
this.focusHandler = e => {
|
||||
let { dispatch } = this.props
|
||||
|
||||
dispatch(searchArticle(''))
|
||||
}
|
||||
window.addEventListener('focus', this.focusHandler)
|
||||
}
|
||||
|
||||
handleClick (e) {
|
||||
ReactDOM.findDOMNode(this.refs.finderInput.refs.input).focus()
|
||||
componentWillUnmount () {
|
||||
document.removeEventListener('keydown', this.keyDownHandler)
|
||||
window.removeEventListener('focus', this.focusHandler)
|
||||
}
|
||||
|
||||
handleKeyDown (e) {
|
||||
@@ -59,17 +67,20 @@ class FinderMain extends React.Component {
|
||||
hideFinder()
|
||||
e.preventDefault()
|
||||
}
|
||||
if (e.keyCode === 91 || e.metaKey) {
|
||||
return
|
||||
}
|
||||
|
||||
ReactDOM.findDOMNode(this.refs.finderInput.refs.input).focus()
|
||||
}
|
||||
|
||||
saveToClipboard () {
|
||||
let { activeArticle } = this.props
|
||||
clipboard.writeText(activeArticle.content)
|
||||
activityRecord.emit('FINDER_COPY')
|
||||
|
||||
notifier.notify({
|
||||
icon: getIconPath(),
|
||||
'title': 'Saved to Clipboard!',
|
||||
'message': 'Paste it wherever you want!'
|
||||
ipcRenderer.send('copy-finder')
|
||||
notify('Saved to Clipboard!', {
|
||||
body: 'Paste it wherever you want!'
|
||||
})
|
||||
hideFinder()
|
||||
}
|
||||
@@ -102,7 +113,7 @@ class FinderMain extends React.Component {
|
||||
let { articles, activeArticle, status, dispatch } = this.props
|
||||
let saveToClipboard = () => this.saveToClipboard()
|
||||
return (
|
||||
<div onClick={e => this.handleClick(e)} onKeyDown={e => this.handleKeyDown(e)} className='Finder'>
|
||||
<div onClick={e => this.handleClick(e)} className='Finder'>
|
||||
<FinderInput
|
||||
handleSearchChange={e => this.handleSearchChange(e)}
|
||||
ref='finderInput'
|
||||
@@ -156,6 +167,14 @@ function buildFilter (key) {
|
||||
return {type: TEXT_FILTER, value: key}
|
||||
}
|
||||
|
||||
function isContaining (target, needle) {
|
||||
return target.match(new RegExp(_.escapeRegExp(needle)))
|
||||
}
|
||||
|
||||
function startsWith (target, needle) {
|
||||
return target.match(new RegExp('^' + _.escapeRegExp(needle)))
|
||||
}
|
||||
|
||||
function remap (state) {
|
||||
let { articles, folders, status } = state
|
||||
|
||||
@@ -172,10 +191,10 @@ function remap (state) {
|
||||
let targetFolders
|
||||
if (folders != null) {
|
||||
let exactTargetFolders = folders.filter(folder => {
|
||||
return _.find(folderExactFilters, filter => folder.name.match(new RegExp(`^${filter.value}$`)))
|
||||
return _.find(folderExactFilters, filter => isContaining(folder.name, filter.value))
|
||||
})
|
||||
let fuzzyTargetFolders = folders.filter(folder => {
|
||||
return _.find(folderFilters, filter => folder.name.match(new RegExp(`^${filter.value}`)))
|
||||
return _.find(folderFilters, filter => startsWith(folder.name, filter.value))
|
||||
})
|
||||
targetFolders = status.targetFolders = exactTargetFolders.concat(fuzzyTargetFolders)
|
||||
|
||||
@@ -188,7 +207,7 @@ function remap (state) {
|
||||
if (textFilters.length > 0) {
|
||||
articles = textFilters.reduce((articles, textFilter) => {
|
||||
return articles.filter(article => {
|
||||
return article.title.match(new RegExp(textFilter.value, 'i')) || article.content.match(new RegExp(textFilter.value, 'i'))
|
||||
return isContaining(article.title, textFilter.value) || isContaining(article.content, textFilter.value)
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
@@ -196,7 +215,7 @@ function remap (state) {
|
||||
if (tagFilters.length > 0) {
|
||||
articles = tagFilters.reduce((articles, tagFilter) => {
|
||||
return articles.filter(article => {
|
||||
return _.find(article.tags, tag => tag.match(new RegExp(tagFilter.value, 'i')))
|
||||
return _.find(article.tags, tag => isContaining(tag, tagFilter.value))
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
@@ -205,7 +224,6 @@ function remap (state) {
|
||||
let activeArticle = _.findWhere(articles, {key: status.articleKey})
|
||||
if (activeArticle == null) activeArticle = articles[0]
|
||||
|
||||
console.log(status.search)
|
||||
return {
|
||||
articles,
|
||||
activeArticle,
|
||||
@@ -216,13 +234,19 @@ function remap (state) {
|
||||
var Finder = connect(remap)(FinderMain)
|
||||
var store = createStore(reducer)
|
||||
|
||||
function refreshData () {
|
||||
let data = dataStore.getData()
|
||||
store.dispatch(actions.refreshData(data))
|
||||
}
|
||||
|
||||
window.onfocus = e => {
|
||||
store.dispatch(refreshData())
|
||||
activityRecord.emit('FINDER_OPEN')
|
||||
refreshData()
|
||||
}
|
||||
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<Finder/>
|
||||
</Provider>
|
||||
), document.getElementById('content'))
|
||||
), document.getElementById('content'), function () {
|
||||
refreshData()
|
||||
})
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { combineReducers } from 'redux'
|
||||
import { SELECT_ARTICLE, SEARCH_ARTICLE, REFRESH_DATA } from './actions'
|
||||
|
||||
let data = JSON.parse(localStorage.getItem('local'))
|
||||
|
||||
let initialArticles = data != null ? data.articles : []
|
||||
let initialFolders = data != null ? data.folders : []
|
||||
let initialArticles = []
|
||||
let initialFolders = []
|
||||
let initialStatus = {
|
||||
articleKey: null,
|
||||
search: ''
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import React, { PropTypes} from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { CREATE_MODE, EDIT_MODE, IDLE_MODE, NEW, toggleTutorial } from 'boost/actions'
|
||||
// import UserNavigator from './HomePage/UserNavigator'
|
||||
import { EDIT_MODE, IDLE_MODE, toggleTutorial } from 'boost/actions'
|
||||
import ArticleNavigator from './HomePage/ArticleNavigator'
|
||||
import ArticleTopBar from './HomePage/ArticleTopBar'
|
||||
import ArticleList from './HomePage/ArticleList'
|
||||
import ArticleDetail from './HomePage/ArticleDetail'
|
||||
import _ from 'lodash'
|
||||
import keygen from 'boost/keygen'
|
||||
import { isModalOpen, closeModal } from 'boost/modal'
|
||||
|
||||
const electron = require('electron')
|
||||
const remote = electron.remote
|
||||
|
||||
const TEXT_FILTER = 'TEXT_FILTER'
|
||||
const FOLDER_FILTER = 'FOLDER_FILTER'
|
||||
const FOLDER_EXACT_FILTER = 'FOLDER_EXACT_FILTER'
|
||||
@@ -49,7 +50,7 @@ class HomePage extends React.Component {
|
||||
}
|
||||
|
||||
switch (status.mode) {
|
||||
case CREATE_MODE:
|
||||
|
||||
case EDIT_MODE:
|
||||
if (e.keyCode === 27) {
|
||||
detail.handleCancelButtonClick()
|
||||
@@ -57,6 +58,13 @@ class HomePage extends React.Component {
|
||||
if ((e.keyCode === 13 && (e.metaKey || e.ctrlKey)) || (e.keyCode === 83 && (e.metaKey || e.ctrlKey))) {
|
||||
detail.handleSaveButtonClick()
|
||||
}
|
||||
if (e.keyCode === 80 && e.metaKey) {
|
||||
detail.handleTogglePreviewButtonClick()
|
||||
}
|
||||
if (e.keyCode === 78 && e.metaKey) {
|
||||
nav.handleNewPostButtonClick()
|
||||
e.preventDefault()
|
||||
}
|
||||
break
|
||||
case IDLE_MODE:
|
||||
if (e.keyCode === 69) {
|
||||
@@ -91,7 +99,7 @@ class HomePage extends React.Component {
|
||||
list.selectNextArticle()
|
||||
}
|
||||
|
||||
if (e.keyCode === 65 || e.keyCode === 13 && (e.metaKey || e.ctrlKey)) {
|
||||
if ((e.keyCode === 65 && !e.metaKey && !e.ctrlKey) || (e.keyCode === 13 && e.metaKey) || (e.keyCode === 78 && e.metaKey)) {
|
||||
nav.handleNewPostButtonClick()
|
||||
e.preventDefault()
|
||||
}
|
||||
@@ -99,13 +107,14 @@ class HomePage extends React.Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
let { dispatch, status, articles, allArticles, activeArticle, folders, tags, filters } = this.props
|
||||
let { dispatch, status, user, articles, allArticles, activeArticle, folders, tags, filters } = this.props
|
||||
|
||||
return (
|
||||
<div className='HomePage'>
|
||||
<ArticleNavigator
|
||||
ref='nav'
|
||||
dispatch={dispatch}
|
||||
user={user}
|
||||
folders={folders}
|
||||
status={status}
|
||||
allArticles={allArticles}
|
||||
@@ -126,6 +135,7 @@ class HomePage extends React.Component {
|
||||
<ArticleDetail
|
||||
ref='detail'
|
||||
dispatch={dispatch}
|
||||
user={user}
|
||||
activeArticle={activeArticle}
|
||||
folders={folders}
|
||||
status={status}
|
||||
@@ -156,8 +166,16 @@ function buildFilter (key) {
|
||||
return {type: TEXT_FILTER, value: key}
|
||||
}
|
||||
|
||||
function isContaining (target, needle) {
|
||||
return target.match(new RegExp(_.escapeRegExp(needle)))
|
||||
}
|
||||
|
||||
function startsWith (target, needle) {
|
||||
return target.match(new RegExp('^' + _.escapeRegExp(needle)))
|
||||
}
|
||||
|
||||
function remap (state) {
|
||||
let { folders, articles, status } = state
|
||||
let { user, folders, articles, status } = state
|
||||
|
||||
if (articles == null) articles = []
|
||||
articles.sort((a, b) => {
|
||||
@@ -184,10 +202,10 @@ function remap (state) {
|
||||
let targetFolders
|
||||
if (folders != null) {
|
||||
let exactTargetFolders = folders.filter(folder => {
|
||||
return _.find(folderExactFilters, filter => folder.name.match(new RegExp(`^${filter.value}$`)))
|
||||
return _.findWhere(folderExactFilters, {value: folder.name})
|
||||
})
|
||||
let fuzzyTargetFolders = folders.filter(folder => {
|
||||
return _.find(folderFilters, filter => folder.name.match(new RegExp(`^${filter.value}`)))
|
||||
return _.find(folderFilters, filter => startsWith(folder.name, filter.value))
|
||||
})
|
||||
targetFolders = status.targetFolders = exactTargetFolders.concat(fuzzyTargetFolders)
|
||||
|
||||
@@ -200,7 +218,7 @@ function remap (state) {
|
||||
if (textFilters.length > 0) {
|
||||
articles = textFilters.reduce((articles, textFilter) => {
|
||||
return articles.filter(article => {
|
||||
return article.title.match(new RegExp(textFilter.value, 'i')) || article.content.match(new RegExp(textFilter.value, 'i'))
|
||||
return isContaining(article.title, textFilter.value) || isContaining(article.content, textFilter.value)
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
@@ -208,7 +226,7 @@ function remap (state) {
|
||||
if (tagFilters.length > 0) {
|
||||
articles = tagFilters.reduce((articles, tagFilter) => {
|
||||
return articles.filter(article => {
|
||||
return _.find(article.tags, tag => tag.match(new RegExp(tagFilter.value, 'i')))
|
||||
return _.find(article.tags, tag => isContaining(tag, tagFilter.value))
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
@@ -218,43 +236,8 @@ function remap (state) {
|
||||
let activeArticle = _.findWhere(articles, {key: status.articleKey})
|
||||
if (activeArticle == null) activeArticle = articles[0]
|
||||
|
||||
// remove Unsaved new article if user is not CREATE_MODE
|
||||
if (status.mode !== CREATE_MODE) {
|
||||
let targetIndex = _.findIndex(articles, article => article.status === NEW)
|
||||
|
||||
if (targetIndex >= 0) articles.splice(targetIndex, 1)
|
||||
}
|
||||
|
||||
// switching CREATE_MODE
|
||||
// restrict
|
||||
// 1. team have one folder at least
|
||||
// or Change IDLE MODE
|
||||
if (status.mode === CREATE_MODE) {
|
||||
let newArticle = _.findWhere(articles, {status: 'NEW'})
|
||||
console.log('targetFolders')
|
||||
let FolderKey = targetFolders.length > 0
|
||||
? targetFolders[0].key
|
||||
: folders[0].key
|
||||
|
||||
if (newArticle == null) {
|
||||
newArticle = {
|
||||
id: null,
|
||||
key: keygen(),
|
||||
title: '',
|
||||
content: '',
|
||||
mode: 'markdown',
|
||||
tags: [],
|
||||
FolderKey: FolderKey,
|
||||
status: NEW
|
||||
}
|
||||
articles.unshift(newArticle)
|
||||
}
|
||||
activeArticle = newArticle
|
||||
} else if (status.mode === CREATE_MODE) {
|
||||
status.mode = IDLE_MODE
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
folders,
|
||||
status,
|
||||
allArticles,
|
||||
@@ -270,11 +253,9 @@ function remap (state) {
|
||||
}
|
||||
|
||||
HomePage.propTypes = {
|
||||
params: PropTypes.shape({
|
||||
userId: PropTypes.string
|
||||
}),
|
||||
status: PropTypes.shape({
|
||||
userId: PropTypes.string
|
||||
status: PropTypes.shape(),
|
||||
user: PropTypes.shape({
|
||||
name: PropTypes.string
|
||||
}),
|
||||
articles: PropTypes.array,
|
||||
allArticles: PropTypes.array,
|
||||
@@ -285,7 +266,8 @@ HomePage.propTypes = {
|
||||
folder: PropTypes.array,
|
||||
tag: PropTypes.array,
|
||||
text: PropTypes.array
|
||||
})
|
||||
}),
|
||||
tags: PropTypes.array
|
||||
}
|
||||
|
||||
export default connect(remap)(HomePage)
|
||||
|
||||
151
browser/main/HomePage/ArticleDetail/ShareButton.js
Normal file
151
browser/main/HomePage/ArticleDetail/ShareButton.js
Normal file
@@ -0,0 +1,151 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import api from 'boost/api'
|
||||
import clientKey from 'boost/clientKey'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
const clipboard = require('electron').clipboard
|
||||
|
||||
function getDefault () {
|
||||
return {
|
||||
openDropdown: false,
|
||||
isSharing: false,
|
||||
// Fetched url
|
||||
url: null,
|
||||
// for tooltip Copy -> Copied!
|
||||
copied: false,
|
||||
failed: false
|
||||
}
|
||||
}
|
||||
|
||||
export default class ShareButton extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
this.state = getDefault()
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
this.setState(getDefault())
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.dropdownInterceptor = e => {
|
||||
this.dropdownClicked = true
|
||||
}
|
||||
ReactDOM.findDOMNode(this.refs.dropdown).addEventListener('click', this.dropdownInterceptor)
|
||||
this.shareViaPublicURLHandler = e => {
|
||||
this.handleShareViaPublicURLClick(e)
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
document.removeEventListener('click', this.dropdownHandler)
|
||||
ReactDOM.findDOMNode(this.refs.dropdown).removeEventListener('click', this.dropdownInterceptor)
|
||||
}
|
||||
|
||||
handleOpenButtonClick (e) {
|
||||
this.openDropdown()
|
||||
if (this.dropdownHandler == null) {
|
||||
this.dropdownHandler = e => {
|
||||
if (!this.dropdownClicked) {
|
||||
this.closeDropdown()
|
||||
} else {
|
||||
this.dropdownClicked = false
|
||||
}
|
||||
}
|
||||
}
|
||||
document.removeEventListener('click', this.dropdownHandler)
|
||||
document.addEventListener('click', this.dropdownHandler)
|
||||
}
|
||||
|
||||
openDropdown () {
|
||||
this.setState({openDropdown: true})
|
||||
}
|
||||
|
||||
closeDropdown () {
|
||||
document.removeEventListener('click', this.dropdownHandler)
|
||||
this.setState({openDropdown: false})
|
||||
}
|
||||
|
||||
handleShareViaPublicURLClick (e) {
|
||||
let { user } = this.props
|
||||
let input = Object.assign({}, this.props.article, {
|
||||
clientKey: clientKey.get(),
|
||||
writerName: user.name
|
||||
})
|
||||
this.setState({
|
||||
isSharing: true,
|
||||
failed: false
|
||||
}, () => {
|
||||
api.shareViaPublicURL(input)
|
||||
.then(res => {
|
||||
let url = res.body.url
|
||||
this.setState({url: url, isSharing: false})
|
||||
activityRecord.emit('ARTICLE_SHARE')
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
this.setState({isSharing: false, failed: true})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleCopyURLClick () {
|
||||
clipboard.writeText(this.state.url)
|
||||
this.setState({copied: true})
|
||||
}
|
||||
|
||||
// Restore copy url tooltip
|
||||
handleCopyURLMouseLeave () {
|
||||
this.setState({copied: false})
|
||||
}
|
||||
|
||||
render () {
|
||||
let hasPublicURL = this.state.url != null
|
||||
return (
|
||||
<div className='ShareButton'>
|
||||
<button ref='openButton' onClick={e => this.handleOpenButtonClick(e)} className='ShareButton-open-button'>
|
||||
<i className='fa fa-fw fa-share-alt'/>
|
||||
{
|
||||
this.state.openDropdown ? null : (
|
||||
<span className='tooltip'>Share</span>
|
||||
)
|
||||
}
|
||||
</button>
|
||||
<div ref='dropdown' className={'share-dropdown' + (this.state.openDropdown ? '' : ' hide')}>
|
||||
{
|
||||
!hasPublicURL ? (
|
||||
<button
|
||||
onClick={e => this.shareViaPublicURLHandler(e)}
|
||||
ref='sharePublicURL'
|
||||
disabled={this.state.isSharing}>
|
||||
<i className='fa fa-fw fa-external-link'/> {this.state.failed ? 'Failed : Click to Try again' : !this.state.isSharing ? 'Share via public URL' : 'Sharing...'}
|
||||
</button>
|
||||
) : (
|
||||
<div className='ShareButton-url'>
|
||||
<input className='ShareButton-url-input' value={this.state.url} readOnly/>
|
||||
<button
|
||||
onClick={e => this.handleCopyURLClick(e)}
|
||||
className='ShareButton-url-button'
|
||||
onMouseLeave={e => this.handleCopyURLMouseLeave(e)}
|
||||
>
|
||||
<i className='fa fa-fw fa-clipboard'/>
|
||||
<div className='ShareButton-url-button-tooltip'>{this.state.copied ? 'Copied!' : 'Copy URL'}</div>
|
||||
</button>
|
||||
<div className='ShareButton-url-alert'>This url is valid for 7 days.</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ShareButton.propTypes = {
|
||||
article: PropTypes.shape({
|
||||
publicURL: PropTypes.string
|
||||
}),
|
||||
user: PropTypes.shape({
|
||||
name: PropTypes.string
|
||||
})
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import MarkdownPreview from 'boost/components/MarkdownPreview'
|
||||
import CodeEditor from 'boost/components/CodeEditor'
|
||||
import {
|
||||
IDLE_MODE,
|
||||
CREATE_MODE,
|
||||
EDIT_MODE,
|
||||
switchMode,
|
||||
switchArticle,
|
||||
@@ -25,6 +24,11 @@ import TagLink from 'boost/components/TagLink'
|
||||
import TagSelect from 'boost/components/TagSelect'
|
||||
import ModeSelect from 'boost/components/ModeSelect'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
import api from 'boost/api'
|
||||
import ShareButton from './ShareButton'
|
||||
|
||||
const electron = require('electron')
|
||||
const clipboard = electron.clipboard
|
||||
|
||||
const BRAND_COLOR = '#18AF90'
|
||||
|
||||
@@ -85,6 +89,10 @@ const modeSelectTutorialElement = (
|
||||
</svg>
|
||||
)
|
||||
|
||||
function notify (...args) {
|
||||
return new window.Notification(...args)
|
||||
}
|
||||
|
||||
function makeInstantArticle (article) {
|
||||
return Object.assign({}, article)
|
||||
}
|
||||
@@ -100,12 +108,16 @@ export default class ArticleDetail extends React.Component {
|
||||
isTagChanged: false,
|
||||
isTitleChanged: false,
|
||||
isContentChanged: false,
|
||||
isModeChanged: false
|
||||
isModeChanged: false,
|
||||
openShareDropdown: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.refreshTimer = setInterval(() => this.forceUpdate(), 60 * 1000)
|
||||
this.shareDropdownInterceptor = e => {
|
||||
e.stopPropagation()
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
@@ -114,7 +126,7 @@ export default class ArticleDetail extends React.Component {
|
||||
|
||||
componentDidUpdate (prevProps) {
|
||||
let isModeChanged = prevProps.status.mode !== this.props.status.mode
|
||||
if (isModeChanged && this.props.status.mode !== IDLE_MODE) {
|
||||
if (isModeChanged && this.props.status.mode === EDIT_MODE) {
|
||||
ReactDOM.findDOMNode(this.refs.title).focus()
|
||||
}
|
||||
}
|
||||
@@ -124,6 +136,7 @@ export default class ArticleDetail extends React.Component {
|
||||
|
||||
let isArticleChanged = nextProps.activeArticle != null && (nextProps.activeArticle.key !== this.state.article.key)
|
||||
let isModeChanged = nextProps.status.mode !== this.props.status.mode
|
||||
|
||||
// Reset article input
|
||||
if (isArticleChanged || (isModeChanged && nextProps.status.mode !== IDLE_MODE)) {
|
||||
Object.assign(nextState, {
|
||||
@@ -154,6 +167,14 @@ export default class ArticleDetail extends React.Component {
|
||||
)
|
||||
}
|
||||
|
||||
handleClipboardButtonClick (e) {
|
||||
activityRecord.emit('MAIN_DETAIL_COPY')
|
||||
clipboard.writeText(this.props.activeArticle.content)
|
||||
notify('Saved to Clipboard!', {
|
||||
body: 'Paste it wherever you want!'
|
||||
})
|
||||
}
|
||||
|
||||
handleEditButtonClick (e) {
|
||||
let { dispatch } = this.props
|
||||
dispatch(switchMode(EDIT_MODE))
|
||||
@@ -176,7 +197,7 @@ export default class ArticleDetail extends React.Component {
|
||||
}
|
||||
|
||||
renderIdle () {
|
||||
let { status, activeArticle, folders } = this.props
|
||||
let { status, activeArticle, folders, user } = this.props
|
||||
|
||||
let tags = activeArticle.tags != null ? activeArticle.tags.length > 0
|
||||
? activeArticle.tags.map(tag => {
|
||||
@@ -185,8 +206,13 @@ export default class ArticleDetail extends React.Component {
|
||||
: (
|
||||
<span className='noTags'>Not tagged yet</span>
|
||||
) : null
|
||||
|
||||
let folder = _.findWhere(folders, {key: activeArticle.FolderKey})
|
||||
|
||||
let title = activeArticle.title.trim().length === 0
|
||||
? <small>(Untitled)</small>
|
||||
: activeArticle.title
|
||||
|
||||
return (
|
||||
<div className='ArticleDetail idle'>
|
||||
{this.state.openDeleteConfirmMenu
|
||||
@@ -214,6 +240,15 @@ export default class ArticleDetail extends React.Component {
|
||||
<div className='tags'><i className='fa fa-fw fa-tags'/>{tags}</div>
|
||||
</div>
|
||||
<div className='right'>
|
||||
<ShareButton
|
||||
article={activeArticle}
|
||||
user={user}
|
||||
/>
|
||||
|
||||
<button onClick={e => this.handleClipboardButtonClick(e)} className='editBtn'>
|
||||
<i className='fa fa-fw fa-clipboard'/><span className='tooltip'>Copy to clipboard</span>
|
||||
</button>
|
||||
|
||||
<button onClick={e => this.handleEditButtonClick(e)} className='editBtn'>
|
||||
<i className='fa fa-fw fa-edit'/><span className='tooltip'>Edit (e)</span>
|
||||
</button>
|
||||
@@ -232,7 +267,7 @@ export default class ArticleDetail extends React.Component {
|
||||
<div className='detailPanel'>
|
||||
<div className='header'>
|
||||
<ModeIcon className='mode' mode={activeArticle.mode}/>
|
||||
<div className='title'>{activeArticle.title}</div>
|
||||
<div className='title'>{title}</div>
|
||||
</div>
|
||||
{activeArticle.mode === 'markdown'
|
||||
? <MarkdownPreview content={activeArticle.content}/>
|
||||
@@ -247,13 +282,14 @@ export default class ArticleDetail extends React.Component {
|
||||
handleCancelButtonClick (e) {
|
||||
let { activeArticle, dispatch } = this.props
|
||||
|
||||
dispatch(unlockStatus())
|
||||
if (activeArticle.status === NEW) dispatch(switchArticle(null))
|
||||
if (activeArticle.status === NEW) {
|
||||
dispatch(switchArticle(null))
|
||||
}
|
||||
dispatch(switchMode(IDLE_MODE))
|
||||
}
|
||||
|
||||
handleSaveButtonClick (e) {
|
||||
let { dispatch, folders, filters } = this.props
|
||||
let { dispatch, folders, status } = this.props
|
||||
let article = this.state.article
|
||||
let newArticle = Object.assign({}, article)
|
||||
|
||||
@@ -262,13 +298,17 @@ export default class ArticleDetail extends React.Component {
|
||||
|
||||
dispatch(unlockStatus())
|
||||
|
||||
delete newArticle.status
|
||||
newArticle.status = null
|
||||
newArticle.updatedAt = new Date()
|
||||
newArticle.title = newArticle.title.trim()
|
||||
if (newArticle.createdAt == null) {
|
||||
newArticle.createdAt = new Date()
|
||||
activityRecord.emit('ARTICLE_CREATE')
|
||||
if (newArticle.title.length === 0) {
|
||||
newArticle.title = `Created at ${moment(newArticle.createdAt).format('YYYY/MM/DD HH:mm')}`
|
||||
}
|
||||
activityRecord.emit('ARTICLE_CREATE', {mode: newArticle.mode})
|
||||
} else {
|
||||
activityRecord.emit('ARTICLE_UPDATE')
|
||||
activityRecord.emit('ARTICLE_UPDATE', {mode: newArticle.mode})
|
||||
}
|
||||
|
||||
dispatch(updateArticle(newArticle))
|
||||
@@ -277,7 +317,7 @@ export default class ArticleDetail extends React.Component {
|
||||
// Searchを初期化し、更新先のFolder filterをかける
|
||||
// かかれていない時に
|
||||
// Searchを初期化する
|
||||
if (filters.folder.length !== 0) dispatch(switchFolder(folder.name))
|
||||
if (status.targetFolders.length > 0) dispatch(switchFolder(folder.name))
|
||||
else dispatch(clearSearch())
|
||||
dispatch(switchArticle(newArticle.key))
|
||||
}
|
||||
@@ -319,8 +359,6 @@ export default class ArticleDetail extends React.Component {
|
||||
let article = this.state.article
|
||||
article.tags = tags
|
||||
|
||||
this.setState({article: article})
|
||||
|
||||
let _isTagChanged = _.difference(article.tags, this.props.activeArticle.tags).length > 0 || _.difference(this.props.activeArticle.tags, article.tags).length > 0
|
||||
|
||||
let { isTitleChanged, isContentChanged, isArticleEdited, isModeChanged } = this.state
|
||||
@@ -378,6 +416,11 @@ export default class ArticleDetail extends React.Component {
|
||||
}
|
||||
|
||||
handleContentChange (e, value) {
|
||||
let { status } = this.props
|
||||
if (status.mode === IDLE_MODE) {
|
||||
return
|
||||
}
|
||||
|
||||
let { article } = this.state
|
||||
article.content = value
|
||||
let _isContentChanged = article.content !== this.props.activeArticle.content
|
||||
@@ -404,7 +447,36 @@ export default class ArticleDetail extends React.Component {
|
||||
}
|
||||
|
||||
handleTogglePreviewButtonClick (e) {
|
||||
this.setState({previewMode: !this.state.previewMode})
|
||||
if (this.state.article.mode === 'markdown') {
|
||||
if (!this.state.previewMode) {
|
||||
let cursorPosition = this.refs.code.getCursorPosition()
|
||||
let firstVisibleRow = this.refs.code.getFirstVisibleRow()
|
||||
this.setState({
|
||||
previewMode: true,
|
||||
cursorPosition,
|
||||
firstVisibleRow
|
||||
}, function () {
|
||||
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
||||
let anchors = previewEl.querySelectorAll('.lineAnchor')
|
||||
for (let i = 0; i < anchors.length; i++) {
|
||||
if (parseInt(anchors[i].dataset.key, 10) > cursorPosition.row || i === anchors.length - 1) {
|
||||
var targetAnchor = anchors[i > 0 ? i - 1 : 0]
|
||||
previewEl.scrollTop = targetAnchor.offsetTop - 100
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
previewMode: false
|
||||
}, function () {
|
||||
console.log(this.state.cursorPosition)
|
||||
this.refs.code.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
||||
this.refs.code.scrollToLine(this.state.firstVisibleRow)
|
||||
this.refs.code.editor.focus()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleTitleKeyDown (e) {
|
||||
@@ -449,18 +521,36 @@ export default class ArticleDetail extends React.Component {
|
||||
<div className='right'>
|
||||
{
|
||||
this.state.article.mode === 'markdown'
|
||||
? (<button className='preview' onClick={e => this.handleTogglePreviewButtonClick(e)}>{!this.state.previewMode ? 'Preview' : 'Edit'}</button>)
|
||||
? (<button className='preview' onClick={e => this.handleTogglePreviewButtonClick(e)}>
|
||||
{
|
||||
!this.state.previewMode
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
}
|
||||
</button>)
|
||||
: null
|
||||
}
|
||||
<button onClick={e => this.handleCancelButtonClick(e)}>Cancel</button>
|
||||
<button onClick={e => this.handleSaveButtonClick(e)} className='primary'>Save</button>
|
||||
<button onClick={e => this.handleCancelButtonClick(e)}>
|
||||
Cancel
|
||||
</button>
|
||||
<button onClick={e => this.handleSaveButtonClick(e)} className='primary'>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className='detailBody'>
|
||||
<div className='detailPanel'>
|
||||
<div className='header'>
|
||||
<div className='title'>
|
||||
<input onKeyDown={e => this.handleTitleKeyDown(e)} placeholder='Title' ref='title' value={this.state.article.title} onChange={e => this.handleTitleChange(e)}/>
|
||||
<input
|
||||
onKeyDown={e => this.handleTitleKeyDown(e)}
|
||||
placeholder={this.state.article.createdAt == null
|
||||
? `Created at ${moment().format('YYYY/MM/DD HH:mm')}`
|
||||
: 'Title'}
|
||||
ref='title'
|
||||
value={this.state.article.title}
|
||||
onChange={e => this.handleTitleChange(e)}
|
||||
/>
|
||||
</div>
|
||||
<ModeSelect
|
||||
ref='mode'
|
||||
@@ -474,7 +564,7 @@ export default class ArticleDetail extends React.Component {
|
||||
</div>
|
||||
|
||||
{this.state.previewMode
|
||||
? <MarkdownPreview content={this.state.article.content}/>
|
||||
? <MarkdownPreview ref='preview' content={this.state.article.content}/>
|
||||
: (<CodeEditor
|
||||
ref='code'
|
||||
onChange={(e, value) => this.handleContentChange(e, value)}
|
||||
@@ -495,7 +585,6 @@ export default class ArticleDetail extends React.Component {
|
||||
if (activeArticle == null) return this.renderEmpty()
|
||||
|
||||
switch (status.mode) {
|
||||
case CREATE_MODE:
|
||||
case EDIT_MODE:
|
||||
return this.renderEdit()
|
||||
case IDLE_MODE:
|
||||
@@ -509,7 +598,8 @@ export default class ArticleDetail extends React.Component {
|
||||
ArticleDetail.propTypes = {
|
||||
status: PropTypes.shape(),
|
||||
activeArticle: PropTypes.shape(),
|
||||
activeUser: PropTypes.shape(),
|
||||
user: PropTypes.shape(),
|
||||
folders: PropTypes.array,
|
||||
dispatch: PropTypes.func
|
||||
}
|
||||
ArticleDetail.prototype.linkState = linkState
|
||||
@@ -80,6 +80,12 @@ export default class ArticleList extends React.Component {
|
||||
: (<span>Not tagged yet</span>)
|
||||
let folder = _.findWhere(folders, {key: article.FolderKey})
|
||||
|
||||
let title = article.status !== NEW
|
||||
? article.title.trim().length === 0
|
||||
? <small>(Untitled)</small>
|
||||
: article.title
|
||||
: '(New article)'
|
||||
|
||||
return (
|
||||
<div key={'article-' + article.key}>
|
||||
<div onClick={e => this.handleArticleClick(article)(e)} className={'articleItem' + (activeArticle.key === article.key ? ' active' : '')}>
|
||||
@@ -91,7 +97,7 @@ export default class ArticleList extends React.Component {
|
||||
<span className='updatedAt'>{article.status != null ? article.status : moment(article.updatedAt).fromNow()}</span>
|
||||
</div>
|
||||
<div className='middle'>
|
||||
<ModeIcon className='mode' mode={article.mode}/> <div className='title'>{article.status !== NEW ? article.title : '(New article)'}</div>
|
||||
<ModeIcon className='mode' mode={article.mode}/> <div className='title'>{title}</div>
|
||||
</div>
|
||||
<div className='bottom'>
|
||||
<div className='tags'><i className='fa fa-fw fa-tags'/>{tagElements}</div>
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import { findWhere } from 'lodash'
|
||||
import { setSearchFilter, switchFolder, switchMode, CREATE_MODE } from 'boost/actions'
|
||||
import { setSearchFilter, switchFolder, switchMode, switchArticle, updateArticle, clearNewArticle, EDIT_MODE } from 'boost/actions'
|
||||
import { openModal } from 'boost/modal'
|
||||
import FolderMark from 'boost/components/FolderMark'
|
||||
import Preferences from 'boost/components/modal/Preferences'
|
||||
import CreateNewFolder from 'boost/components/modal/CreateNewFolder'
|
||||
|
||||
import remote from 'remote'
|
||||
let mainEnv = remote.getGlobal('process').env
|
||||
let userName = mainEnv.USER != null
|
||||
? mainEnv.USER
|
||||
: mainEnv.USERNAME
|
||||
import keygen from 'boost/keygen'
|
||||
|
||||
const BRAND_COLOR = '#18AF90'
|
||||
|
||||
@@ -68,9 +63,28 @@ export default class ArticleNavigator extends React.Component {
|
||||
}
|
||||
|
||||
handleNewPostButtonClick (e) {
|
||||
let { dispatch } = this.props
|
||||
let { dispatch, folders, status } = this.props
|
||||
let { targetFolders } = status
|
||||
|
||||
dispatch(switchMode(CREATE_MODE))
|
||||
let FolderKey = targetFolders.length > 0
|
||||
? targetFolders[0].key
|
||||
: folders[0].key
|
||||
|
||||
let newArticle = {
|
||||
id: null,
|
||||
key: keygen(),
|
||||
title: '',
|
||||
content: '',
|
||||
mode: 'markdown',
|
||||
tags: [],
|
||||
FolderKey: FolderKey,
|
||||
status: 'NEW'
|
||||
}
|
||||
|
||||
dispatch(clearNewArticle())
|
||||
dispatch(updateArticle(newArticle))
|
||||
dispatch(switchArticle(newArticle.key, true))
|
||||
dispatch(switchMode(EDIT_MODE))
|
||||
}
|
||||
|
||||
handleNewFolderButton (e) {
|
||||
@@ -91,13 +105,13 @@ export default class ArticleNavigator extends React.Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
let { status, folders, allArticles } = this.props
|
||||
let { status, user, folders, allArticles } = this.props
|
||||
let { targetFolders } = status
|
||||
if (targetFolders == null) targetFolders = []
|
||||
|
||||
let folderElememts = folders.map((folder, index) => {
|
||||
let isActive = findWhere(targetFolders, {key: folder.key})
|
||||
let articleCount = allArticles.filter(article => article.FolderKey === folder.key).length
|
||||
let articleCount = allArticles.filter(article => article.FolderKey === folder.key && article.status !== 'NEW').length
|
||||
|
||||
return (
|
||||
<button onClick={e => this.handleFolderButtonClick(folder.name)(e)} key={'folder-' + folder.key} className={isActive ? 'active' : ''}>
|
||||
@@ -109,7 +123,7 @@ export default class ArticleNavigator extends React.Component {
|
||||
return (
|
||||
<div className='ArticleNavigator'>
|
||||
<div className='userInfo'>
|
||||
<div className='userProfileName'>{userName}</div>
|
||||
<div className='userProfileName'>{user.name}</div>
|
||||
<div className='userName'>localStorage</div>
|
||||
<button onClick={e => this.handlePreferencesButtonClick(e)} className='settingBtn'>
|
||||
<i className='fa fa-fw fa-chevron-down'/>
|
||||
|
||||
@@ -35,18 +35,33 @@ export default class ArticleTopBar extends React.Component {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
isTooltipHidden: true
|
||||
isTooltipHidden: true,
|
||||
isLinksDropdownOpen: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.searchInput = ReactDOM.findDOMNode(this.refs.searchInput)
|
||||
this.linksButton = ReactDOM.findDOMNode(this.refs.links)
|
||||
this.showLinksDropdown = e => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
if (!this.state.isLinksDropdownOpen) {
|
||||
this.setState({isLinksDropdownOpen: true})
|
||||
}
|
||||
}
|
||||
this.linksButton.addEventListener('click', this.showLinksDropdown)
|
||||
this.hideLinksDropdown = e => {
|
||||
if (this.state.isLinksDropdownOpen) {
|
||||
this.setState({isLinksDropdownOpen: false})
|
||||
}
|
||||
}
|
||||
document.addEventListener('click', this.hideLinksDropdown)
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
this.searchInput.removeEventListener('keydown', this.showTooltip)
|
||||
this.searchInput.removeEventListener('focus', this.showTooltip)
|
||||
this.searchInput.removeEventListener('blur', this.showTooltip)
|
||||
document.removeEventListener('click', this.hideLinksDropdown)
|
||||
this.linksButton.removeEventListener('click', this.showLinksDropdown())
|
||||
}
|
||||
|
||||
handleTooltipRequest (e) {
|
||||
@@ -118,8 +133,11 @@ export default class ArticleTopBar extends React.Component {
|
||||
: null
|
||||
}
|
||||
<div className={'tooltip' + (this.state.isTooltipHidden ? ' hide' : '')}>
|
||||
- Search by tag : #{'{string}'}<br/>
|
||||
- Search by folder : /{'{folder_name}'}
|
||||
<ul>
|
||||
<li>- Search by tag : #{'{string}'}</li>
|
||||
<li>- Search by folder : /{'{folder_name}'}</li>
|
||||
<li><small>exact match : //{'{folder_name}'}</small></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -129,10 +147,23 @@ export default class ArticleTopBar extends React.Component {
|
||||
<div className='right'>
|
||||
<button onClick={e => this.handleTutorialButtonClick(e)}>?<span className='tooltip'>How to use</span>
|
||||
</button>
|
||||
<ExternalLink className='logo' href='http://b00st.io'>
|
||||
<a ref='links' className='linksBtn' href>
|
||||
<img src='../../resources/favicon-230x230.png' width='44' height='44'/>
|
||||
<span className='tooltip'>Boost official page</span>
|
||||
</ExternalLink>
|
||||
</a>
|
||||
{
|
||||
this.state.isLinksDropdownOpen
|
||||
? (
|
||||
<div className='links-dropdown'>
|
||||
<ExternalLink className='links-item' href='https://b00st.io'>
|
||||
<i className='fa fa-fw fa-home'/>Boost official page
|
||||
</ExternalLink>
|
||||
<ExternalLink className='links-item' href='https://github.com/BoostIO/boost-app-discussions/issues'>
|
||||
<i className='fa fa-fw fa-bullhorn'/> Discuss
|
||||
</ExternalLink>
|
||||
</div>
|
||||
)
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
|
||||
{status.isTutorialOpen ? (
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import ipc from 'ipc'
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
import React, { PropTypes } from 'react'
|
||||
|
||||
var ContactModal = require('boost/components/modal/ContactModal')
|
||||
|
||||
export default class MainContainer extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
@@ -19,20 +18,12 @@ export default class MainContainer extends React.Component {
|
||||
ipc.send('update-app', 'Deal with it.')
|
||||
}
|
||||
|
||||
openContactModal () {
|
||||
this.openModal(ContactModal)
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div className='Main'>
|
||||
{this.state.updateAvailable ? (
|
||||
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
|
||||
) : null}
|
||||
{/* <button onClick={this.openContactModal} className='contactButton'>
|
||||
<i className='fa fa-paper-plane-o'/>
|
||||
<div className='tooltip'>Contact us</div>
|
||||
</button> */}
|
||||
{this.props.children}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<link rel="stylesheet" href="../../node_modules/font-awesome/css/font-awesome.min.css" media="screen" charset="utf-8">
|
||||
<link rel="stylesheet" href="../../node_modules/devicon/devicon.min.css">
|
||||
<link rel="stylesheet" href="../../node_modules/highlight.js/styles/xcode.css">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
|
||||
<style>
|
||||
@@ -53,8 +54,9 @@
|
||||
|
||||
<script src="../../submodules/ace/src-min/ace.js"></script>
|
||||
<script type='text/javascript'>
|
||||
require('web-frame').setZoomLevelLimits(1, 1)
|
||||
var version = require('remote').require('app').getVersion()
|
||||
const electron = require('electron')
|
||||
electron.webFrame.setZoomLevelLimits(1, 1)
|
||||
var version = electron.remote.app.getVersion()
|
||||
document.title = 'Boost' + ((version == null || version.length === 0) ? ' DEV' : '')
|
||||
var scriptUrl = process.env.BOOST_ENV === 'development'
|
||||
? 'http://localhost:8080/assets/main.js'
|
||||
|
||||
@@ -11,13 +11,31 @@ require('../styles/main/index.styl')
|
||||
import { openModal } from 'boost/modal'
|
||||
import Tutorial from 'boost/components/modal/Tutorial'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
import ipc from 'ipc'
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
|
||||
activityRecord.init()
|
||||
window.addEventListener('online', function () {
|
||||
ipc.send('check-update', 'check-update')
|
||||
})
|
||||
|
||||
function notify (...args) {
|
||||
return new window.Notification(...args)
|
||||
}
|
||||
|
||||
ipc.on('notify', function (e, payload) {
|
||||
notify(payload.title, {
|
||||
body: payload.body
|
||||
})
|
||||
})
|
||||
|
||||
ipc.on('copy-finder', function () {
|
||||
activityRecord.emit('FINDER_COPY')
|
||||
})
|
||||
ipc.on('open-finder', function () {
|
||||
activityRecord.emit('FINDER_OPEN')
|
||||
})
|
||||
|
||||
let routes = (
|
||||
<Route path='/' component={MainPage}>
|
||||
<IndexRoute name='home' component={HomePage}/>
|
||||
|
||||
@@ -16,6 +16,8 @@ body
|
||||
width 100%
|
||||
height 100%
|
||||
overflow hidden
|
||||
button, input
|
||||
font-family "Lato"
|
||||
|
||||
.Finder
|
||||
absolute top bottom left right
|
||||
|
||||
@@ -284,7 +284,87 @@ iptFocusBorderColor = #369DCD
|
||||
color noTagsColor
|
||||
.right
|
||||
z-index 30
|
||||
button
|
||||
div.share-dropdown
|
||||
position absolute
|
||||
right 5px
|
||||
top 30px
|
||||
background-color transparentify(invBackgroundColor, 80%)
|
||||
padding 5px 0
|
||||
width 200px
|
||||
&.hide
|
||||
display none
|
||||
&>button
|
||||
width 200px
|
||||
text-align left
|
||||
display block
|
||||
height 33px
|
||||
background-color transparent
|
||||
color white
|
||||
font-size 14px
|
||||
padding 0 10px
|
||||
border none
|
||||
&:hover
|
||||
background-color transparentify(lighten(invBackgroundColor, 30%), 80%)
|
||||
&>.ShareButton-url
|
||||
clearfix()
|
||||
input.ShareButton-url-input
|
||||
width 155px
|
||||
margin 0 0 0 5px
|
||||
height 25px
|
||||
outline none
|
||||
border none
|
||||
border-top-left-radius 5px
|
||||
border-bottom-left-radius 5px
|
||||
float left
|
||||
padding 5px
|
||||
button.ShareButton-url-button
|
||||
width 35px
|
||||
height 25px
|
||||
border none
|
||||
margin 0 5px 0 0
|
||||
outline none
|
||||
border-top-right-radius 5px
|
||||
border-bottom-right-radius 5px
|
||||
background-color darken(white, 5%)
|
||||
color inactiveTextColor
|
||||
float right
|
||||
div.ShareButton-url-button-tooltip
|
||||
tooltip()
|
||||
right 10px
|
||||
&:hover
|
||||
color textColor
|
||||
div.ShareButton-url-button-tooltip
|
||||
opacity 1
|
||||
div.ShareButton-url-alert
|
||||
float left
|
||||
height 25px
|
||||
line-height 25px
|
||||
padding 0 15px
|
||||
color white
|
||||
|
||||
.ShareButton
|
||||
display inline-block
|
||||
button.ShareButton-open-button
|
||||
border-radius 16.5px
|
||||
cursor pointer
|
||||
height 33px
|
||||
width 33px
|
||||
border none
|
||||
margin-right 5px
|
||||
font-size 18px
|
||||
color inactiveTextColor
|
||||
background-color darken(white, 5%)
|
||||
padding 0
|
||||
.tooltip
|
||||
tooltip()
|
||||
margin-top 25px
|
||||
margin-left -40px
|
||||
&:hover
|
||||
color textColor
|
||||
.tooltip
|
||||
opacity 1
|
||||
|
||||
&>button
|
||||
border-radius 16.5px
|
||||
cursor pointer
|
||||
height 33px
|
||||
@@ -323,7 +403,8 @@ iptFocusBorderColor = #369DCD
|
||||
right 15px
|
||||
font-size 24px
|
||||
line-height 60px
|
||||
|
||||
white-space nowrap
|
||||
overflow-x auto
|
||||
overflow-y hidden
|
||||
small
|
||||
color #AAA
|
||||
|
||||
@@ -48,6 +48,8 @@ articleItemColor = #777
|
||||
left 19px
|
||||
right 0
|
||||
overflow ellipsis
|
||||
small
|
||||
color #AAA
|
||||
.bottom
|
||||
padding 5px 0
|
||||
overflow-x auto
|
||||
|
||||
@@ -14,7 +14,7 @@ articleCount = #999
|
||||
.userProfileName
|
||||
color brandColor
|
||||
font-size 28px
|
||||
padding 6px 0 0 10px
|
||||
padding 6px 37px 0 10px
|
||||
white-space nowrap
|
||||
text-overflow ellipsis
|
||||
overflow hidden
|
||||
|
||||
@@ -62,6 +62,13 @@ infoBtnActiveBgColor = #3A3A3A
|
||||
opacity 1
|
||||
&.hide
|
||||
opacity 0
|
||||
ul
|
||||
li:last-child
|
||||
line-height 10px
|
||||
margin-bottom 3px
|
||||
small
|
||||
font-size 10px
|
||||
margin-left 15px
|
||||
input
|
||||
absolute top left
|
||||
width 350px
|
||||
@@ -140,17 +147,33 @@ infoBtnActiveBgColor = #3A3A3A
|
||||
.tooltip
|
||||
opacity 1
|
||||
|
||||
&>.logo
|
||||
&>.linksBtn
|
||||
display block
|
||||
position absolute
|
||||
top 8px
|
||||
right 15px
|
||||
opacity 0.7
|
||||
.tooltip
|
||||
tooltip()
|
||||
margin-top 44px
|
||||
margin-left -120px
|
||||
&:hover
|
||||
opacity 1
|
||||
.tooltip
|
||||
opacity 1
|
||||
&>.links-dropdown
|
||||
position fixed
|
||||
z-index 50
|
||||
right 10px
|
||||
top 40px
|
||||
background-color transparentify(invBackgroundColor, 80%)
|
||||
padding 5px 0
|
||||
.links-item
|
||||
padding 0 10px
|
||||
height 33px
|
||||
width 100%
|
||||
display block
|
||||
line-height 33px
|
||||
text-decoration none
|
||||
color white
|
||||
&:hover
|
||||
background-color transparentify(lighten(invBackgroundColor, 30%), 80%)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
marked()
|
||||
h1, h2, h3, h4, h5, h6, p
|
||||
&:first-child
|
||||
margin-top 0
|
||||
hr
|
||||
border-top none
|
||||
border-bottom solid 1px borderColor
|
||||
margin 15px 0
|
||||
h1, h2, h3, h4, h5, h6
|
||||
margin 0 0 15px
|
||||
font-weight 600
|
||||
* + h1, * + h2, * + h3, * + h4, * + h5, * + h6
|
||||
margin-top 25px
|
||||
h1
|
||||
font-size 2em
|
||||
border-bottom solid 2px borderColor
|
||||
margin 0.33em auto 0.67em
|
||||
line-height 2.333em
|
||||
h2
|
||||
font-size 1.5em
|
||||
margin 0.42em auto 0.83em
|
||||
font-size 1.66em
|
||||
line-height 2.07em
|
||||
h3
|
||||
font-size 1.17em
|
||||
margin 0.5em auto 1em
|
||||
font-size 1.33em
|
||||
line-height 1.6625em
|
||||
h4
|
||||
font-size 1em
|
||||
margin 0.67em auto 1.33em
|
||||
font-size 1.15em
|
||||
line-height 1.4375em
|
||||
h5
|
||||
font-size 0.83em
|
||||
margin 0.84em auto 1.67em
|
||||
font-size 1em
|
||||
line-height 1.25em
|
||||
h6
|
||||
font-size 0.67em
|
||||
margin 1.16em auto 2.33em
|
||||
h1, h2, h3, h4, h5, h6
|
||||
font-weight 700
|
||||
line-height 1.8em
|
||||
font-size 0.8em
|
||||
line-height 1em
|
||||
|
||||
* + p, * + blockquote, * + ul, * + ol, * + pre
|
||||
margin-top 15px
|
||||
p
|
||||
line-height 1.8em
|
||||
margin 15px 0 25px
|
||||
line-height 1.9em
|
||||
margin 0 0 15px
|
||||
img
|
||||
max-width 100%
|
||||
strong
|
||||
@@ -41,15 +43,17 @@ marked()
|
||||
text-decoration line-through
|
||||
blockquote
|
||||
border-left solid 4px brandBorderColor
|
||||
margin 15px 0 25px
|
||||
margin 0 0 15px
|
||||
padding 0 25px
|
||||
ul
|
||||
list-style-type disc
|
||||
padding-left 35px
|
||||
margin-bottom 35px
|
||||
margin-bottom 15px
|
||||
li
|
||||
display list-item
|
||||
line-height 1.8em
|
||||
&>li>ul, &>li>ol
|
||||
margin 0
|
||||
&>li>ul
|
||||
list-style-type circle
|
||||
&>li>ul
|
||||
@@ -57,12 +61,14 @@ marked()
|
||||
ol
|
||||
list-style-type decimal
|
||||
padding-left 35px
|
||||
margin-bottom 35px
|
||||
margin-bottom 15px
|
||||
li
|
||||
display list-item
|
||||
line-height 1.8em
|
||||
&>li>ul, &>li>ol
|
||||
margin 0
|
||||
code
|
||||
font-family monospace
|
||||
font-family Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace;
|
||||
padding 2px 4px
|
||||
border solid 1px borderColor
|
||||
border-radius 4px
|
||||
@@ -70,14 +76,19 @@ marked()
|
||||
color black
|
||||
text-decoration none
|
||||
background-color #F6F6F6
|
||||
margin-right 2px
|
||||
* + code
|
||||
margin-left 2px
|
||||
pre
|
||||
padding 5px
|
||||
border solid 1px borderColor
|
||||
border-radius 5px
|
||||
overflow-x auto
|
||||
margin 15px 0 25px
|
||||
margin 0 0 15px
|
||||
background-color #F6F6F6
|
||||
line-height 1.35em
|
||||
&>code
|
||||
margin 0
|
||||
padding 0
|
||||
border none
|
||||
border-radius 0
|
||||
|
||||
12
builder-config.json
Normal file
12
builder-config.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"osx" : {
|
||||
"title": "Boost Installer",
|
||||
// "background": "resources/background.png",
|
||||
"icon": "resources/app.icns",
|
||||
"icon-size": 80,
|
||||
"contents": [
|
||||
{ "x": 438, "y": 344, "type": "link", "path": "/Applications" },
|
||||
{ "x": 192, "y": 344, "type": "file" }
|
||||
]
|
||||
}
|
||||
}
|
||||
81
finder.js
Executable file
81
finder.js
Executable file
@@ -0,0 +1,81 @@
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Tray = electron.Tray
|
||||
const Menu = electron.Menu
|
||||
const MenuItem = electron.MenuItem
|
||||
const ipcMain = electron.ipcMain
|
||||
|
||||
process.stdin.setEncoding('utf8')
|
||||
|
||||
console.log = function () {
|
||||
process.stdout.write(JSON.stringify({
|
||||
type: 'log',
|
||||
data: JSON.stringify(Array.prototype.slice.call(arguments).join(' '))
|
||||
}), 'utf-8')
|
||||
}
|
||||
|
||||
function emit (type, data) {
|
||||
process.stdout.write(JSON.stringify({
|
||||
type: type,
|
||||
data: JSON.stringify(data)
|
||||
}), 'utf-8')
|
||||
}
|
||||
|
||||
var finderWindow
|
||||
app.on('ready', function () {
|
||||
app.dock.hide()
|
||||
var appIcon = new Tray(__dirname + '/resources/tray-icon.png')
|
||||
appIcon.setToolTip('Boost')
|
||||
|
||||
var template = require('./atom-lib/menu-template')
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
|
||||
finderWindow = require('./atom-lib/finder-window')
|
||||
finderWindow.webContents.on('did-finish-load', function () {
|
||||
var trayMenu = new Menu()
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Open Main window',
|
||||
click: function () {
|
||||
emit('show-main-window')
|
||||
}
|
||||
}))
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Open Finder window',
|
||||
click: function () {
|
||||
finderWindow.show()
|
||||
}
|
||||
}))
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Quit',
|
||||
click: function () {
|
||||
emit('quit-app')
|
||||
}
|
||||
}))
|
||||
appIcon.setContextMenu(trayMenu)
|
||||
|
||||
process.stdin.on('data', function (payload) {
|
||||
try {
|
||||
payload = JSON.parse(payload)
|
||||
} catch (e) {
|
||||
console.log('Not parsable payload : ', payload)
|
||||
return
|
||||
}
|
||||
console.log('from main >> ', payload.type)
|
||||
switch (payload.type) {
|
||||
case 'open-finder':
|
||||
finderWindow.show()
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('copy-finder', function () {
|
||||
emit('copy-finder')
|
||||
})
|
||||
})
|
||||
|
||||
global.hideFinder = function () {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
}
|
||||
})
|
||||
|
||||
10
index.js
Normal file
10
index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
function isFinderCalled () {
|
||||
var argv = process.argv.slice(1)
|
||||
return argv.some(arg => arg.match(/--finder/))
|
||||
}
|
||||
|
||||
if (isFinderCalled()) {
|
||||
require('./finder.js')
|
||||
} else {
|
||||
require('./main.js')
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
// Action types
|
||||
export const USER_UPDATE = 'USER_UPDATE'
|
||||
|
||||
export const CLEAR_NEW_ARTICLE = 'CLEAR_NEW_ARTICLE'
|
||||
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
|
||||
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
|
||||
export const FOLDER_CREATE = 'FOLDER_CREATE'
|
||||
@@ -18,13 +21,25 @@ export const TOGGLE_TUTORIAL = 'TOGGLE_TUTORIAL'
|
||||
|
||||
// Status - mode
|
||||
export const IDLE_MODE = 'IDLE_MODE'
|
||||
export const CREATE_MODE = 'CREATE_MODE'
|
||||
export const EDIT_MODE = 'EDIT_MODE'
|
||||
|
||||
// Article status
|
||||
export const NEW = 'NEW'
|
||||
|
||||
export function updateUser (input) {
|
||||
return {
|
||||
type: USER_UPDATE,
|
||||
data: input
|
||||
}
|
||||
}
|
||||
|
||||
// DB
|
||||
export function clearNewArticle () {
|
||||
return {
|
||||
type: CLEAR_NEW_ARTICLE
|
||||
}
|
||||
}
|
||||
|
||||
export function updateArticle (article) {
|
||||
return {
|
||||
type: ARTICLE_UPDATE,
|
||||
@@ -84,10 +99,13 @@ export function switchMode (mode) {
|
||||
}
|
||||
}
|
||||
|
||||
export function switchArticle (articleKey) {
|
||||
export function switchArticle (articleKey, isNew) {
|
||||
return {
|
||||
type: SWITCH_ARTICLE,
|
||||
data: articleKey
|
||||
data: {
|
||||
key: articleKey,
|
||||
isNew: isNew
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,3 +146,23 @@ export function toggleTutorial () {
|
||||
type: TOGGLE_TUTORIAL
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
updateUser,
|
||||
clearNewArticle,
|
||||
updateArticle,
|
||||
destroyArticle,
|
||||
createFolder,
|
||||
updateFolder,
|
||||
destroyFolder,
|
||||
replaceFolder,
|
||||
switchFolder,
|
||||
switchMode,
|
||||
switchArticle,
|
||||
setSearchFilter,
|
||||
setTagFilter,
|
||||
clearSearch,
|
||||
lockStatus,
|
||||
unlockStatus,
|
||||
toggleTutorial
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import _ from 'lodash'
|
||||
import moment from 'moment'
|
||||
import keygen from 'boost/keygen'
|
||||
import dataStore from 'boost/dataStore'
|
||||
import { request, WEB_URL } from 'boost/api'
|
||||
import clientKey from 'boost/clientKey'
|
||||
|
||||
const electron = require('electron')
|
||||
const version = electron.remote.app.getVersion()
|
||||
|
||||
function isSameDate (a, b) {
|
||||
a = moment(a).utcOffset(+540).format('YYYYMMDD')
|
||||
@@ -16,6 +19,7 @@ export function init () {
|
||||
if (records == null) {
|
||||
saveAllRecords([])
|
||||
}
|
||||
emit(null)
|
||||
|
||||
postRecords()
|
||||
if (window != null) {
|
||||
@@ -24,16 +28,6 @@ export function init () {
|
||||
}
|
||||
}
|
||||
|
||||
export function getClientKey () {
|
||||
let clientKey = localStorage.getItem('clientKey')
|
||||
if (!_.isString(clientKey) || clientKey.length !== 40) {
|
||||
clientKey = keygen()
|
||||
localStorage.setItem('clientKey', clientKey)
|
||||
}
|
||||
|
||||
return clientKey
|
||||
}
|
||||
|
||||
export function getAllRecords () {
|
||||
return JSON.parse(localStorage.getItem('activityRecords'))
|
||||
}
|
||||
@@ -47,6 +41,10 @@ Post all records(except today)
|
||||
and remove all posted records
|
||||
*/
|
||||
export function postRecords (data) {
|
||||
if (process.env.BOOST_ENV === 'development') {
|
||||
console.log('post failed - on development')
|
||||
return
|
||||
}
|
||||
let records = getAllRecords()
|
||||
records = records.filter(record => {
|
||||
return !isSameDate(new Date(), record.date)
|
||||
@@ -59,7 +57,7 @@ export function postRecords (data) {
|
||||
|
||||
console.log('posting...', records)
|
||||
let input = {
|
||||
clientKey: getClientKey(),
|
||||
clientKey: clientKey.get(),
|
||||
records
|
||||
}
|
||||
return request.post(WEB_URL + 'apis/activity')
|
||||
@@ -77,7 +75,7 @@ export function postRecords (data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function emit (type, data) {
|
||||
export function emit (type, data = {}) {
|
||||
let records = getAllRecords()
|
||||
|
||||
let index = _.findIndex(records, record => {
|
||||
@@ -90,7 +88,6 @@ export function emit (type, data) {
|
||||
records.push(todayRecord)
|
||||
}
|
||||
else todayRecord = records[index]
|
||||
console.log(type)
|
||||
switch (type) {
|
||||
case 'ARTICLE_CREATE':
|
||||
case 'ARTICLE_UPDATE':
|
||||
@@ -100,6 +97,8 @@ export function emit (type, data) {
|
||||
case 'FOLDER_DESTROY':
|
||||
case 'FINDER_OPEN':
|
||||
case 'FINDER_COPY':
|
||||
case 'MAIN_DETAIL_COPY':
|
||||
case 'ARTICLE_SHARE':
|
||||
todayRecord[type] = todayRecord[type] == null
|
||||
? 1
|
||||
: todayRecord[type] + 1
|
||||
@@ -107,9 +106,26 @@ export function emit (type, data) {
|
||||
break
|
||||
}
|
||||
|
||||
// Count ARTICLE_CREATE and ARTICLE_UPDATE again by syntax
|
||||
if ((type === 'ARTICLE_CREATE' || type === 'ARTICLE_UPDATE') && data.mode != null) {
|
||||
let recordKey = type + '_BY_SYNTAX'
|
||||
if (todayRecord[recordKey] == null) todayRecord[recordKey] = {}
|
||||
|
||||
todayRecord[recordKey][data.mode] = todayRecord[recordKey][data.mode] == null
|
||||
? 1
|
||||
: todayRecord[recordKey][data.mode] + 1
|
||||
}
|
||||
|
||||
let storeData = dataStore.getData()
|
||||
todayRecord.FOLDER_COUNT = _.isArray(storeData.folders) ? storeData.folders.length : 0
|
||||
todayRecord.ARTICLE_COUNT = _.isArray(storeData.articles) ? storeData.articles.length : 0
|
||||
todayRecord.CLIENT_VERSION = version
|
||||
|
||||
todayRecord.SYNTAX_COUNT = storeData.articles.reduce((sum, article) => {
|
||||
if (sum[article.mode] == null) sum[article.mode] = 1
|
||||
else sum[article.mode]++
|
||||
return sum
|
||||
}, {})
|
||||
|
||||
saveAllRecords(records)
|
||||
}
|
||||
@@ -117,6 +133,5 @@ export function emit (type, data) {
|
||||
export default {
|
||||
init,
|
||||
emit,
|
||||
getClientKey,
|
||||
postRecords
|
||||
}
|
||||
|
||||
189
lib/api.js
189
lib/api.js
@@ -1,191 +1,22 @@
|
||||
import superagent from 'superagent'
|
||||
import superagentPromise from 'superagent-promise'
|
||||
import auth from 'boost/auth'
|
||||
// import auth from 'boost/auth'
|
||||
|
||||
export const API_URL = 'http://boost-api4.elasticbeanstalk.com/'
|
||||
export const WEB_URL = 'https://b00st.io/'
|
||||
// export const WEB_URL = 'http://localhost:3333/'
|
||||
export const SERVER_URL = 'https://b00st.io/'
|
||||
// export const SERVER_URL = 'http://localhost:3333/'
|
||||
|
||||
export const request = superagentPromise(superagent, Promise)
|
||||
|
||||
export function login (input) {
|
||||
export function shareViaPublicURL (input) {
|
||||
return request
|
||||
.post(API_URL + 'auth/login')
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function signup (input) {
|
||||
return request
|
||||
.post(API_URL + 'auth/register')
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function updateUserInfo (input) {
|
||||
return request
|
||||
.put(API_URL + 'auth/user')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function updatePassword (input) {
|
||||
return request
|
||||
.post(API_URL + 'auth/password')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function fetchCurrentUser () {
|
||||
return request
|
||||
.get(API_URL + 'auth/user')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchArticles (userId) {
|
||||
return request
|
||||
.get(API_URL + 'teams/' + userId + '/articles')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
}
|
||||
|
||||
export function createArticle (input) {
|
||||
return request
|
||||
.post(API_URL + 'articles/')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function saveArticle (input) {
|
||||
return request
|
||||
.put(API_URL + 'articles/' + input.id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function destroyArticle (articleId) {
|
||||
return request
|
||||
.del(API_URL + 'articles/' + articleId)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
}
|
||||
|
||||
export function createTeam (input) {
|
||||
return request
|
||||
.post(API_URL + 'teams')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function updateTeamInfo (teamId, input) {
|
||||
return request
|
||||
.put(API_URL + 'teams/' + teamId)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function destroyTeam (teamId) {
|
||||
return request
|
||||
.del(API_URL + 'teams/' + teamId)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
}
|
||||
|
||||
export function searchUser (key) {
|
||||
return request
|
||||
.get(API_URL + 'search/users')
|
||||
.query({key: key})
|
||||
}
|
||||
|
||||
export function setMember (teamId, input) {
|
||||
return request
|
||||
.post(API_URL + 'teams/' + teamId + '/members')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function deleteMember (teamId, input) {
|
||||
return request
|
||||
.del(API_URL + 'teams/' + teamId + '/members')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function createFolder (input) {
|
||||
return request
|
||||
.post(API_URL + 'folders/')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function updateFolder (id, input) {
|
||||
return request
|
||||
.put(API_URL + 'folders/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export function destroyFolder (id) {
|
||||
return request
|
||||
.del(API_URL + 'folders/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
}
|
||||
|
||||
export function sendEmail (input) {
|
||||
return request
|
||||
.post(API_URL + 'mail')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + auth.token()
|
||||
})
|
||||
.post(SERVER_URL + 'apis/share')
|
||||
// .set({
|
||||
// Authorization: 'Bearer ' + auth.token()
|
||||
// })
|
||||
.send(input)
|
||||
}
|
||||
|
||||
export default {
|
||||
API_URL,
|
||||
WEB_URL,
|
||||
request,
|
||||
login,
|
||||
signup,
|
||||
updateUserInfo,
|
||||
updatePassword,
|
||||
fetchCurrentUser,
|
||||
fetchArticles,
|
||||
createArticle,
|
||||
saveArticle,
|
||||
destroyArticle,
|
||||
createTeam,
|
||||
updateTeamInfo,
|
||||
destroyTeam,
|
||||
searchUser,
|
||||
setMember,
|
||||
deleteMember,
|
||||
createFolder,
|
||||
updateFolder,
|
||||
destroyFolder,
|
||||
sendEmail
|
||||
SERVER_URL,
|
||||
shareViaPublicURL
|
||||
}
|
||||
|
||||
23
lib/clientKey.js
Normal file
23
lib/clientKey.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import _ from 'lodash'
|
||||
import keygen from 'boost/keygen'
|
||||
|
||||
function getClientKey () {
|
||||
let clientKey = localStorage.getItem('clientKey')
|
||||
if (!_.isString(clientKey) || clientKey.length !== 40) {
|
||||
clientKey = keygen()
|
||||
setClientKey(clientKey)
|
||||
}
|
||||
|
||||
return clientKey
|
||||
}
|
||||
|
||||
function setClientKey (newKey) {
|
||||
localStorage.setItem('clientKey', newKey)
|
||||
}
|
||||
|
||||
getClientKey()
|
||||
|
||||
export default {
|
||||
get: getClientKey,
|
||||
set: setClientKey
|
||||
}
|
||||
@@ -30,6 +30,15 @@ module.exports = React.createClass({
|
||||
editor.renderer.setShowGutter(true)
|
||||
editor.setTheme('ace/theme/xcode')
|
||||
editor.clearSelection()
|
||||
editor.moveCursorTo(0, 0)
|
||||
editor.commands.addCommand({
|
||||
name: 'Emacs cursor up',
|
||||
bindKey: {mac: 'Ctrl-P'},
|
||||
exec: function (editor) {
|
||||
editor.navigateUp(1)
|
||||
},
|
||||
readOnly: true
|
||||
})
|
||||
|
||||
editor.setReadOnly(!!this.props.readOnly)
|
||||
|
||||
@@ -50,16 +59,14 @@ module.exports = React.createClass({
|
||||
this.props.onChange(e, value)
|
||||
}
|
||||
}.bind(this))
|
||||
|
||||
this.setState({editor: editor})
|
||||
},
|
||||
componentDidUpdate: function (prevProps) {
|
||||
if (this.state.editor.getValue() !== this.props.code) {
|
||||
this.state.editor.setValue(this.props.code)
|
||||
this.state.editor.clearSelection()
|
||||
if (this.editor.getValue() !== this.props.code) {
|
||||
this.editor.setValue(this.props.code)
|
||||
this.editor.clearSelection()
|
||||
}
|
||||
if (prevProps.mode !== this.props.mode) {
|
||||
var session = this.state.editor.getSession()
|
||||
var session = this.editor.getSession()
|
||||
let mode = _.findWhere(modes, {name: this.props.mode})
|
||||
let syntaxMode = mode != null
|
||||
? mode.mode
|
||||
@@ -67,6 +74,18 @@ module.exports = React.createClass({
|
||||
session.setMode('ace/mode/' + syntaxMode)
|
||||
}
|
||||
},
|
||||
getFirstVisibleRow: function () {
|
||||
return this.editor.getFirstVisibleRow()
|
||||
},
|
||||
getCursorPosition: function () {
|
||||
return this.editor.getCursorPosition()
|
||||
},
|
||||
moveCursorTo: function (row, col) {
|
||||
this.editor.moveCursorTo(row, col)
|
||||
},
|
||||
scrollToLine: function (num) {
|
||||
this.editor.scrollToLine(num, false, false)
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<div ref='target' className={this.props.className == null ? 'CodeEditor' : 'CodeEditor ' + this.props.className}></div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import shell from 'shell'
|
||||
const electron = require('electron')
|
||||
const shell = electron.shell
|
||||
|
||||
export default class ExternalLink extends React.Component {
|
||||
handleClick (e) {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import shell from 'shell'
|
||||
var React = require('react')
|
||||
var { PropTypes } = React
|
||||
import markdown from 'boost/markdown'
|
||||
var ReactDOM = require('react-dom')
|
||||
|
||||
const electron = require('electron')
|
||||
const shell = electron.shell
|
||||
|
||||
function handleAnchorClick (e) {
|
||||
shell.openExternal(e.target.href)
|
||||
e.preventDefault()
|
||||
|
||||
@@ -161,8 +161,8 @@ export default class ModeSelect extends React.Component {
|
||||
let filteredOptions = modes
|
||||
.filter(mode => {
|
||||
let search = this.state.search
|
||||
let nameMatched = mode.name.match(search)
|
||||
let aliasMatched = _.some(mode.alias, alias => alias.match(search))
|
||||
let nameMatched = mode.name.match(_.escapeRegExp(search))
|
||||
let aliasMatched = _.some(mode.alias, alias => alias.match(_.escapeRegExp(search)))
|
||||
return nameMatched || aliasMatched
|
||||
})
|
||||
.map((mode, index) => {
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
import React, { PropTypes, findDOMNode } from 'react'
|
||||
import linkState from 'boost/linkState'
|
||||
import { sendEmail } from 'boost/api'
|
||||
|
||||
export default class ContactModal extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.linkState = linkState
|
||||
|
||||
this.state = {
|
||||
isSent: false,
|
||||
mail: {
|
||||
title: '',
|
||||
content: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onKeyCast (e) {
|
||||
switch (e.status) {
|
||||
case 'closeModal':
|
||||
this.props.close()
|
||||
break
|
||||
case 'submitContactModal':
|
||||
if (this.state.isSent) {
|
||||
this.props.close()
|
||||
return
|
||||
}
|
||||
this.sendEmail()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
findDOMNode(this.refs.title).focus()
|
||||
}
|
||||
|
||||
sendEmail () {
|
||||
sendEmail(this.state.mail)
|
||||
.then(function (res) {
|
||||
this.setState({isSent: !this.state.isSent})
|
||||
}.bind(this))
|
||||
.catch(function (err) {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div className='ContactModal modal'>
|
||||
<div className='modal-header'><h1>Contact form</h1></div>
|
||||
|
||||
{!this.state.isSent ? (
|
||||
<div className='contactForm'>
|
||||
<div className='modal-body'>
|
||||
<div className='formField'>
|
||||
<input ref='title' valueLink={this.linkState('mail.title')} placeholder='Title'/>
|
||||
</div>
|
||||
<div className='formField'>
|
||||
<textarea valueLink={this.linkState('mail.content')} placeholder='Content'/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='modal-footer'>
|
||||
<div className='formControl'>
|
||||
<button onClick={this.sendEmail} className='sendButton'>Send</button>
|
||||
<button onClick={this.props.close}>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='confirmation'>
|
||||
<div className='confirmationMessage'>Thanks for sharing your opinion!</div>
|
||||
<button className='doneButton' onClick={this.props.close}>Done</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ContactModal.propTypes = {
|
||||
close: PropTypes.func
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import linkState from 'boost/linkState'
|
||||
import { createFolder } from 'boost/actions'
|
||||
import store from 'boost/store'
|
||||
@@ -15,6 +16,10 @@ export default class CreateNewFolder extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
ReactDOM.findDOMNode(this.refs.folderName).focus()
|
||||
}
|
||||
|
||||
handleCloseButton (e) {
|
||||
this.props.close()
|
||||
}
|
||||
@@ -84,7 +89,7 @@ export default class CreateNewFolder extends React.Component {
|
||||
|
||||
<div className='title'>Create new folder</div>
|
||||
|
||||
<input onKeyDown={e => this.handleKeyDown(e)} className='ipt' type='text' valueLink={this.linkState('name')} placeholder='Enter folder name'/>
|
||||
<input ref='folderName' onKeyDown={e => this.handleKeyDown(e)} className='ipt' type='text' valueLink={this.linkState('name')} placeholder='Enter folder name'/>
|
||||
<div className='colorSelect'>
|
||||
{colorElements}
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import store from 'boost/store'
|
||||
import { unlockStatus } from 'boost/actions'
|
||||
import { unlockStatus, clearNewArticle } from 'boost/actions'
|
||||
|
||||
export default class EditedAlert extends React.Component {
|
||||
componentDidMount () {
|
||||
ReactDOM.findDOMNode(this.refs.no).focus()
|
||||
}
|
||||
|
||||
handleNoButtonClick (e) {
|
||||
this.props.close()
|
||||
}
|
||||
@@ -10,6 +15,7 @@ export default class EditedAlert extends React.Component {
|
||||
handleYesButtonClick (e) {
|
||||
store.dispatch(unlockStatus())
|
||||
store.dispatch(this.props.action)
|
||||
store.dispatch(clearNewArticle())
|
||||
this.props.close()
|
||||
}
|
||||
|
||||
@@ -21,8 +27,8 @@ export default class EditedAlert extends React.Component {
|
||||
<div className='message'>Do you really want to leave without finishing?</div>
|
||||
|
||||
<div className='control'>
|
||||
<button onClick={e => this.handleNoButtonClick(e)}><i className='fa fa-fw fa-close'/> No</button>
|
||||
<button onClick={e => this.handleYesButtonClick(e)} className='primary'><i className='fa fa-fw fa-check'/> Yes</button>
|
||||
<button ref='no' onClick={e => this.handleNoButtonClick(e)}><i className='fa fa-fw fa-close'/> No</button>
|
||||
<button ref='yes' onClick={e => this.handleYesButtonClick(e)} className='primary'><i className='fa fa-fw fa-check'/> Yes</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,30 +1,41 @@
|
||||
import React from 'react'
|
||||
import React, { PropTypes } from 'react'
|
||||
import linkState from 'boost/linkState'
|
||||
import remote from 'remote'
|
||||
import ipc from 'ipc'
|
||||
import { updateUser } from 'boost/actions'
|
||||
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
const remote = electron.remote
|
||||
|
||||
export default class AppSettingTab extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
let keymap = remote.getGlobal('keymap')
|
||||
let userName = props.user != null ? props.user.name : null
|
||||
|
||||
this.state = {
|
||||
toggleFinder: keymap.toggleFinder,
|
||||
alert: null
|
||||
user: {
|
||||
name: userName,
|
||||
alert: null
|
||||
},
|
||||
userAlert: null,
|
||||
keymap: {
|
||||
toggleFinder: keymap.toggleFinder
|
||||
},
|
||||
keymapAlert: null
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.handleSettingDone = () => {
|
||||
this.setState({alert: {
|
||||
this.setState({keymapAlert: {
|
||||
type: 'success',
|
||||
message: 'Successfully done!'
|
||||
}})
|
||||
}
|
||||
this.handleSettingError = err => {
|
||||
this.setState({alert: {
|
||||
this.setState({keymapAlert: {
|
||||
type: 'error',
|
||||
message: err.message
|
||||
message: err.message != null ? err.message : 'Error occurs!'
|
||||
}})
|
||||
}
|
||||
ipc.addListener('APP_SETTING_DONE', this.handleSettingDone)
|
||||
@@ -38,7 +49,7 @@ export default class AppSettingTab extends React.Component {
|
||||
|
||||
submitHotKey () {
|
||||
ipc.send('hotkeyUpdated', {
|
||||
toggleFinder: this.state.toggleFinder
|
||||
toggleFinder: this.state.keymap.toggleFinder
|
||||
})
|
||||
}
|
||||
|
||||
@@ -47,28 +58,61 @@ export default class AppSettingTab extends React.Component {
|
||||
}
|
||||
|
||||
handleKeyDown (e) {
|
||||
this.submitHotKey()
|
||||
if (e.keyCode === 13) {
|
||||
this.submitHotKey()
|
||||
}
|
||||
}
|
||||
|
||||
handleNameSaveButtonClick (e) {
|
||||
let { dispatch } = this.props
|
||||
|
||||
dispatch(updateUser({name: this.state.user.name}))
|
||||
this.setState({
|
||||
userAlert: {
|
||||
type: 'success',
|
||||
message: 'Successfully done!'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
let alert = this.state.alert
|
||||
let alertElement = alert != null ? (
|
||||
<p className={`alert ${alert.type}`}>
|
||||
{alert.message}
|
||||
let keymapAlert = this.state.keymapAlert
|
||||
let keymapAlertElement = keymapAlert != null
|
||||
? (
|
||||
<p className={`alert ${keymapAlert.type}`}>
|
||||
{keymapAlert.message}
|
||||
</p>
|
||||
) : null
|
||||
let userAlert = this.state.userAlert
|
||||
let userAlertElement = userAlert != null
|
||||
? (
|
||||
<p className={`alert ${userAlert.type}`}>
|
||||
{userAlert.message}
|
||||
</p>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<div className='AppSettingTab content'>
|
||||
<div className='section'>
|
||||
<div className='sectionTitle'>User's info</div>
|
||||
<div className='sectionInput'>
|
||||
<label>User name</label>
|
||||
<input valueLink={this.linkState('user.name')} type='text'/>
|
||||
</div>
|
||||
<div className='sectionConfirm'>
|
||||
<button onClick={e => this.handleNameSaveButtonClick(e)}>Save</button>
|
||||
{userAlertElement}
|
||||
</div>
|
||||
</div>
|
||||
<div className='section'>
|
||||
<div className='sectionTitle'>Hotkey</div>
|
||||
<div className='sectionInput'>
|
||||
<label>Toggle Finder(popup)</label>
|
||||
<input onKeyDown={e => this.handleKeyDown(e)} valueLink={this.linkState('toggleFinder')} type='text'/>
|
||||
<input onKeyDown={e => this.handleKeyDown(e)} valueLink={this.linkState('keymap.toggleFinder')} type='text'/>
|
||||
</div>
|
||||
<div className='sectionConfirm'>
|
||||
<button onClick={e => this.handleSaveButtonClick(e)}>Save</button>
|
||||
{alertElement}
|
||||
{keymapAlertElement}
|
||||
</div>
|
||||
<div className='description'>
|
||||
<ul>
|
||||
@@ -97,3 +141,6 @@ export default class AppSettingTab extends React.Component {
|
||||
}
|
||||
|
||||
AppSettingTab.prototype.linkState = linkState
|
||||
AppSettingTab.propTypes = {
|
||||
dispatch: PropTypes.func
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class Preferences extends React.Component {
|
||||
}
|
||||
|
||||
renderContent () {
|
||||
let { folders, dispatch } = this.props
|
||||
let { user, folders, dispatch } = this.props
|
||||
|
||||
switch (this.state.currentTab) {
|
||||
case HELP:
|
||||
@@ -80,164 +80,20 @@ class Preferences extends React.Component {
|
||||
)
|
||||
case APP:
|
||||
default:
|
||||
return (<AppSettingTab/>)
|
||||
return (
|
||||
<AppSettingTab
|
||||
user={user}
|
||||
dispatch={dispatch}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// handleProfileSaveButtonClick (e) {
|
||||
// let profileState = this.state.profile
|
||||
// profileState.userInfo.alert = {
|
||||
// type: 'info',
|
||||
// message: 'Sending...'
|
||||
// }
|
||||
// this.setState({profile: profileState}, () => {
|
||||
// let input = {
|
||||
// profileName: profileState.userInfo.profileName,
|
||||
// email: profileState.userInfo.email
|
||||
// }
|
||||
// api.updateUserInfo(input)
|
||||
// .then(res => {
|
||||
// let profileState = this.state.profile
|
||||
// profileState.userInfo.alert = {
|
||||
// type: 'success',
|
||||
// message: 'Successfully done!'
|
||||
// }
|
||||
// this.setState({profile: profileState})
|
||||
// })
|
||||
// .catch(err => {
|
||||
// var message
|
||||
// if (err.status != null) {
|
||||
// message = err.response.body.message
|
||||
// } else if (err.code === 'ECONNREFUSED') {
|
||||
// message = 'Can\'t connect to API server.'
|
||||
// } else throw err
|
||||
|
||||
// let profileState = this.state.profile
|
||||
// profileState.userInfo.alert = {
|
||||
// type: 'error',
|
||||
// message: message
|
||||
// }
|
||||
|
||||
// this.setState({profile: profileState})
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
// handlePasswordSaveButton (e) {
|
||||
// let profileState = this.state.profile
|
||||
|
||||
// if (profileState.password.newPassword !== profileState.password.confirmation) {
|
||||
// profileState.password.alert = {
|
||||
// type: 'error',
|
||||
// message: 'Confirmation doesn\'t match'
|
||||
// }
|
||||
// this.setState({profile: profileState})
|
||||
// return
|
||||
// }
|
||||
|
||||
// profileState.password.alert = {
|
||||
// type: 'info',
|
||||
// message: 'Sending...'
|
||||
// }
|
||||
|
||||
// this.setState({profile: profileState}, () => {
|
||||
// let input = {
|
||||
// password: profileState.password.currentPassword,
|
||||
// newPassword: profileState.password.newPassword
|
||||
// }
|
||||
// api.updatePassword(input)
|
||||
// .then(res => {
|
||||
// let profileState = this.state.profile
|
||||
// profileState.password.alert = {
|
||||
// type: 'success',
|
||||
// message: 'Successfully done!'
|
||||
// }
|
||||
// profileState.password.currentPassword = ''
|
||||
// profileState.password.newPassword = ''
|
||||
// profileState.password.confirmation = ''
|
||||
|
||||
// this.setState({profile: profileState})
|
||||
// })
|
||||
// .catch(err => {
|
||||
// var message
|
||||
// if (err.status != null) {
|
||||
// message = err.response.body.message
|
||||
// } else if (err.code === 'ECONNREFUSED') {
|
||||
// message = 'Can\'t connect to API server.'
|
||||
// } else throw err
|
||||
|
||||
// let profileState = this.state.profile
|
||||
// profileState.password.alert = {
|
||||
// type: 'error',
|
||||
// message: message
|
||||
// }
|
||||
// profileState.password.currentPassword = ''
|
||||
// profileState.password.newPassword = ''
|
||||
// profileState.password.confirmation = ''
|
||||
|
||||
// this.setState({profile: profileState}, () => {
|
||||
// if (this.refs.currentPassword != null) findDOMNode(this.refs.currentPassword).focus()
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
// renderProfile () {
|
||||
// let profileState = this.state.profile
|
||||
// return (
|
||||
// <div className='content profile'>
|
||||
// <div className='section userSection'>
|
||||
// <div className='sectionTitle'>User Info</div>
|
||||
// <div className='sectionInput'>
|
||||
// <label>Profile Name</label>
|
||||
// <input valueLink={this.linkState('profile.userInfo.profileName')} type='text'/>
|
||||
// </div>
|
||||
// <div className='sectionInput'>
|
||||
// <label>E-mail</label>
|
||||
// <input valueLink={this.linkState('profile.userInfo.email')} type='text'/>
|
||||
// </div>
|
||||
// <div className='sectionConfirm'>
|
||||
// <button onClick={e => this.handleProfileSaveButtonClick(e)}>Save</button>
|
||||
|
||||
// {this.state.profile.userInfo.alert != null
|
||||
// ? (
|
||||
// <div className={'alert ' + profileState.userInfo.alert.type}>{profileState.userInfo.alert.message}</div>
|
||||
// )
|
||||
// : null}
|
||||
// </div>
|
||||
// </div>
|
||||
|
||||
// <div className='section passwordSection'>
|
||||
// <div className='sectionTitle'>Password</div>
|
||||
// <div className='sectionInput'>
|
||||
// <label>Current Password</label>
|
||||
// <input ref='currentPassword' valueLink={this.linkState('profile.password.currentPassword')} type='password' placeholder='Current Password'/>
|
||||
// </div>
|
||||
// <div className='sectionInput'>
|
||||
// <label>New Password</label>
|
||||
// <input valueLink={this.linkState('profile.password.newPassword')} type='password' placeholder='New Password'/>
|
||||
// </div>
|
||||
// <div className='sectionInput'>
|
||||
// <label>Confirmation</label>
|
||||
// <input valueLink={this.linkState('profile.password.confirmation')} type='password' placeholder='Confirmation'/>
|
||||
// </div>
|
||||
// <div className='sectionConfirm'>
|
||||
// <button onClick={e => this.handlePasswordSaveButton(e)}>Save</button>
|
||||
|
||||
// {profileState.password.alert != null
|
||||
// ? (
|
||||
// <div className={'alert ' + profileState.password.alert.type}>{profileState.password.alert.message}</div>
|
||||
// )
|
||||
// : null}
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Preferences.propTypes = {
|
||||
user: PropTypes.shape({
|
||||
name: PropTypes.string
|
||||
}),
|
||||
folders: PropTypes.array,
|
||||
dispatch: PropTypes.func
|
||||
}
|
||||
@@ -245,9 +101,10 @@ Preferences.propTypes = {
|
||||
Preferences.prototype.linkState = linkState
|
||||
|
||||
function remap (state) {
|
||||
let { folders, status } = state
|
||||
let { user, folders, status } = state
|
||||
|
||||
return {
|
||||
user,
|
||||
folders,
|
||||
status
|
||||
}
|
||||
|
||||
113
lib/dataStore.js
113
lib/dataStore.js
@@ -1,11 +1,80 @@
|
||||
import keygen from 'boost/keygen'
|
||||
import _ from 'lodash'
|
||||
|
||||
let defaultContent = 'Boost is a brand new note App for programmers.\n\n> 下に日本語版があります。\n\n# \u25CEfeature\n\nBoost has some preponderant functions for efficient engineer\'s task.See some part of it.\n\n1. classify information by\u300CFolders\u300D\n2. deal with great variety of syntax\n3. Finder function\n\n\uFF0A\u3000\uFF0A\u3000\uFF0A\u3000\uFF0A\n\n# 1. classify information by \u300CFolders\u300D- access the information you needed easily.\n\n\u300CFolders\u300D which on the left side bar. Press plus button now. flexible way of classification.\n- Create Folder every language or flamework\n- Make Folder for your own casual memos\n\n# 2. Deal with a great variety of syntax \u2013 instead of your brain\nSave handy all information related with programming\n- Use markdown and gather api specification\n- Well using module and snippet\n\nSave them on Boost, you don\'t need to rewrite or re-search same code again.\n\n# 3. Load Finder function \u2013 now you don\'t need to spell command by hand typing.\n\n**Shift +cmd+tab** press buttons at same time.\nThen, the window will show up for search Boost contents that instant.\n\nUsing cursor key to chose, press enter, cmd+v to paste and\u2026 please check it out by your own eye.\n\n- Such command spl or linux which programmers often use but troublesome to hand type\n\n- (Phrases commonly used for e-mail or customer support)\n\nWe support preponderant efficiency\n\n\uFF0A\u3000\uFF0A\u3000\uFF0A\u3000\uFF0A\n\n## \u25CEfor more information\nFrequently updated with this blog ( http:\/\/blog-jp.b00st.io )\n\nHave wonderful programmer life!\n\n## Hack your memory**\n\n\n\n# 日本語版\n\n**Boost**は全く新しいエンジニアライクのノートアプリです。\n\n# ◎特徴\nBoostはエンジニアの仕事を圧倒的に効率化するいくつかの機能を備えています。\nその一部をご紹介します。\n1. Folderで情報を分類\n2. 豊富なsyantaxに対応\n3. Finder機能\n4. チーム機能(リアルタイム搭載)\n\n* * * *\n\n# 1. Folderで情報を分類、欲しい情報にすぐアクセス。\n左側のバーに存在する「Folders」。\n今すぐプラスボタンを押しましょう。\n分類の仕方も自由自在です。\n- 言語やフレームワークごとにFolderを作成\n- 自分用のカジュアルなメモをまとめる場としてFolderを作成\n\n\n# 2. 豊富なsyntaxに対応、自分の脳の代わりに。\nプログラミングに関する情報を全て、手軽に保存しましょう。\n- mdで、apiの仕様をまとめる\n- よく使うモジュールやスニペット\n\nBoostに保存しておくことで、何度も同じコードを書いたり調べたりする必要がなくなります。\n\n# 3. Finder機能を搭載、もうコマンドを手打ちする必要はありません。\n**「shift+cmd+tab」** を同時に押してみてください。\nここでは、一瞬でBoostの中身を検索するウィンドウを表示させることができます。\n\n矢印キーで選択、Enterを押し、cmd+vでペーストすると…続きはご自身の目でお確かめください。\n- sqlやlinux等の、よく使うが手打ちが面倒なコマンド\n- (メールやカスタマーサポート等でよく使うフレーズ)\n\n私たちは、圧倒的な効率性を支援します。\n\* * * *\n\n\n## ◎詳しくは\nこちらのブログ( http://blog-jp.b00st.io )にて随時更新しています。\n\nそれでは素晴らしいエンジニアライフを!\n\n## Hack your memory**'
|
||||
const electron = require('electron')
|
||||
const remote = electron.remote
|
||||
const jetpack = require('fs-jetpack')
|
||||
const path = require('path')
|
||||
|
||||
let defaultContent = 'Boost is a brand new note App for programmers.\n\n> 下に日本語版があります。\n\n# \u25CEfeature\n\nBoost has some preponderant functions for efficient engineer\'s task.See some part of it.\n\n1. classify information by\u300CFolders\u300D\n2. deal with great variety of syntax\n3. Finder function\n\n\uFF0A\u3000\uFF0A\u3000\uFF0A\u3000\uFF0A\n\n# 1. classify information by \u300CFolders\u300D- access the information you needed easily.\n\n\u300CFolders\u300D which on the left side bar. Press plus button now. flexible way of classification.\n- Create Folder every language or flamework\n- Make Folder for your own casual memos\n\n# 2. Deal with a great variety of syntax \u2013 instead of your brain\nSave handy all information related with programming\n- Use markdown and gather api specification\n- Well using module and snippet\n\nSave them on Boost, you don\'t need to rewrite or re-search same code again.\n\n# 3. Load Finder function \u2013 now you don\'t need to spell command by hand typing.\n\n**Shift +ctrl+tab** press buttons at same time.\nThen, the window will show up for search Boost contents that instant.\n\nUsing cursor key to chose, press enter, cmd+v to paste and\u2026 please check it out by your own eye.\n\n- Such command spl or linux which programmers often use but troublesome to hand type\n\n- (Phrases commonly used for e-mail or customer support)\n\nWe support preponderant efficiency\n\n\uFF0A\u3000\uFF0A\u3000\uFF0A\u3000\uFF0A\n\n## \u25CEfor more information\nFrequently updated with this blog ( http:\/\/blog-jp.b00st.io )\n\nHave wonderful programmer life!\n\n## Hack your memory**\n\n\n\n# 日本語版\n\n**Boost**は全く新しいエンジニアライクのノートアプリです。\n\n# ◎特徴\nBoostはエンジニアの仕事を圧倒的に効率化するいくつかの機能を備えています。\nその一部をご紹介します。\n1. Folderで情報を分類\n2. 豊富なsyantaxに対応\n3. Finder機能\n\n\n* * * *\n\n# 1. Folderで情報を分類、欲しい情報にすぐアクセス。\n左側のバーに存在する「Folders」。\n今すぐプラスボタンを押しましょう。\n分類の仕方も自由自在です。\n- 言語やフレームワークごとにFolderを作成\n- 自分用のカジュアルなメモをまとめる場としてFolderを作成\n\n\n# 2. 豊富なsyntaxに対応、自分の脳の代わりに。\nプログラミングに関する情報を全て、手軽に保存しましょう。\n- mdで、apiの仕様をまとめる\n- よく使うモジュールやスニペット\n\nBoostに保存しておくことで、何度も同じコードを書いたり調べたりする必要がなくなります。\n\n# 3. Finder機能を搭載、もうコマンドを手打ちする必要はありません。\n**「shift+ctrl+tab」** を同時に押してみてください。\nここでは、一瞬でBoostの中身を検索するウィンドウを表示させることができます。\n\n矢印キーで選択、Enterを押し、cmd+vでペーストすると…続きはご自身の目でお確かめください。\n- sqlやlinux等の、よく使うが手打ちが面倒なコマンド\n- (メールやカスタマーサポート等でよく使うフレーズ)\n\n私たちは、圧倒的な効率性を支援します。\n\* * * *\n\n\n## ◎詳しくは\nこちらのブログ( http://blog-jp.b00st.io )にて随時更新しています。\n\nそれでは素晴らしいエンジニアライフを!\n\n## Hack your memory**'
|
||||
|
||||
function getLocalPath () {
|
||||
return path.join(remote.app.getPath('userData'), 'local.json')
|
||||
}
|
||||
|
||||
function forgeInitialRepositories () {
|
||||
return [{
|
||||
key: keygen(),
|
||||
name: 'local',
|
||||
type: 'userData',
|
||||
user: {
|
||||
name: remote.getGlobal('process').env.USER
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
function getRepositories () {
|
||||
let raw = localStorage.getItem('repositories')
|
||||
try {
|
||||
let parsed = JSON.parse(raw)
|
||||
if (!_.isArray(parsed)) {
|
||||
throw new Error('repositories data is currupte. re-init data.')
|
||||
}
|
||||
return parsed
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
let newRepos = forgeInitialRepositories()
|
||||
saveRepositories(newRepos)
|
||||
return newRepos
|
||||
}
|
||||
}
|
||||
|
||||
function saveRepositories (repos) {
|
||||
localStorage.setItem('repositories', JSON.stringify(repos))
|
||||
}
|
||||
|
||||
export function getUser (repoName) {
|
||||
if (repoName == null) {
|
||||
return getRepositories()[0]
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function saveUser (repoName, user) {
|
||||
let repos = getRepositories()
|
||||
if (repoName == null) {
|
||||
Object.assign(repos[0].user, user)
|
||||
}
|
||||
saveRepositories(repos)
|
||||
}
|
||||
|
||||
export function init () {
|
||||
console.log('initialize data store')
|
||||
let data = JSON.parse(localStorage.getItem('local'))
|
||||
// set repositories info
|
||||
getRepositories()
|
||||
|
||||
// set local.json
|
||||
let data = jetpack.read(getLocalPath(), 'json')
|
||||
|
||||
if (data == null) {
|
||||
// for 0.4.1 -> 0.4.2
|
||||
if (localStorage.getItem('local') != null) {
|
||||
data = JSON.parse(localStorage.getItem('local'))
|
||||
jetpack.write(getLocalPath(), data)
|
||||
localStorage.removeItem('local')
|
||||
console.log('update 0.4.1 => 0.4.2')
|
||||
return
|
||||
}
|
||||
|
||||
let defaultFolder = {
|
||||
name: 'default',
|
||||
key: keygen()
|
||||
@@ -24,38 +93,38 @@ export function init () {
|
||||
folders: [defaultFolder],
|
||||
version: '0.4'
|
||||
}
|
||||
localStorage.setItem('local', JSON.stringify(data))
|
||||
jetpack.write(getLocalPath(), data)
|
||||
}
|
||||
}
|
||||
|
||||
function getKey (teamId) {
|
||||
return teamId == null
|
||||
? 'local'
|
||||
: `team-${teamId}`
|
||||
export function getData () {
|
||||
return jetpack.read(getLocalPath(), 'json')
|
||||
}
|
||||
|
||||
export function getData (teamId) {
|
||||
let key = getKey(teamId)
|
||||
return JSON.parse(localStorage.getItem(key))
|
||||
}
|
||||
|
||||
export function setArticles (teamId, articles) {
|
||||
let key = getKey(teamId)
|
||||
let data = JSON.parse(localStorage.getItem(key))
|
||||
export function setArticles (articles) {
|
||||
let data = getData()
|
||||
data.articles = articles
|
||||
localStorage.setItem(key, JSON.stringify(data))
|
||||
jetpack.write(getLocalPath(), data)
|
||||
}
|
||||
|
||||
export function setFolders (teamId, folders) {
|
||||
let key = getKey(teamId)
|
||||
let data = JSON.parse(localStorage.getItem(key))
|
||||
export function setFolders (folders) {
|
||||
let data = getData()
|
||||
data.folders = folders
|
||||
localStorage.setItem(key, JSON.stringify(data))
|
||||
jetpack.write(getLocalPath(), data)
|
||||
}
|
||||
|
||||
function isFinderCalled () {
|
||||
var argv = process.argv.slice(1)
|
||||
return argv.some(arg => arg.match(/--finder/))
|
||||
}
|
||||
|
||||
export default (function () {
|
||||
init()
|
||||
if (!isFinderCalled()) {
|
||||
init()
|
||||
}
|
||||
return {
|
||||
getUser,
|
||||
saveUser,
|
||||
init,
|
||||
getData,
|
||||
setArticles,
|
||||
|
||||
@@ -2,6 +2,6 @@ var crypto = require('crypto')
|
||||
|
||||
module.exports = function () {
|
||||
var shasum = crypto.createHash('sha1')
|
||||
shasum.update(((new Date()).getTime()).toString())
|
||||
shasum.update(((new Date()).getTime() + Math.round(Math.random()*1000)).toString())
|
||||
return shasum.digest('hex')
|
||||
}
|
||||
|
||||
@@ -1,11 +1,38 @@
|
||||
import markdownit from 'markdown-it'
|
||||
import hljs from 'highlight.js'
|
||||
import emoji from 'markdown-it-emoji'
|
||||
|
||||
var md = markdownit({
|
||||
typographer: true,
|
||||
linkify: true
|
||||
linkify: true,
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(lang, str).value
|
||||
} catch (__) {}
|
||||
}
|
||||
|
||||
try {
|
||||
return hljs.highlightAuto(str).value
|
||||
} catch (__) {}
|
||||
|
||||
return ''
|
||||
}
|
||||
})
|
||||
md.use(emoji)
|
||||
|
||||
let originalRenderToken = md.renderer.renderToken
|
||||
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
||||
let token = tokens[idx]
|
||||
let result = originalRenderToken.call(md.renderer, tokens, idx, options)
|
||||
if (token.map != null) {
|
||||
return result + '<a class=\'lineAnchor\' data-key=\'' + token.map[0] + '\'></a>'
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default function markdown (content) {
|
||||
if (content == null) content = ''
|
||||
|
||||
return md.render(content.toString())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var shell = require('shell')
|
||||
const electron = require('electron')
|
||||
const shell = electron.shell
|
||||
|
||||
export default function (e) {
|
||||
shell.openExternal(e.currentTarget.href)
|
||||
|
||||
@@ -12,9 +12,13 @@ import {
|
||||
UNLOCK_STATUS,
|
||||
TOGGLE_TUTORIAL,
|
||||
|
||||
// user
|
||||
USER_UPDATE,
|
||||
|
||||
// Article action type
|
||||
ARTICLE_UPDATE,
|
||||
ARTICLE_DESTROY,
|
||||
CLEAR_NEW_ARTICLE,
|
||||
|
||||
// Folder action type
|
||||
FOLDER_CREATE,
|
||||
@@ -23,8 +27,7 @@ import {
|
||||
FOLDER_REPLACE,
|
||||
|
||||
// view mode
|
||||
IDLE_MODE,
|
||||
CREATE_MODE
|
||||
IDLE_MODE
|
||||
} from './actions'
|
||||
import dataStore from 'boost/dataStore'
|
||||
import keygen from 'boost/keygen'
|
||||
@@ -42,6 +45,21 @@ const initialStatus = {
|
||||
let data = dataStore.getData()
|
||||
let initialArticles = data.articles
|
||||
let initialFolders = data.folders
|
||||
let initialUser = dataStore.getUser().user
|
||||
|
||||
let isStatusLocked = false
|
||||
let isCreatingNew = false
|
||||
|
||||
function user (state = initialUser, action) {
|
||||
switch (action.type) {
|
||||
case USER_UPDATE:
|
||||
let updated = Object.assign(state, action.data)
|
||||
dataStore.saveUser(null, updated)
|
||||
return updated
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
function folders (state = initialFolders, action) {
|
||||
state = state.slice()
|
||||
@@ -64,7 +82,7 @@ function folders (state = initialFolders, action) {
|
||||
if (conflictFolder != null) throw new Error(`${newFolder.name} already exists!`)
|
||||
state.push(newFolder)
|
||||
|
||||
dataStore.setFolders(null, state)
|
||||
dataStore.setFolders(state)
|
||||
activityRecord.emit('FOLDER_CREATE')
|
||||
return state
|
||||
}
|
||||
@@ -91,7 +109,7 @@ function folders (state = initialFolders, action) {
|
||||
updatedAt: new Date()
|
||||
})
|
||||
|
||||
dataStore.setFolders(null, state)
|
||||
dataStore.setFolders(state)
|
||||
activityRecord.emit('FOLDER_UPDATE')
|
||||
return state
|
||||
}
|
||||
@@ -104,7 +122,7 @@ function folders (state = initialFolders, action) {
|
||||
if (targetIndex >= 0) {
|
||||
state.splice(targetIndex, 1)
|
||||
}
|
||||
dataStore.setFolders(null, state)
|
||||
dataStore.setFolders(state)
|
||||
activityRecord.emit('FOLDER_DESTROY')
|
||||
return state
|
||||
}
|
||||
@@ -116,24 +134,57 @@ function folders (state = initialFolders, action) {
|
||||
state.splice(a, 1, folderB)
|
||||
state.splice(b, 1, folderA)
|
||||
}
|
||||
dataStore.setFolders(state)
|
||||
return state
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
let isCleaned = true
|
||||
function articles (state = initialArticles, action) {
|
||||
state = state.slice()
|
||||
|
||||
if (!isCreatingNew && !isCleaned) {
|
||||
state = state.filter(article => article.status !== 'NEW')
|
||||
isCleaned = true
|
||||
}
|
||||
switch (action.type) {
|
||||
case SWITCH_ARTICLE:
|
||||
if (action.data.isNew) {
|
||||
isCleaned = false
|
||||
}
|
||||
if (!isStatusLocked && !action.data.isNew) {
|
||||
isCreatingNew = false
|
||||
if (!isCleaned) {
|
||||
state = state.filter(article => article.status !== 'NEW')
|
||||
isCleaned = true
|
||||
}
|
||||
}
|
||||
return state
|
||||
case SWITCH_FOLDER:
|
||||
case SET_SEARCH_FILTER:
|
||||
case SET_TAG_FILTER:
|
||||
case CLEAR_SEARCH:
|
||||
if (!isStatusLocked) {
|
||||
isCreatingNew = false
|
||||
if (!isCleaned) {
|
||||
state = state.filter(article => article.status !== 'NEW')
|
||||
isCleaned = true
|
||||
}
|
||||
}
|
||||
return state
|
||||
case CLEAR_NEW_ARTICLE:
|
||||
return state.filter(article => article.status !== 'NEW')
|
||||
case ARTICLE_UPDATE:
|
||||
{
|
||||
let article = action.data.article
|
||||
|
||||
let targetIndex = _.findIndex(state, _article => article.key === _article.key)
|
||||
if (targetIndex < 0) state.unshift(article)
|
||||
else state.splice(targetIndex, 1, article)
|
||||
else Object.assign(state[targetIndex], article)
|
||||
|
||||
dataStore.setArticles(null, state)
|
||||
if (article.status !== 'NEW') dataStore.setArticles(state)
|
||||
else isCreatingNew = true
|
||||
return state
|
||||
}
|
||||
case ARTICLE_DESTROY:
|
||||
@@ -143,7 +194,7 @@ function articles (state = initialArticles, action) {
|
||||
let targetIndex = _.findIndex(state, _article => articleKey === _article.key)
|
||||
if (targetIndex >= 0) state.splice(targetIndex, 1)
|
||||
|
||||
dataStore.setArticles(null, state)
|
||||
dataStore.setArticles(state)
|
||||
return state
|
||||
}
|
||||
case FOLDER_DESTROY:
|
||||
@@ -152,7 +203,7 @@ function articles (state = initialArticles, action) {
|
||||
|
||||
state = state.filter(article => article.FolderKey !== folderKey)
|
||||
|
||||
dataStore.setArticles(null, state)
|
||||
dataStore.setArticles(state)
|
||||
return state
|
||||
}
|
||||
default:
|
||||
@@ -162,16 +213,15 @@ function articles (state = initialArticles, action) {
|
||||
|
||||
function status (state = initialStatus, action) {
|
||||
state = Object.assign({}, state)
|
||||
|
||||
switch (action.type) {
|
||||
case TOGGLE_TUTORIAL:
|
||||
state.isTutorialOpen = !state.isTutorialOpen
|
||||
return state
|
||||
case LOCK_STATUS:
|
||||
state.isStatusLocked = true
|
||||
isStatusLocked = state.isStatusLocked = true
|
||||
return state
|
||||
case UNLOCK_STATUS:
|
||||
state.isStatusLocked = false
|
||||
isStatusLocked = state.isStatusLocked = false
|
||||
return state
|
||||
}
|
||||
|
||||
@@ -188,11 +238,10 @@ function status (state = initialStatus, action) {
|
||||
return state
|
||||
case SWITCH_MODE:
|
||||
state.mode = action.data
|
||||
if (state.mode === CREATE_MODE) state.articleKey = null
|
||||
|
||||
return state
|
||||
case SWITCH_ARTICLE:
|
||||
state.articleKey = action.data
|
||||
state.articleKey = action.data.key
|
||||
state.mode = IDLE_MODE
|
||||
|
||||
return state
|
||||
@@ -217,6 +266,7 @@ function status (state = initialStatus, action) {
|
||||
}
|
||||
|
||||
export default combineReducers({
|
||||
user,
|
||||
folders,
|
||||
articles,
|
||||
status
|
||||
|
||||
@@ -68,7 +68,7 @@ const modes = [
|
||||
{
|
||||
name: 'csharp',
|
||||
label: 'C#',
|
||||
alias: ['cs'],
|
||||
alias: ['cs', 'c#'],
|
||||
mode: 'csharp'
|
||||
},
|
||||
{
|
||||
|
||||
193
main.js
193
main.js
@@ -1,61 +1,83 @@
|
||||
var app = require('app')
|
||||
var Menu = require('menu')
|
||||
var MenuItem = require('menu-item')
|
||||
var Tray = require('tray')
|
||||
var ipc = require('ipc')
|
||||
var jetpack = require('fs-jetpack')
|
||||
|
||||
require('crash-reporter').start()
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Menu = electron.Menu
|
||||
const ipc = electron.ipcMain
|
||||
const globalShortcut = electron.globalShortcut
|
||||
const autoUpdater = electron.autoUpdater
|
||||
const jetpack = require('fs-jetpack')
|
||||
const path = require('path')
|
||||
const ChildProcess = require('child_process')
|
||||
electron.crashReporter.start()
|
||||
|
||||
var mainWindow = null
|
||||
var appIcon = null
|
||||
var menu = null
|
||||
var finderWindow = null
|
||||
|
||||
var finderProcess
|
||||
var update = null
|
||||
|
||||
// app.on('window-all-closed', function () {
|
||||
// if (process.platform !== 'darwin') app.quit()
|
||||
// })
|
||||
|
||||
var version = app.getVersion()
|
||||
var versionText = (version == null || version.length === 0) ? 'DEV version' : 'v' + version
|
||||
var nn = require('node-notifier')
|
||||
var updater = require('./atom-lib/updater')
|
||||
var path = require('path')
|
||||
|
||||
var appQuit = false
|
||||
|
||||
updater
|
||||
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
||||
nn.notify({
|
||||
title: 'Ready to Update!! ' + versionText,
|
||||
icon: path.join(__dirname, '/resources/favicon-230x230.png'),
|
||||
message: 'Click update button on Main window: ' + releaseName
|
||||
var version = app.getVersion()
|
||||
var versionText = (version == null || version.length === 0) ? 'DEV version' : 'v' + version
|
||||
var versionNotified = false
|
||||
|
||||
function notify (title, body) {
|
||||
if (mainWindow != null) {
|
||||
mainWindow.webContents.send('notify', {
|
||||
title: title,
|
||||
body: body
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
autoUpdater
|
||||
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
||||
update = quitAndUpdate
|
||||
|
||||
if (mainWindow != null && !mainWindow.webContents.isLoading()) {
|
||||
if (mainWindow != null) {
|
||||
notify('Ready to Update! ' + releaseName, 'Click update button on Main window.')
|
||||
mainWindow.webContents.send('update-available', 'Update available!')
|
||||
}
|
||||
})
|
||||
.on('error', function (err, message) {
|
||||
console.error(err)
|
||||
if (!versionNotified) {
|
||||
notify('Updater error!', message)
|
||||
}
|
||||
})
|
||||
// .on('checking-for-update', function () {
|
||||
// // Connecting
|
||||
// console.log('checking...')
|
||||
// })
|
||||
.on('update-available', function () {
|
||||
notify('Update is available!', 'Download started.. wait for the update ready.')
|
||||
})
|
||||
.on('update-not-available', function () {
|
||||
if (mainWindow != null && !versionNotified) {
|
||||
versionNotified = true
|
||||
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
|
||||
}
|
||||
})
|
||||
|
||||
app.on('ready', function () {
|
||||
app.on('before-quit', function () {
|
||||
if (finderProcess) finderProcess.kill()
|
||||
appQuit = true
|
||||
})
|
||||
console.log('Version ' + version)
|
||||
updater.setFeedUrl('http://orbital.b00st.io/rokt33r/boost-dev/latest?version=' + version)
|
||||
updater.checkForUpdates()
|
||||
// menu start
|
||||
autoUpdater.setFeedURL('https://orbital.b00st.io/rokt33r/boost-app/latest?version=' + version)
|
||||
|
||||
var template = require('./atom-lib/menu-template')
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
|
||||
setInterval(function () {
|
||||
if (update == null) updater.checkForUpdates()
|
||||
if (update == null) autoUpdater.checkForUpdates()
|
||||
}, 1000 * 60 * 60 * 24)
|
||||
|
||||
ipc.on('check-update', function (event, msg) {
|
||||
if (update == null) updater.checkForUpdates()
|
||||
if (update == null) autoUpdater.checkForUpdates()
|
||||
})
|
||||
|
||||
ipc.on('update-app', function (event, msg) {
|
||||
@@ -65,48 +87,77 @@ app.on('ready', function () {
|
||||
}
|
||||
})
|
||||
|
||||
menu = Menu.buildFromTemplate(template)
|
||||
|
||||
Menu.setApplicationMenu(menu)
|
||||
// menu end
|
||||
appIcon = new Tray(__dirname + '/resources/tray-icon.png')
|
||||
appIcon.setToolTip('Boost')
|
||||
|
||||
var trayMenu = new Menu()
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Open main window',
|
||||
click: function () {
|
||||
if (mainWindow != null) mainWindow.show()
|
||||
}
|
||||
}))
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Quit',
|
||||
click: function () {
|
||||
app.quit()
|
||||
}
|
||||
}))
|
||||
appIcon.setContextMenu(trayMenu)
|
||||
|
||||
mainWindow = require('./atom-lib/main-window')
|
||||
mainWindow.on('close', function (e) {
|
||||
if (appQuit) return true
|
||||
e.preventDefault()
|
||||
mainWindow.hide()
|
||||
})
|
||||
if (update != null) {
|
||||
mainWindow.webContents.on('did-finish-load', function () {
|
||||
mainWindow.webContents.send('update-available', 'whoooooooh!')
|
||||
})
|
||||
}
|
||||
mainWindow.webContents.on('did-finish-load', function () {
|
||||
if (finderProcess == null) {
|
||||
finderProcess = ChildProcess
|
||||
.execFile(process.execPath, [path.resolve(__dirname, 'finder.js'), '--finder'])
|
||||
finderProcess.stdout.setEncoding('utf8')
|
||||
finderProcess.stderr.setEncoding('utf8')
|
||||
finderProcess.stdout.on('data', format)
|
||||
finderProcess.stderr.on('data', errorFormat)
|
||||
}
|
||||
|
||||
app.on('activate-with-no-open-windows', function () {
|
||||
if (update != null) {
|
||||
mainWindow.webContents.send('update-available', 'whoooooooh!')
|
||||
} else {
|
||||
autoUpdater.checkForUpdates()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
if (mainWindow == null) return null
|
||||
mainWindow.show()
|
||||
})
|
||||
|
||||
finderWindow = require('./atom-lib/finder-window')
|
||||
function format (payload) {
|
||||
// console.log('from finder >> ', payload)
|
||||
try {
|
||||
payload = JSON.parse(payload)
|
||||
} catch (e) {
|
||||
console.log('Not parsable payload : ', payload)
|
||||
return
|
||||
}
|
||||
switch (payload.type) {
|
||||
case 'log':
|
||||
console.log('FINDER(stdout): ' + payload.data)
|
||||
break
|
||||
case 'show-main-window':
|
||||
mainWindow.show()
|
||||
break
|
||||
case 'copy-finder':
|
||||
mainWindow.webContents.send('copy-finder')
|
||||
break
|
||||
case 'request-data':
|
||||
mainWindow.webContents.send('request-data')
|
||||
break
|
||||
case 'quit-app':
|
||||
appQuit = true
|
||||
app.quit()
|
||||
break
|
||||
}
|
||||
}
|
||||
function errorFormat (output) {
|
||||
console.error('FINDER(stderr):' + output)
|
||||
}
|
||||
|
||||
function emitToFinder (type, data) {
|
||||
if (!finderProcess) {
|
||||
console.log('finder process is not ready')
|
||||
return
|
||||
}
|
||||
var payload = {
|
||||
type: type,
|
||||
data: data
|
||||
}
|
||||
finderProcess.stdin.write(JSON.stringify(payload), 'utf-8')
|
||||
}
|
||||
|
||||
var globalShortcut = require('global-shortcut')
|
||||
var userDataPath = app.getPath('userData')
|
||||
if (!jetpack.cwd(userDataPath).exists('keymap.json')) {
|
||||
jetpack.cwd(userDataPath).file('keymap.json', {content: '{}'})
|
||||
@@ -122,10 +173,8 @@ app.on('ready', function () {
|
||||
|
||||
try {
|
||||
globalShortcut.register(toggleFinderKey, function () {
|
||||
if (mainWindow != null && !mainWindow.isFocused()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
finderWindow.show()
|
||||
emitToFinder('open-finder')
|
||||
mainWindow.webContents.send('open-finder', {})
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err.name)
|
||||
@@ -141,10 +190,8 @@ app.on('ready', function () {
|
||||
var toggleFinderKey = global.keymap.toggleFinder != null ? global.keymap.toggleFinder : 'ctrl+tab+shift'
|
||||
try {
|
||||
globalShortcut.register(toggleFinderKey, function () {
|
||||
if (mainWindow != null && !mainWindow.isFocused()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
finderWindow.show()
|
||||
emitToFinder('open-finder')
|
||||
mainWindow.webContents.send('open-finder', {})
|
||||
})
|
||||
mainWindow.webContents.send('APP_SETTING_DONE', {})
|
||||
} catch (err) {
|
||||
@@ -154,12 +201,4 @@ app.on('ready', function () {
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
global.hideFinder = function () {
|
||||
if (!mainWindow.isVisible()) {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
} else {
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
23
package.json
23
package.json
@@ -1,19 +1,21 @@
|
||||
{
|
||||
"name": "boost",
|
||||
"version": "0.4.1-beta",
|
||||
"version": "0.4.6",
|
||||
"description": "Boost App",
|
||||
"main": "main.js",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "set BOOST_ENV=development&& electron ./main.js",
|
||||
"webpack": "webpack-dev-server --hot --inline --config webpack.config.js",
|
||||
"compile": "NODE_ENV=production webpack --config webpack.config.production.js",
|
||||
"build": "electron-packager ./ Boost --app-version=$npm_package_version $npm_package_config_platform $npm_package_config_version $npm_package_config_ignore --overwrite",
|
||||
"codesign": "codesign --verbose --deep --force --sign \"MAISIN solutions Inc.\" Boost-darwin-x64/Boost.app"
|
||||
"pack:osx": "electron-packager ./ Boost --app-version=$npm_package_version $npm_package_config_platform $npm_package_config_version $npm_package_config_ignore --overwrite --out=\"dist\"",
|
||||
"codesign": "codesign --verbose --deep --force --sign \"MAISIN solutions Inc.\" dist/Boost-darwin-x64/Boost.app",
|
||||
"build:osx": "electron-builder \"dist/Boost-darwin-x64/Boost.app\" --platform=osx --out=\"dist\" --config=\"./builder-config.json\"",
|
||||
"release": "electron-release --app=\"dist/Boost-darwin-x64/Boost.app\" --token=$(cat .env/.github-token) --repo=\"BoostIO/boost-releases\""
|
||||
},
|
||||
"config": {
|
||||
"version": "--version=0.34.0 --app-bundle-id=com.maisin.boost",
|
||||
"version": "--version=0.35.3 --app-bundle-id=com.maisin.boost",
|
||||
"platform": "--platform=darwin --arch=x64 --prune --icon=resources/app.icns",
|
||||
"ignore": "--ignore=Boost-darwin-x64 --ignore=node_modules/devicon/icons --ignore=submodules/ace/(?!src-min)|submodules/ace/(?=src-min-noconflict)"
|
||||
"ignore": "--ignore=.env --ignore=Boost-darwin-x64 --ignore=node_modules/devicon/icons --ignore=submodules/ace/(?!src-min)|submodules/ace/(?=src-min-noconflict)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -40,11 +42,12 @@
|
||||
"devicon": "^2.0.0",
|
||||
"font-awesome": "^4.3.0",
|
||||
"fs-jetpack": "^0.7.0",
|
||||
"highlight.js": "^8.9.1",
|
||||
"lodash": "^3.10.1",
|
||||
"markdown-it": "^4.3.1",
|
||||
"markdown-it-emoji": "^1.1.0",
|
||||
"md5": "^2.0.0",
|
||||
"moment": "^2.10.3",
|
||||
"node-notifier": "^4.2.3",
|
||||
"socket.io-client": "^1.3.6",
|
||||
"superagent": "^1.2.0",
|
||||
"superagent-promise": "^1.0.3"
|
||||
@@ -54,16 +57,16 @@
|
||||
"babel-plugin-react-transform": "^1.1.1",
|
||||
"css-loader": "^0.19.0",
|
||||
"electron-packager": "^5.1.0",
|
||||
"electron-prebuilt": "^0.33.6",
|
||||
"electron-prebuilt": "^0.35.1",
|
||||
"electron-release": "^2.2.0",
|
||||
"nib": "^1.1.0",
|
||||
"react": "^0.14.0",
|
||||
"react-dom": "^0.14.0",
|
||||
"react-redux": "^4.0.0",
|
||||
"react-router": "^1.0.0-rc1",
|
||||
"react-select": "^0.8.1",
|
||||
"react-transform-catch-errors": "^1.0.0",
|
||||
"react-transform-hmr": "^1.0.1",
|
||||
"redbox-react": "^1.1.1",
|
||||
"redbox-react": "^1.2.0",
|
||||
"redux": "^3.0.2",
|
||||
"standard": "^5.3.1",
|
||||
"style-loader": "^0.12.4",
|
||||
|
||||
@@ -3,7 +3,6 @@ var path = require('path')
|
||||
var JsonpTemplatePlugin = webpack.JsonpTemplatePlugin
|
||||
var FunctionModulePlugin = require('webpack/lib/FunctionModulePlugin')
|
||||
var NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
|
||||
var ExternalsPlugin = webpack.ExternalsPlugin
|
||||
|
||||
var opt = {
|
||||
path: path.join(__dirname, 'compiled'),
|
||||
@@ -44,29 +43,10 @@ var config = {
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NoErrorsPlugin(),
|
||||
new ExternalsPlugin('commonjs', [
|
||||
'app',
|
||||
'auto-updater',
|
||||
'browser-window',
|
||||
'content-tracing',
|
||||
'dialog',
|
||||
'global-shortcut',
|
||||
'ipc',
|
||||
'menu',
|
||||
'menu-item',
|
||||
'power-monitor',
|
||||
'protocol',
|
||||
'tray',
|
||||
'remote',
|
||||
'web-frame',
|
||||
'clipboard',
|
||||
'crash-reporter',
|
||||
'screen',
|
||||
'shell'
|
||||
]),
|
||||
new NodeTargetPlugin()
|
||||
],
|
||||
externals: [
|
||||
'electron',
|
||||
'socket.io-client',
|
||||
'md5',
|
||||
'superagent',
|
||||
@@ -74,7 +54,9 @@ var config = {
|
||||
'lodash',
|
||||
'markdown-it',
|
||||
'moment',
|
||||
'node-notifier'
|
||||
'highlight.js',
|
||||
'markdown-it-emoji',
|
||||
'fs-jetpack'
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var webpack = require('webpack')
|
||||
module.exports = {
|
||||
devtool: 'source-map',
|
||||
entry: {
|
||||
main: './browser/main/index.js',
|
||||
finder: './browser/finder/index.js'
|
||||
@@ -8,7 +7,7 @@ module.exports = {
|
||||
output: {
|
||||
path: 'compiled',
|
||||
filename: '[name].js',
|
||||
sourceMapFilename: '[name].map',
|
||||
// sourceMapFilename: '[name].map',
|
||||
libraryTarget: 'commonjs2'
|
||||
},
|
||||
module: {
|
||||
@@ -31,14 +30,15 @@ module.exports = {
|
||||
'process.env': {
|
||||
'NODE_ENV': JSON.stringify('production')
|
||||
}
|
||||
}),
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compressor: {
|
||||
warnings: false
|
||||
}
|
||||
})
|
||||
// new webpack.optimize.UglifyJsPlugin({
|
||||
// compressor: {
|
||||
// warnings: false
|
||||
// }
|
||||
// })
|
||||
],
|
||||
externals: [
|
||||
'electron',
|
||||
'socket.io-client',
|
||||
'md5',
|
||||
'superagent',
|
||||
@@ -46,10 +46,11 @@ module.exports = {
|
||||
'lodash',
|
||||
'markdown-it',
|
||||
'moment',
|
||||
'node-notifier'
|
||||
'highlight.js',
|
||||
'markdown-it-emoji',
|
||||
'fs-jetpack'
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['', '.js', '.jsx', 'styl']
|
||||
},
|
||||
target: 'atom'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user