mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-30 18:11:47 +00:00
addTag search
This commit is contained in:
@@ -6,7 +6,7 @@ import ArticleNavigator from './HomePage/ArticleNavigator'
|
||||
import ArticleTopBar from './HomePage/ArticleTopBar'
|
||||
import ArticleList from './HomePage/ArticleList'
|
||||
import ArticleDetail from './HomePage/ArticleDetail'
|
||||
import { findWhere, findIndex, pick } from 'lodash'
|
||||
import _, { findWhere, findIndex, pick } from 'lodash'
|
||||
import keygen from 'boost/keygen'
|
||||
import api from 'boost/api'
|
||||
import auth from 'boost/auth'
|
||||
@@ -14,6 +14,7 @@ import io from 'boost/socket'
|
||||
|
||||
const TEXT_FILTER = 'TEXT_FILTER'
|
||||
const FOLDER_FILTER = 'FOLDER_FILTER'
|
||||
const TAG_FILTER = 'TAG_FILTER'
|
||||
|
||||
class HomePage extends React.Component {
|
||||
componentDidMount () {
|
||||
@@ -83,14 +84,18 @@ function remap (state) {
|
||||
})
|
||||
|
||||
// Filter articles
|
||||
let filters = status.search.split(' ').map(key => key.trim()).filter(key => key.length > 0).map(key => {
|
||||
let filters = status.search.split(' ').map(key => key.trim()).filter(key => key.length > 0 && !key.match(/^#$/)).map(key => {
|
||||
if (key.match(/^in:.+$/)) {
|
||||
return {type: FOLDER_FILTER, value: key.match(/^in:(.+)$/)[1]}
|
||||
}
|
||||
if (key.match(/^#(.+)/)) {
|
||||
return {type: TAG_FILTER, value: key.match(/^#(.+)$/)[1]}
|
||||
}
|
||||
return {type: TEXT_FILTER, value: key}
|
||||
})
|
||||
let folderFilters = filters.filter(filter => filter.type === FOLDER_FILTER)
|
||||
let textFilters = filters.filter(filter => filter.type === TEXT_FILTER)
|
||||
let tagFilters = filters.filter(filter => filter.type === TAG_FILTER)
|
||||
|
||||
if (activeUser.Folders != null) {
|
||||
let targetFolders = activeUser.Folders.filter(folder => {
|
||||
@@ -110,6 +115,14 @@ function remap (state) {
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
|
||||
if (tagFilters.length > 0) {
|
||||
articles = tagFilters.reduce((articles, tagFilter) => {
|
||||
return articles.filter(article => {
|
||||
return _.find(article.Tags, tag => tag.name.match(new RegExp(tagFilter.value, 'i')))
|
||||
})
|
||||
}, articles)
|
||||
}
|
||||
}
|
||||
|
||||
// Grab active article
|
||||
|
||||
@@ -10,6 +10,7 @@ import Select from 'react-select'
|
||||
import linkState from 'boost/linkState'
|
||||
import api from 'boost/api'
|
||||
import FolderMark from 'boost/components/FolderMark'
|
||||
import TagLink from 'boost/components/TagLink'
|
||||
|
||||
var modeOptions = aceModes.map(function (mode) {
|
||||
return {
|
||||
@@ -86,13 +87,13 @@ export default class ArticleDetail extends React.Component {
|
||||
renderIdle () {
|
||||
let { activeArticle, activeUser } = this.props
|
||||
|
||||
let tags = activeArticle.Tags.length > 0 ? activeArticle.Tags.map(tag => {
|
||||
return (
|
||||
<a key={tag.name}>{tag.name}</a>
|
||||
let tags = activeArticle.Tags.length > 0
|
||||
? activeArticle.Tags.map(tag => {
|
||||
return (<TagLink key={tag.name} tag={tag}/>)
|
||||
})
|
||||
: (
|
||||
<span className='noTags'>Not tagged yet</span>
|
||||
)
|
||||
}) : (
|
||||
<span className='noTags'>Not tagged yet</span>
|
||||
)
|
||||
let folder = findWhere(activeUser.Folders, {id: activeArticle.FolderId})
|
||||
let folderName = folder != null ? folder.name : '(unknown)'
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import ModeIcon from 'boost/components/ModeIcon'
|
||||
import moment from 'moment'
|
||||
import { switchArticle, NEW } from 'boost/actions'
|
||||
import FolderMark from 'boost/components/FolderMark'
|
||||
import TagLink from 'boost/components/TagLink'
|
||||
|
||||
export default class ArticleList extends React.Component {
|
||||
handleArticleClick (key) {
|
||||
@@ -19,7 +20,7 @@ export default class ArticleList extends React.Component {
|
||||
let articlesEl = articles.map(article => {
|
||||
let tags = Array.isArray(article.Tags) && article.Tags.length > 0
|
||||
? article.Tags.map(tag => {
|
||||
return (<a key={tag.name}>{tag.name}</a>)
|
||||
return (<TagLink key={tag.name} tag={tag}/>)
|
||||
})
|
||||
: (<span>Not tagged yet</span>)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<div id="content"></div>
|
||||
|
||||
<script src="../../submodules/ace/src-min/ace.js"></script>
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
var version = require('remote').require('app').getVersion()
|
||||
document.title = 'Boost' + ((version == null || version.length === 0) ? ' DEV' : '')
|
||||
document.addEventListener('mousewheel', function(e) {
|
||||
|
||||
@@ -158,6 +158,7 @@ noTagsColor = #999
|
||||
margin 2px
|
||||
font-size 10px
|
||||
opacity 0.8
|
||||
cursor pointer
|
||||
&:hover
|
||||
opacity 1
|
||||
span.noTags
|
||||
|
||||
Reference in New Issue
Block a user