1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-12 17:26:17 +00:00

fix: Lint issues.

This commit is contained in:
Luis Reinoso
2020-05-08 10:01:30 -05:00
parent 2ea0514bbe
commit 98d4fa0603
7 changed files with 109 additions and 73 deletions

View File

@@ -21,7 +21,6 @@ const buildEditorContextMenu = require('browser/lib/contextMenuBuilder')
import { createTurndownService } from '../lib/turndown'
import { languageMaps } from '../lib/CMLanguageList'
import snippetManager from '../lib/SnippetManager'
import { gfm } from 'turndown-plugin-gfm'
import { findStorage } from 'browser/lib/findStorage'
import { sendWakatimeHeartBeat } from 'browser/lib/wakatime-plugin'
import {
@@ -120,8 +119,15 @@ export default class CodeEditor extends React.Component {
// wakatime
const { storageKey, noteKey } = this.props
const storage = findStorage(storageKey)
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, false, false, true)
if (storage)
sendWakatimeHeartBeat(
storage.path,
noteKey,
storage.name,
false,
false,
true
)
}
handleSearch(msg) {
@@ -807,9 +813,25 @@ export default class CodeEditor extends React.Component {
const storage = findStorage(storageKey)
if (this.props.onChange) {
this.props.onChange(editor)
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, true, true, false)
if (storage)
sendWakatimeHeartBeat(
storage.path,
noteKey,
storage.name,
true,
true,
false
)
} else {
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, false, false, false)
if (storage)
sendWakatimeHeartBeat(
storage.path,
noteKey,
storage.name,
false,
false,
false
)
}
}
@@ -942,7 +964,15 @@ export default class CodeEditor extends React.Component {
// wakatime
const { storageKey, noteKey } = this.props
const storage = findStorage(storageKey)
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, false, false, true)
if (storage)
sendWakatimeHeartBeat(
storage.path,
noteKey,
storage.name,
false,
false,
true
)
}
setValue(value) {

View File

@@ -1299,9 +1299,4 @@ MarkdownPreview.propTypes = {
breaks: PropTypes.bool
}
export default connect(
null,
null,
null,
{ forwardRef: true }
)(MarkdownPreview)
export default connect(null, null, null, { forwardRef: true })(MarkdownPreview)

View File

@@ -278,9 +278,7 @@ class Markdown {
flowchart: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="flowchart" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="flowchart" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
},
gallery: token => {
@@ -299,25 +297,19 @@ class Markdown {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="gallery" data-autoplay="${
token.parameters.autoplay
}" data-height="${token.parameters.height}">${content}</div>
<div class="gallery" data-autoplay="${token.parameters.autoplay}" data-height="${token.parameters.height}">${content}</div>
</pre>`
},
mermaid: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="mermaid" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="mermaid" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
},
sequence: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="sequence" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="sequence" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
}
},

View File

@@ -3,7 +3,14 @@ const exec = require('child_process').exec
const path = require('path')
let lastHeartbeat = 0
function sendWakatimeHeartBeat (storagePath, noteKey, storageName, isWrite, hasFileChanges, isFileChange) {
function sendWakatimeHeartBeat(
storagePath,
noteKey,
storageName,
isWrite,
hasFileChanges,
isFileChange
) {
if (new Date().getTime() - lastHeartbeat > 120000 || isFileChange) {
const notePath = path.join(storagePath, 'notes', noteKey + '.cson')
@@ -14,14 +21,25 @@ function sendWakatimeHeartBeat (storagePath, noteKey, storageName, isWrite, hasF
lastHeartbeat = new Date()
const wakatimeKey = config.get().wakatime.key
if (wakatimeKey) {
exec(`wakatime --file ${notePath} --project '${storageName}' --key ${wakatimeKey} --plugin Boostnote-wakatime`, (error, stdOut, stdErr) => {
if (error) {
console.log(error)
lastHeartbeat = 0
} else {
console.log('wakatime', 'isWrite', isWrite, 'hasChanges', hasFileChanges, 'isFileChange', isFileChange)
exec(
`wakatime --file ${notePath} --project '${storageName}' --key ${wakatimeKey} --plugin Boostnote-wakatime`,
(error, stdOut, stdErr) => {
if (error) {
console.log(error)
lastHeartbeat = 0
} else {
console.log(
'wakatime',
'isWrite',
isWrite,
'hasChanges',
hasFileChanges,
'isFileChange',
isFileChange
)
}
}
})
)
}
}
}

View File

@@ -11,7 +11,7 @@ const electron = require('electron')
const ipc = electron.ipcRenderer
class PluginsTab extends React.Component {
constructor (props) {
constructor(props) {
super(props)
this.state = {
@@ -19,27 +19,34 @@ class PluginsTab extends React.Component {
}
}
componentDidMount () {
componentDidMount() {
this.handleSettingDone = () => {
this.setState({pluginsAlert: {
type: 'success',
message: i18n.__('Successfully applied!')
}})
this.setState({
pluginsAlert: {
type: 'success',
message: i18n.__('Successfully applied!')
}
})
}
this.handleSettingError = (err) => {
this.handleSettingError = err => {
if (
this.state.config.wakatime.key === '' ||
this.state.config.wakatime.key === null
) {
this.setState({pluginsAlert: {
type: 'success',
message: i18n.__('Successfully applied!')
}})
this.setState({
pluginsAlert: {
type: 'success',
message: i18n.__('Successfully applied!')
}
})
} else {
this.setState({pluginsAlert: {
type: 'error',
message: err.message != null ? err.message : i18n.__('An error occurred!')
}})
this.setState({
pluginsAlert: {
type: 'error',
message:
err.message != null ? err.message : i18n.__('An error occurred!')
}
})
}
}
this.oldWakatimekey = this.state.config.wakatime
@@ -47,12 +54,12 @@ class PluginsTab extends React.Component {
ipc.addListener('APP_SETTING_ERROR', this.handleSettingError)
}
componentWillUnmount () {
componentWillUnmount() {
ipc.removeListener('APP_SETTING_DONE', this.handleSettingDone)
ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError)
}
handleSaveButtonClick (e) {
handleSaveButtonClick(e) {
const newConfig = {
wakatime: this.state.config.wakatime
}
@@ -67,7 +74,7 @@ class PluginsTab extends React.Component {
this.props.haveToSave()
}
handleWakatimeKeyChange (e) {
handleWakatimeKeyChange(e) {
const { config } = this.state
config.wakatime = { key: this.refs.key.value }
this.setState({
@@ -84,7 +91,7 @@ class PluginsTab extends React.Component {
}
}
clearMessage () {
clearMessage() {
_.debounce(() => {
this.setState({
pluginsAlert: null
@@ -92,13 +99,12 @@ class PluginsTab extends React.Component {
}, 2000)()
}
render () {
render() {
const pluginsAlert = this.state.pluginsAlert
const pluginsAlertElement = pluginsAlert != null
? <p className={`alert ${pluginsAlert.type}`}>
{pluginsAlert.message}
</p>
: null
const pluginsAlertElement =
pluginsAlert != null ? (
<p className={`alert ${pluginsAlert.type}`}>{pluginsAlert.message}</p>
) : null
const { config } = this.state
return (
@@ -108,8 +114,9 @@ class PluginsTab extends React.Component {
<div styleName='group-section'>
<div styleName='group-section-label'>{i18n.__('Wakatime key')}</div>
<div styleName='group-section-control'>
<input styleName='group-section-control-input'
onChange={(e) => this.handleWakatimeKeyChange(e)}
<input
styleName='group-section-control-input'
onChange={e => this.handleWakatimeKeyChange(e)}
ref='key'
value={config.wakatime.key}
type='text'
@@ -117,8 +124,11 @@ class PluginsTab extends React.Component {
</div>
</div>
<div styleName='group-control'>
<button styleName='group-control-rightButton'
onClick={(e) => this.handleSaveButtonClick(e)}>{i18n.__('Save')}
<button
styleName='group-control-rightButton'
onClick={e => this.handleSaveButtonClick(e)}
>
{i18n.__('Save')}
</button>
{pluginsAlertElement}
</div>

View File

@@ -82,19 +82,13 @@ class Preferences extends React.Component {
/>
)
case 'SNIPPET':
return (
<SnippetTab
dispatch={dispatch}
config={config}
data={data}
/>
)
return <SnippetTab dispatch={dispatch} config={config} data={data} />
case 'PLUGINS':
return (
<PluginsTab
dispatch={dispatch}
config={config}
haveToSave={alert => this.setState({PluginsAlert: alert})}
haveToSave={alert => this.setState({ PluginsAlert: alert })}
/>
)
case 'STORAGES':

View File

@@ -480,10 +480,7 @@ const store = createStore(
reducer,
undefined,
process.env.NODE_ENV === 'development'
? compose(
applyMiddleware(routerMiddleware(history)),
DevTools.instrument()
)
? compose(applyMiddleware(routerMiddleware(history)), DevTools.instrument())
: applyMiddleware(routerMiddleware(history))
)