1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

♻️ Refactor

This commit is contained in:
asmsuechan
2017-08-14 09:14:51 +09:00
parent 56eb9c76ae
commit 8985062d34
2 changed files with 35 additions and 114 deletions

View File

@@ -20,7 +20,7 @@ $control-height = 34px
overflow hidden
display flex
.control-newPostButton
.control-newNoteButton
display block
width 32px
height $control-height - 2
@@ -30,10 +30,10 @@ $control-height = 34px
padding 0
&:active
border-color $ui-button--active-backgroundColor
&:hover .control-newPostButton-tooltip
&:hover .control-newNoteButton-tooltip
opacity 1
.control-newPostButton-tooltip
.control-newNoteButton-tooltip
tooltip()
position fixed
pointer-events none
@@ -53,7 +53,7 @@ body[data-theme="dark"]
.control
border-color $ui-dark-borderColor
.control-newPostButton
.control-newNoteButton
color $ui-inactive-text-color
border-color $ui-dark-borderColor
background-color $ui-dark-noteList-backgroundColor
@@ -64,5 +64,5 @@ body[data-theme="dark"]
background-color alpha($ui-dark-button--active-backgroundColor, 20%)
border-color $ui-dark-button--active-backgroundColor
.control-newPostButton-tooltip
.control-newNoteButton-tooltip
darkTooltip()

View File

@@ -6,7 +6,6 @@ import modal from 'browser/main/lib/modal'
import NewNoteModal from 'browser/main/modals/NewNoteModal'
import { hashHistory } from 'react-router'
import ee from 'browser/main/lib/eventEmitter'
import ConfigManager from 'browser/main/lib/ConfigManager'
import dataApi from 'browser/main/lib/dataApi'
const { remote } = require('electron')
@@ -22,7 +21,7 @@ class NewNoteButton extends React.Component {
}
this.newNoteHandler = () => {
this.handleNewPostButtonClick()
this.handleNewNoteButtonClick()
}
}
@@ -35,38 +34,16 @@ class NewNoteButton extends React.Component {
ee.off('top:new-note', this.newNoteHandler)
}
handleNewPostButtonClick (e) {
let { config, location } = this.props
handleNewNoteButtonClick (e) {
let { config, location, dispatch } = this.props
let { storage, folder } = this.resolveTargetFolder()
if (location.pathname === '/trashed') {
dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'warning',
message: 'Cannot create new note',
detail: 'You cannot create new note in trash box.',
buttons: ['OK']
})
return
}
switch (config.ui.defaultNote) {
case 'MARKDOWN_NOTE':
this.createNote('MARKDOWN_NOTE')
break
case 'SNIPPET_NOTE':
this.createNote('SNIPPET_NOTE')
break
case 'ALWAYS_ASK':
default:
let { dispatch, location } = this.props
let { storage, folder } = this.resolveTargetFolder()
modal.open(NewNoteModal, {
storage: storage.key,
folder: folder.key,
dispatch,
location
})
}
modal.open(NewNoteModal, {
storage: storage.key,
folder: folder.key,
dispatch,
location
})
}
resolveTargetFolder () {
@@ -91,87 +68,31 @@ class NewNoteButton extends React.Component {
}
}
createNote (noteType) {
let { dispatch, location } = this.props
if (noteType !== 'MARKDOWN_NOTE' && noteType !== 'SNIPPET_NOTE') throw new Error('Invalid note type.')
let { storage, folder } = this.resolveTargetFolder()
let newNote = noteType === 'MARKDOWN_NOTE'
? {
type: 'MARKDOWN_NOTE',
folder: folder.key,
title: '',
content: ''
}
: {
type: 'SNIPPET_NOTE',
folder: folder.key,
title: '',
description: '',
snippets: [{
name: '',
mode: 'text',
content: ''
}]
}
dataApi
.createNote(storage.key, newNote)
.then((note) => {
dispatch({
type: 'UPDATE_NOTE',
note: note
})
hashHistory.push({
pathname: location.pathname,
query: {key: note.storage + '-' + note.key}
})
ee.emit('detail:focus')
})
}
setDefaultNote (defaultNote) {
let { config, dispatch } = this.props
let ui = Object.assign(config.ui)
ui.defaultNote = defaultNote
ConfigManager.set({
ui
})
dispatch({
type: 'SET_UI',
config: ConfigManager.get()
})
}
render () {
let { config, style, data } = this.props
return (
<div className='NewNoteButton'
styleName={config.isSideNavFolded ? 'root--expanded' : 'root'}
style={style}
>
<div styleName='control'>
<button styleName='control-newPostButton'
onClick={(e) => this.handleNewPostButtonClick(e)}>
<i className='fa fa-pencil-square-o' />
<span styleName='control-newPostButton-tooltip'>
Make a Note {OSX ? '⌘' : '^'} + n
</span>
</button>
let { config, style, data, location } = this.props
if (location.pathname === '/trashed') {
return ''
} else {
return (
<div className='NewNoteButton'
styleName={config.isSideNavFolded ? 'root--expanded' : 'root'}
style={style}
>
<div styleName='control'>
<button styleName='control-newNoteButton'
onClick={(e) => this.handleNewNoteButtonClick(e)}>
<i className='fa fa-pencil-square-o' />
<span styleName='control-newNoteButton-tooltip'>
Make a Note {OSX ? '⌘' : '^'} + n
</span>
</button>
</div>
</div>
</div>
)
)
}
}
}
NewNoteButton.contextTypes = {
router: PropTypes.shape({
push: PropTypes.func
})
}
NewNoteButton.propTypes = {
dispatch: PropTypes.func,
config: PropTypes.shape({