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

add Tag filter

This commit is contained in:
Rokt33r
2015-07-25 02:04:27 +09:00
parent 054daac6db
commit 465b315ae0
4 changed files with 18 additions and 9 deletions

View File

@@ -11,7 +11,8 @@ var PlanetArticleDetail = React.createClass({
propTypes: { propTypes: {
article: React.PropTypes.object, article: React.PropTypes.object,
onOpenEditModal: React.PropTypes.func, onOpenEditModal: React.PropTypes.func,
onOpenDeleteModal: React.PropTypes.func onOpenDeleteModal: React.PropTypes.func,
showOnlyWithTag: React.PropTypes.func
}, },
getInitialState: function () { getInitialState: function () {
return { return {
@@ -29,9 +30,9 @@ var PlanetArticleDetail = React.createClass({
} }
var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) { var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) {
return ( return (
<a key={tag.id} href>#{tag.name}</a> <a onClick={this.props.showOnlyWithTag(tag.name)} key={tag.id}>#{tag.name}</a>
) )
}) : ( }.bind(this)) : (
<a className='noTag'>Not tagged yet</a> <a className='noTag'>Not tagged yet</a>
) )
if (article.type === 'snippet') { if (article.type === 'snippet') {

View File

@@ -8,7 +8,8 @@ var Markdown = require('../Mixins/Markdown')
var PlanetArticleList = React.createClass({ var PlanetArticleList = React.createClass({
mixins: [ReactRouter.Navigation, ReactRouter.State, ForceUpdate(60000), Markdown], mixins: [ReactRouter.Navigation, ReactRouter.State, ForceUpdate(60000), Markdown],
propTypes: { propTypes: {
articles: React.PropTypes.array articles: React.PropTypes.array,
showOnlyWithTag: React.PropTypes.func
}, },
handleKeyDown: function (e) { handleKeyDown: function (e) {
e.preventDefault() e.preventDefault()
@@ -17,9 +18,9 @@ var PlanetArticleList = React.createClass({
var articles = this.props.articles.map(function (article) { var articles = this.props.articles.map(function (article) {
var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) { var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) {
return ( return (
<a key={tag.id} href>#{tag.name}</a> <a onClick={this.props.showOnlyWithTag(tag.name)} key={tag.id}>#{tag.name}</a>
) )
}) : ( }.bind(this)) : (
<a className='noTag'>Not tagged yet</a> <a className='noTag'>Not tagged yet</a>
) )
var params = this.getParams() var params = this.getParams()

View File

@@ -63,7 +63,7 @@ function blueprintFilter (articles) {
function tagFilter (keyword, articles) { function tagFilter (keyword, articles) {
return articles.filter(function (article) { return articles.filter(function (article) {
return article.Tags.some(function (tag) { return article.Tags.some(function (tag) {
return tag.name.match(new RegExp(keyword, 'i')) return tag.name.match(new RegExp('^' + keyword, 'i'))
}) })
}) })
} }
@@ -336,6 +336,11 @@ module.exports = React.createClass({
showOnlyBlueprints: function () { showOnlyBlueprints: function () {
this.setState({search: '$b'}) this.setState({search: '$b'})
}, },
showOnlyWithTag: function (tag) {
return function () {
this.setState({search: '#' + tag})
}.bind(this)
},
openLaunchModal: function () { openLaunchModal: function () {
this.setState({isLaunchModalOpen: true}) this.setState({isLaunchModalOpen: true})
}, },
@@ -547,9 +552,9 @@ module.exports = React.createClass({
showAll={this.showAll} showAll={this.showAll}
showOnlySnippets={this.showOnlySnippets} showOnlyBlueprints={this.showOnlyBlueprints} currentPlanet={this.state.currentPlanet}/> showOnlySnippets={this.showOnlySnippets} showOnlyBlueprints={this.showOnlyBlueprints} currentPlanet={this.state.currentPlanet}/>
<PlanetArticleList ref='list' articles={filteredArticles}/> <PlanetArticleList showOnlyWithTag={this.showOnlyWithTag} ref='list' articles={filteredArticles}/>
<PlanetArticleDetail ref='detail' article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal}/> <PlanetArticleDetail ref='detail' article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal} showOnlyWithTag={this.showOnlyWithTag}/>
</div> </div>
) )
} }

View File

@@ -7,6 +7,8 @@
overflow-x: auto; overflow-x: auto;
a a
margin 0 2px margin 0 2px
text-decoration underline
cursor pointer
&.noTag &.noTag
color inactiveTextColor color inactiveTextColor
font-size 0.8em font-size 0.8em