1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +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 overflow hidden
display flex display flex
.control-newPostButton .control-newNoteButton
display block display block
width 32px width 32px
height $control-height - 2 height $control-height - 2
@@ -30,10 +30,10 @@ $control-height = 34px
padding 0 padding 0
&:active &:active
border-color $ui-button--active-backgroundColor border-color $ui-button--active-backgroundColor
&:hover .control-newPostButton-tooltip &:hover .control-newNoteButton-tooltip
opacity 1 opacity 1
.control-newPostButton-tooltip .control-newNoteButton-tooltip
tooltip() tooltip()
position fixed position fixed
pointer-events none pointer-events none
@@ -53,7 +53,7 @@ body[data-theme="dark"]
.control .control
border-color $ui-dark-borderColor border-color $ui-dark-borderColor
.control-newPostButton .control-newNoteButton
color $ui-inactive-text-color color $ui-inactive-text-color
border-color $ui-dark-borderColor border-color $ui-dark-borderColor
background-color $ui-dark-noteList-backgroundColor background-color $ui-dark-noteList-backgroundColor
@@ -64,5 +64,5 @@ body[data-theme="dark"]
background-color alpha($ui-dark-button--active-backgroundColor, 20%) background-color alpha($ui-dark-button--active-backgroundColor, 20%)
border-color $ui-dark-button--active-backgroundColor border-color $ui-dark-button--active-backgroundColor
.control-newPostButton-tooltip .control-newNoteButton-tooltip
darkTooltip() darkTooltip()

View File

@@ -6,7 +6,6 @@ import modal from 'browser/main/lib/modal'
import NewNoteModal from 'browser/main/modals/NewNoteModal' import NewNoteModal from 'browser/main/modals/NewNoteModal'
import { hashHistory } from 'react-router' import { hashHistory } from 'react-router'
import ee from 'browser/main/lib/eventEmitter' import ee from 'browser/main/lib/eventEmitter'
import ConfigManager from 'browser/main/lib/ConfigManager'
import dataApi from 'browser/main/lib/dataApi' import dataApi from 'browser/main/lib/dataApi'
const { remote } = require('electron') const { remote } = require('electron')
@@ -22,7 +21,7 @@ class NewNoteButton extends React.Component {
} }
this.newNoteHandler = () => { this.newNoteHandler = () => {
this.handleNewPostButtonClick() this.handleNewNoteButtonClick()
} }
} }
@@ -35,38 +34,16 @@ class NewNoteButton extends React.Component {
ee.off('top:new-note', this.newNoteHandler) ee.off('top:new-note', this.newNoteHandler)
} }
handleNewPostButtonClick (e) { handleNewNoteButtonClick (e) {
let { config, location } = this.props let { config, location, dispatch } = this.props
let { storage, folder } = this.resolveTargetFolder()
if (location.pathname === '/trashed') { modal.open(NewNoteModal, {
dialog.showMessageBox(remote.getCurrentWindow(), { storage: storage.key,
type: 'warning', folder: folder.key,
message: 'Cannot create new note', dispatch,
detail: 'You cannot create new note in trash box.', location
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
})
}
} }
resolveTargetFolder () { 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 () { render () {
let { config, style, data } = this.props let { config, style, data, location } = this.props
return ( if (location.pathname === '/trashed') {
<div className='NewNoteButton' return ''
styleName={config.isSideNavFolded ? 'root--expanded' : 'root'} } else {
style={style} return (
> <div className='NewNoteButton'
<div styleName='control'> styleName={config.isSideNavFolded ? 'root--expanded' : 'root'}
<button styleName='control-newPostButton' style={style}
onClick={(e) => this.handleNewPostButtonClick(e)}> >
<i className='fa fa-pencil-square-o' /> <div styleName='control'>
<span styleName='control-newPostButton-tooltip'> <button styleName='control-newNoteButton'
Make a Note {OSX ? '⌘' : '^'} + n onClick={(e) => this.handleNewNoteButtonClick(e)}>
</span> <i className='fa fa-pencil-square-o' />
</button> <span styleName='control-newNoteButton-tooltip'>
Make a Note {OSX ? '⌘' : '^'} + n
</span>
</button>
</div>
</div> </div>
</div> )
) }
} }
} }
NewNoteButton.contextTypes = {
router: PropTypes.shape({
push: PropTypes.func
})
}
NewNoteButton.propTypes = { NewNoteButton.propTypes = {
dispatch: PropTypes.func, dispatch: PropTypes.func,
config: PropTypes.shape({ config: PropTypes.shape({