Skip to content

Commit f56df7c

Browse files
committed
addTag search
1 parent c507dfa commit f56df7c

10 files changed

Lines changed: 63 additions & 14 deletions

File tree

browser/main/HomePage.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import ArticleNavigator from './HomePage/ArticleNavigator'
66
import ArticleTopBar from './HomePage/ArticleTopBar'
77
import ArticleList from './HomePage/ArticleList'
88
import ArticleDetail from './HomePage/ArticleDetail'
9-
import { findWhere, findIndex, pick } from 'lodash'
9+
import _, { findWhere, findIndex, pick } from 'lodash'
1010
import keygen from 'boost/keygen'
1111
import api from 'boost/api'
1212
import auth from 'boost/auth'
1313
import io from 'boost/socket'
1414

1515
const TEXT_FILTER = 'TEXT_FILTER'
1616
const FOLDER_FILTER = 'FOLDER_FILTER'
17+
const TAG_FILTER = 'TAG_FILTER'
1718

1819
class HomePage extends React.Component {
1920
componentDidMount () {
@@ -83,14 +84,18 @@ function remap (state) {
8384
})
8485

8586
// Filter articles
86-
let filters = status.search.split(' ').map(key => key.trim()).filter(key => key.length > 0).map(key => {
87+
let filters = status.search.split(' ').map(key => key.trim()).filter(key => key.length > 0 && !key.match(/^#$/)).map(key => {
8788
if (key.match(/^in:.+$/)) {
8889
return {type: FOLDER_FILTER, value: key.match(/^in:(.+)$/)[1]}
8990
}
91+
if (key.match(/^#(.+)/)) {
92+
return {type: TAG_FILTER, value: key.match(/^#(.+)$/)[1]}
93+
}
9094
return {type: TEXT_FILTER, value: key}
9195
})
9296
let folderFilters = filters.filter(filter => filter.type === FOLDER_FILTER)
9397
let textFilters = filters.filter(filter => filter.type === TEXT_FILTER)
98+
let tagFilters = filters.filter(filter => filter.type === TAG_FILTER)
9499

95100
if (activeUser.Folders != null) {
96101
let targetFolders = activeUser.Folders.filter(folder => {
@@ -110,6 +115,14 @@ function remap (state) {
110115
})
111116
}, articles)
112117
}
118+
119+
if (tagFilters.length > 0) {
120+
articles = tagFilters.reduce((articles, tagFilter) => {
121+
return articles.filter(article => {
122+
return _.find(article.Tags, tag => tag.name.match(new RegExp(tagFilter.value, 'i')))
123+
})
124+
}, articles)
125+
}
113126
}
114127

115128
// Grab active article

browser/main/HomePage/ArticleDetail.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Select from 'react-select'
1010
import linkState from 'boost/linkState'
1111
import api from 'boost/api'
1212
import FolderMark from 'boost/components/FolderMark'
13+
import TagLink from 'boost/components/TagLink'
1314

1415
var modeOptions = aceModes.map(function (mode) {
1516
return {
@@ -86,13 +87,13 @@ export default class ArticleDetail extends React.Component {
8687
renderIdle () {
8788
let { activeArticle, activeUser } = this.props
8889

89-
let tags = activeArticle.Tags.length > 0 ? activeArticle.Tags.map(tag => {
90-
return (
91-
<a key={tag.name}>{tag.name}</a>
90+
let tags = activeArticle.Tags.length > 0
91+
? activeArticle.Tags.map(tag => {
92+
return (<TagLink key={tag.name} tag={tag}/>)
93+
})
94+
: (
95+
<span className='noTags'>Not tagged yet</span>
9296
)
93-
}) : (
94-
<span className='noTags'>Not tagged yet</span>
95-
)
9697
let folder = findWhere(activeUser.Folders, {id: activeArticle.FolderId})
9798
let folderName = folder != null ? folder.name : '(unknown)'
9899

browser/main/HomePage/ArticleList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ModeIcon from 'boost/components/ModeIcon'
44
import moment from 'moment'
55
import { switchArticle, NEW } from 'boost/actions'
66
import FolderMark from 'boost/components/FolderMark'
7+
import TagLink from 'boost/components/TagLink'
78

89
export default class ArticleList extends React.Component {
910
handleArticleClick (key) {
@@ -19,7 +20,7 @@ export default class ArticleList extends React.Component {
1920
let articlesEl = articles.map(article => {
2021
let tags = Array.isArray(article.Tags) && article.Tags.length > 0
2122
? article.Tags.map(tag => {
22-
return (<a key={tag.name}>{tag.name}</a>)
23+
return (<TagLink key={tag.name} tag={tag}/>)
2324
})
2425
: (<span>Not tagged yet</span>)
2526

browser/main/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div id="content"></div>
5454

5555
<script src="../../submodules/ace/src-min/ace.js"></script>
56-
<script type="text/javascript">
56+
<script>
5757
var version = require('remote').require('app').getVersion()
5858
document.title = 'Boost' + ((version == null || version.length === 0) ? ' DEV' : '')
5959
document.addEventListener('mousewheel', function(e) {

browser/styles/main/HomeContainer/components/ArticleDetail.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ noTagsColor = #999
158158
margin 2px
159159
font-size 10px
160160
opacity 0.8
161+
cursor pointer
161162
&:hover
162163
opacity 1
163164
span.noTags

lib/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const SWITCH_FOLDER = 'SWITCH_FOLDER'
99
export const SWITCH_MODE = 'SWITCH_MODE'
1010
export const SWITCH_ARTICLE = 'SWITCH_ARTICLE'
1111
export const SET_SEARCH_FILTER = 'SET_SEARCH_FILTER'
12+
export const SET_TAG_FILTER = 'SET_TAG_FILTER'
1213

1314
// Status - mode
1415
export const IDLE_MODE = 'IDLE_MODE'
@@ -84,3 +85,10 @@ export function setSearchFilter (search) {
8485
data: search
8586
}
8687
}
88+
89+
export function setTagFilter (tag) {
90+
return {
91+
type: SET_TAG_FILTER,
92+
data: tag
93+
}
94+
}

lib/components/CodeEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
2+
let ReactDOM = require('react-dom')
33
var ace = window.ace
44

55
module.exports = React.createClass({
@@ -16,7 +16,7 @@ module.exports = React.createClass({
1616
}
1717
},
1818
componentDidMount: function () {
19-
var el = React.findDOMNode(this.refs.target)
19+
var el = ReactDOM.findDOMNode(this.refs.target)
2020
var editor = ace.edit(el)
2121
editor.$blockScrolling = Infinity
2222
editor.setValue(this.props.code)

lib/components/TagLink.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { PropTypes } from 'react'
2+
import store from '../store'
3+
import { setTagFilter } from '../actions'
4+
5+
export default class TagLink extends React.Component {
6+
handleClick (e) {
7+
store.dispatch(setTagFilter(this.props.tag.name))
8+
}
9+
render () {
10+
return (
11+
<a onClick={e => this.handleClick(e)}>{this.props.tag.name}</a>
12+
)
13+
}
14+
}
15+
16+
TagLink.propTypes = {
17+
tag: PropTypes.shape({
18+
name: PropTypes.string
19+
})
20+
}

lib/components/modal/CreateNewFolder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class CreateNewFolder extends React.Component {
2727

2828
api.createFolder(input)
2929
.then(res => {
30-
console.log(res)
30+
console.log(res.body)
3131
close()
3232
})
3333
.catch(err => {

lib/reducer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { combineReducers } from 'redux'
22
import { findIndex } from 'lodash'
3-
import { SWITCH_USER, SWITCH_FOLDER, SWITCH_MODE, SWITCH_ARTICLE, SET_SEARCH_FILTER, USER_UPDATE, ARTICLE_REFRESH, ARTICLE_UPDATE, ARTICLE_DESTROY, IDLE_MODE, CREATE_MODE } from './actions'
3+
import { SWITCH_USER, SWITCH_FOLDER, SWITCH_MODE, SWITCH_ARTICLE, SET_SEARCH_FILTER, SET_TAG_FILTER, USER_UPDATE, ARTICLE_REFRESH, ARTICLE_UPDATE, ARTICLE_DESTROY, IDLE_MODE, CREATE_MODE } from './actions'
44
import auth from 'boost/auth'
55

66
const initialStatus = {
@@ -40,6 +40,7 @@ function status (state, action) {
4040
case SWITCH_USER:
4141
state.userId = action.data
4242
state.mode = IDLE_MODE
43+
state.search = ''
4344
return state
4445
case SWITCH_FOLDER:
4546
state.mode = IDLE_MODE
@@ -58,6 +59,10 @@ function status (state, action) {
5859
state.search = action.data
5960
state.mode = IDLE_MODE
6061
return state
62+
case SET_TAG_FILTER:
63+
state.search = `#${action.data}`
64+
state.mode = IDLE_MODE
65+
return state
6166
default:
6267
if (state == null) return initialStatus
6368
return state

0 commit comments

Comments
 (0)