Skip to content

Commit 465b315

Browse files
committed
add Tag filter
1 parent 054daac commit 465b315

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

browser/main/Components/PlanetArticleDetail.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var PlanetArticleDetail = React.createClass({
1111
propTypes: {
1212
article: React.PropTypes.object,
1313
onOpenEditModal: React.PropTypes.func,
14-
onOpenDeleteModal: React.PropTypes.func
14+
onOpenDeleteModal: React.PropTypes.func,
15+
showOnlyWithTag: React.PropTypes.func
1516
},
1617
getInitialState: function () {
1718
return {
@@ -29,9 +30,9 @@ var PlanetArticleDetail = React.createClass({
2930
}
3031
var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) {
3132
return (
32-
<a key={tag.id} href>#{tag.name}</a>
33+
<a onClick={this.props.showOnlyWithTag(tag.name)} key={tag.id}>#{tag.name}</a>
3334
)
34-
}) : (
35+
}.bind(this)) : (
3536
<a className='noTag'>Not tagged yet</a>
3637
)
3738
if (article.type === 'snippet') {

browser/main/Components/PlanetArticleList.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var Markdown = require('../Mixins/Markdown')
88
var PlanetArticleList = React.createClass({
99
mixins: [ReactRouter.Navigation, ReactRouter.State, ForceUpdate(60000), Markdown],
1010
propTypes: {
11-
articles: React.PropTypes.array
11+
articles: React.PropTypes.array,
12+
showOnlyWithTag: React.PropTypes.func
1213
},
1314
handleKeyDown: function (e) {
1415
e.preventDefault()
@@ -17,9 +18,9 @@ var PlanetArticleList = React.createClass({
1718
var articles = this.props.articles.map(function (article) {
1819
var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) {
1920
return (
20-
<a key={tag.id} href>#{tag.name}</a>
21+
<a onClick={this.props.showOnlyWithTag(tag.name)} key={tag.id}>#{tag.name}</a>
2122
)
22-
}) : (
23+
}.bind(this)) : (
2324
<a className='noTag'>Not tagged yet</a>
2425
)
2526
var params = this.getParams()

browser/main/Containers/PlanetContainer.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function blueprintFilter (articles) {
6363
function tagFilter (keyword, articles) {
6464
return articles.filter(function (article) {
6565
return article.Tags.some(function (tag) {
66-
return tag.name.match(new RegExp(keyword, 'i'))
66+
return tag.name.match(new RegExp('^' + keyword, 'i'))
6767
})
6868
})
6969
}
@@ -336,6 +336,11 @@ module.exports = React.createClass({
336336
showOnlyBlueprints: function () {
337337
this.setState({search: '$b'})
338338
},
339+
showOnlyWithTag: function (tag) {
340+
return function () {
341+
this.setState({search: '#' + tag})
342+
}.bind(this)
343+
},
339344
openLaunchModal: function () {
340345
this.setState({isLaunchModalOpen: true})
341346
},
@@ -547,9 +552,9 @@ module.exports = React.createClass({
547552
showAll={this.showAll}
548553
showOnlySnippets={this.showOnlySnippets} showOnlyBlueprints={this.showOnlyBlueprints} currentPlanet={this.state.currentPlanet}/>
549554

550-
<PlanetArticleList ref='list' articles={filteredArticles}/>
555+
<PlanetArticleList showOnlyWithTag={this.showOnlyWithTag} ref='list' articles={filteredArticles}/>
551556

552-
<PlanetArticleDetail ref='detail' article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal}/>
557+
<PlanetArticleDetail ref='detail' article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal} showOnlyWithTag={this.showOnlyWithTag}/>
553558
</div>
554559
)
555560
}

browser/styles/main/containers/PlanetContainer.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
overflow-x: auto;
88
a
99
margin 0 2px
10+
text-decoration underline
11+
cursor pointer
1012
&.noTag
1113
color inactiveTextColor
1214
font-size 0.8em

0 commit comments

Comments
 (0)