mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 18:56:22 +00:00
Star a note
This commit is contained in:
@@ -441,6 +441,27 @@ class Repository {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
starNote (noteKey) {
|
||||||
|
let note = _.find(this.notes, {key: noteKey})
|
||||||
|
if (note != null) {
|
||||||
|
let json = this.json
|
||||||
|
json.starred.push(noteKey)
|
||||||
|
|
||||||
|
return this.saveJSON(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unstarNote (noteKey) {
|
||||||
|
let note = _.find(this.notes, {key: noteKey})
|
||||||
|
if (note != null) {
|
||||||
|
let json = this.json
|
||||||
|
json.starred = json.starred
|
||||||
|
.filter((starredKey) => starredKey !== noteKey)
|
||||||
|
|
||||||
|
return this.saveJSON(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
removeNote (noteKey) {
|
removeNote (noteKey) {
|
||||||
let noteIndex = _.findIndex(this.notes, {key: noteKey})
|
let noteIndex = _.findIndex(this.notes, {key: noteKey})
|
||||||
|
|
||||||
@@ -473,7 +494,8 @@ class Repository {
|
|||||||
key: keygen(),
|
key: keygen(),
|
||||||
name: 'general',
|
name: 'general',
|
||||||
color: this.randomColor()
|
color: this.randomColor()
|
||||||
}]
|
}],
|
||||||
|
starred: []
|
||||||
}, override)
|
}, override)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import CSSModules from 'browser/lib/CSSModules'
|
|||||||
import styles from './NoteDetail.styl'
|
import styles from './NoteDetail.styl'
|
||||||
import MarkdownEditor from 'browser/components/MarkdownEditor'
|
import MarkdownEditor from 'browser/components/MarkdownEditor'
|
||||||
import queue from 'browser/main/lib/queue'
|
import queue from 'browser/main/lib/queue'
|
||||||
|
import StarButton from './StarButton'
|
||||||
import TagSelect from './TagSelect'
|
import TagSelect from './TagSelect'
|
||||||
|
import Repository from 'browser/lib/Repository'
|
||||||
|
|
||||||
class NoteDetail extends React.Component {
|
class NoteDetail extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -106,7 +108,42 @@ class NoteDetail extends React.Component {
|
|||||||
queue.save(repoKey, note)
|
queue.save(repoKey, note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleStarButtonClick (e) {
|
||||||
|
let { note } = this.state
|
||||||
|
let { dispatch } = this.props
|
||||||
|
let isStarred = note._repository.starred.some((starredKey) => starredKey === note.key)
|
||||||
|
|
||||||
|
if (isStarred) {
|
||||||
|
Repository
|
||||||
|
.find(note._repository.key)
|
||||||
|
.then((repo) => {
|
||||||
|
return repo.unstarNote(note.key)
|
||||||
|
})
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: 'UNSTAR_NOTE',
|
||||||
|
repository: note._repository.key,
|
||||||
|
note: note.key
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Repository
|
||||||
|
.find(note._repository.key)
|
||||||
|
.then((repo) => {
|
||||||
|
return repo.starNote(note.key)
|
||||||
|
})
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: 'STAR_NOTE',
|
||||||
|
repository: note._repository.key,
|
||||||
|
note: note.key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
let { note } = this.state
|
||||||
|
let isStarred = note._repository.starred.some((starredKey) => starredKey === note.key)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='NoteDetail'
|
<div className='NoteDetail'
|
||||||
style={this.props.style}
|
style={this.props.style}
|
||||||
@@ -116,9 +153,10 @@ class NoteDetail extends React.Component {
|
|||||||
<div styleName='info-left'>
|
<div styleName='info-left'>
|
||||||
|
|
||||||
<div styleName='info-left-top'>
|
<div styleName='info-left-top'>
|
||||||
<button styleName='info-left-top-starButton'>
|
<StarButton styleName='info-left-top-starButton'
|
||||||
<i className='fa fa-star-o fa-fw'/>
|
onClick={(e) => this.handleStarButtonClick(e)}
|
||||||
</button>
|
isActive={isStarred}
|
||||||
|
/>
|
||||||
<div styleName='info-left-top-folderSelect'>FolderSelect</div>
|
<div styleName='info-left-top-folderSelect'>FolderSelect</div>
|
||||||
</div>
|
</div>
|
||||||
<div styleName='info-left-bottom'>
|
<div styleName='info-left-bottom'>
|
||||||
|
|||||||
@@ -18,6 +18,19 @@ $info-height = 80px
|
|||||||
.info-left-top
|
.info-left-top
|
||||||
height 40px
|
height 40px
|
||||||
|
|
||||||
|
.info-left-top-starButton
|
||||||
|
display inline-block
|
||||||
|
height 40px
|
||||||
|
width 40px
|
||||||
|
line-height 40px
|
||||||
|
vertical-align top
|
||||||
|
|
||||||
|
.info-left-top-folderSelect
|
||||||
|
display inline-block
|
||||||
|
height 40px
|
||||||
|
width 100px
|
||||||
|
vertical-align top
|
||||||
|
|
||||||
.info-left-bottom
|
.info-left-bottom
|
||||||
height 40px
|
height 40px
|
||||||
|
|
||||||
|
|||||||
66
browser/main/Detail/StarButton.js
Normal file
66
browser/main/Detail/StarButton.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import React, { PropTypes } from 'react'
|
||||||
|
import CSSModules from 'browser/lib/CSSModules'
|
||||||
|
import styles from './StarButton.styl'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
|
class StarButton extends React.Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
isActive: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseDown (e) {
|
||||||
|
this.setState({
|
||||||
|
isActive: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseUp (e) {
|
||||||
|
this.setState({
|
||||||
|
isActive: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseLeave (e) {
|
||||||
|
this.setState({
|
||||||
|
isActive: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
let { className } = this.props
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button className={_.isString(className)
|
||||||
|
? 'StarButton ' + className
|
||||||
|
: 'StarButton'
|
||||||
|
}
|
||||||
|
styleName={this.state.isActive || this.props.isActive
|
||||||
|
? 'root--active'
|
||||||
|
: 'root'
|
||||||
|
}
|
||||||
|
onMouseDown={(e) => this.handleMouseDown(e)}
|
||||||
|
onMouseUp={(e) => this.handleMouseUp(e)}
|
||||||
|
onMouseLeave={(e) => this.handleMouseLeave(e)}
|
||||||
|
onClick={this.props.onClick}
|
||||||
|
>
|
||||||
|
<i className={this.state.isActive || this.props.isActive
|
||||||
|
? 'fa fa-star'
|
||||||
|
: 'fa fa-star-o'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StarButton.propTypes = {
|
||||||
|
isActive: PropTypes.bool,
|
||||||
|
onClick: PropTypes.func,
|
||||||
|
className: PropTypes.string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CSSModules(StarButton, styles)
|
||||||
19
browser/main/Detail/StarButton.styl
Normal file
19
browser/main/Detail/StarButton.styl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
.root
|
||||||
|
position relative
|
||||||
|
color $ui-inactive-text-color
|
||||||
|
font-size 18px
|
||||||
|
text-align center
|
||||||
|
background-color transparent
|
||||||
|
border none
|
||||||
|
padding 0
|
||||||
|
transition transform 0.15s
|
||||||
|
&:hover
|
||||||
|
color $ui-text-color
|
||||||
|
transform rotate(-72deg)
|
||||||
|
|
||||||
|
.root--active
|
||||||
|
@extend .root
|
||||||
|
color $ui-active-color
|
||||||
|
transform rotate(-72deg)
|
||||||
|
&:hover
|
||||||
|
color $ui-active-color
|
||||||
@@ -136,6 +136,21 @@ class NoteList extends React.Component {
|
|||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (location.pathname.match(/\/starred/)) {
|
||||||
|
return repositories
|
||||||
|
.reduce((sum, repository) => {
|
||||||
|
return sum.concat(repository.starred
|
||||||
|
.map((starredKey) => {
|
||||||
|
return _.find(repository.notes, {key: starredKey})
|
||||||
|
})
|
||||||
|
.filter((note) => _.isObject(note))
|
||||||
|
.map((note) => {
|
||||||
|
note._repository = repository
|
||||||
|
return note
|
||||||
|
}))
|
||||||
|
}, [])
|
||||||
|
}
|
||||||
|
|
||||||
let repository = _.find(repositories, {key: repositoryKey})
|
let repository = _.find(repositories, {key: repositoryKey})
|
||||||
if (repository == null) return []
|
if (repository == null) return []
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,34 @@ function repositories (state = initialRepositories, action) {
|
|||||||
targetRepo.notes.push(action.note)
|
targetRepo.notes.push(action.note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return repos
|
||||||
|
}
|
||||||
|
case 'STAR_NOTE':
|
||||||
|
{
|
||||||
|
let repos = state.slice()
|
||||||
|
let targetRepo = _.find(repos, {key: action.repository})
|
||||||
|
|
||||||
|
if (targetRepo == null) return state
|
||||||
|
|
||||||
|
let targetNoteIndex = _.findIndex(targetRepo.notes, {key: action.note})
|
||||||
|
if (targetNoteIndex > -1) {
|
||||||
|
targetRepo.starred.push(action.note)
|
||||||
|
} else {
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
|
return repos
|
||||||
|
}
|
||||||
|
case 'UNSTAR_NOTE':
|
||||||
|
{
|
||||||
|
let repos = state.slice()
|
||||||
|
let targetRepo = _.find(repos, {key: action.repository})
|
||||||
|
|
||||||
|
if (targetRepo == null) return state
|
||||||
|
|
||||||
|
targetRepo.starred = targetRepo.starred
|
||||||
|
.filter((starredKey) => starredKey !== action.note)
|
||||||
|
|
||||||
return repos
|
return repos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user