1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00

Merge pull request #2135 from BoostIO/improve-snippets-ui

Improve snippets ui
This commit is contained in:
Sosuke Suzuki
2018-06-30 20:11:33 +09:00
committed by GitHub
3 changed files with 38 additions and 6 deletions

View File

@@ -21,7 +21,10 @@ class SnippetList extends React.Component {
} }
reloadSnippetList () { reloadSnippetList () {
dataApi.fetchSnippet().then(snippets => this.setState({snippets})) dataApi.fetchSnippet().then(snippets => {
this.setState({snippets})
this.props.onSnippetSelect(snippets[0])
})
} }
handleSnippetContextMenu (snippet) { handleSnippetContextMenu (snippet) {
@@ -43,7 +46,7 @@ class SnippetList extends React.Component {
} }
handleSnippetClick (snippet) { handleSnippetClick (snippet) {
this.props.onSnippetClick(snippet) this.props.onSnippetSelect(snippet)
} }
createSnippet () { createSnippet () {
@@ -55,6 +58,16 @@ class SnippetList extends React.Component {
}).catch(err => { throw err }) }).catch(err => { throw err })
} }
defineSnippetStyleName (snippet) {
const { currentSnippet } = this.props
if (currentSnippet == null) return
if (currentSnippet.id === snippet.id) {
return 'snippet-item-selected'
} else {
return 'snippet-item'
}
}
render () { render () {
const { snippets } = this.state const { snippets } = this.state
return ( return (
@@ -70,7 +83,7 @@ class SnippetList extends React.Component {
{ {
snippets.map((snippet) => ( snippets.map((snippet) => (
<li <li
styleName='snippet-item' styleName={this.defineSnippetStyleName(snippet)}
key={snippet.id} key={snippet.id}
onContextMenu={() => this.handleSnippetContextMenu(snippet)} onContextMenu={() => this.handleSnippetContextMenu(snippet)}
onClick={() => this.handleSnippetClick(snippet)}> onClick={() => this.handleSnippetClick(snippet)}>

View File

@@ -25,7 +25,7 @@ class SnippetTab extends React.Component {
}, 500) }, 500)
} }
handleSnippetClick (snippet) { handleSnippetSelect (snippet) {
const { currentSnippet } = this.state const { currentSnippet } = this.state
if (currentSnippet === null || currentSnippet.id !== snippet.id) { if (currentSnippet === null || currentSnippet.id !== snippet.id) {
dataApi.fetchSnippet(snippet.id).then(changedSnippet => { dataApi.fetchSnippet(snippet.id).then(changedSnippet => {
@@ -66,8 +66,9 @@ class SnippetTab extends React.Component {
<div styleName='root'> <div styleName='root'>
<div styleName='header'>{i18n.__('Snippets')}</div> <div styleName='header'>{i18n.__('Snippets')}</div>
<SnippetList <SnippetList
onSnippetClick={this.handleSnippetClick.bind(this)} onSnippetSelect={this.handleSnippetSelect.bind(this)}
onSnippetDeleted={this.handleDeleteSnippet.bind(this)} /> onSnippetDeleted={this.handleDeleteSnippet.bind(this)}
currentSnippet={currentSnippet} />
<div styleName='snippet-detail' style={{visibility: currentSnippet ? 'visible' : 'hidden'}}> <div styleName='snippet-detail' style={{visibility: currentSnippet ? 'visible' : 'hidden'}}>
<div styleName='group-section'> <div styleName='group-section'>
<div styleName='group-section-label'>{i18n.__('Snippet name')}</div> <div styleName='group-section-label'>{i18n.__('Snippet name')}</div>

View File

@@ -122,6 +122,10 @@
&:hover &:hover
background darken(#f5f5f5, 5) background darken(#f5f5f5, 5)
.snippet-item-selected
@extend .snippet-list .snippet-item
background darken(#f5f5f5, 5)
.snippet-detail .snippet-detail
width 70% width 70%
height calc(100% - 200px) height calc(100% - 200px)
@@ -142,6 +146,8 @@ body[data-theme="default"], body[data-theme="white"]
background $ui-borderColor background $ui-borderColor
&:hover &:hover
background darken($ui-backgroundColor, 5) background darken($ui-backgroundColor, 5)
.snippet-item-selected
background darken($ui-backgroundColor, 5)
body[data-theme="dark"] body[data-theme="dark"]
.snippets .snippets
@@ -152,8 +158,12 @@ body[data-theme="dark"]
background $ui-dark-borderColor background $ui-dark-borderColor
&:hover &:hover
background darken($ui-dark-backgroundColor, 5) background darken($ui-dark-backgroundColor, 5)
.snippet-item-selected
background darken($ui-dark-backgroundColor, 5)
.snippet-detail .snippet-detail
color white color white
.group-control-button
colorDarkPrimaryButton()
body[data-theme="solarized-dark"] body[data-theme="solarized-dark"]
.snippets .snippets
@@ -164,8 +174,12 @@ body[data-theme="solarized-dark"]
background $ui-solarized-dark-borderColor background $ui-solarized-dark-borderColor
&:hover &:hover
background darken($ui-solarized-dark-backgroundColor, 5) background darken($ui-solarized-dark-backgroundColor, 5)
.snippet-item-selected
background darken($ui-solarized-dark-backgroundColor, 5)
.snippet-detail .snippet-detail
color white color white
.group-control-button
colorSolarizedDarkPrimaryButton()
body[data-theme="monokai"] body[data-theme="monokai"]
.snippets .snippets
@@ -176,5 +190,9 @@ body[data-theme="monokai"]
background $ui-monokai-borderColor background $ui-monokai-borderColor
&:hover &:hover
background darken($ui-monokai-backgroundColor, 5) background darken($ui-monokai-backgroundColor, 5)
.snippet-item-selected
background darken($ui-monokai-backgroundColor, 5)
.snippet-detail .snippet-detail
color white color white
.group-control-button
colorMonokaiPrimaryButton()