diff --git a/browser/main/HomePage.js b/browser/main/HomePage.js
index fc88883f..d9cd38cb 100644
--- a/browser/main/HomePage.js
+++ b/browser/main/HomePage.js
@@ -12,6 +12,9 @@ import api from 'boost/api'
import auth from 'boost/auth'
import io from 'boost/socket'
+const TEXT_FILTER = 'TEXT_FILTER'
+const FOLDER_FILTER = 'FOLDER_FILTER'
+
class HomePage extends React.Component {
componentDidMount () {
const { dispatch } = this.props
@@ -53,7 +56,7 @@ class HomePage extends React.Component {
@@ -72,12 +75,42 @@ function remap (state) {
let activeUser = findWhere(users, {id: parseInt(status.userId, 10)})
if (activeUser == null) activeUser = users[0]
+ // Fetch articles
let articles = state.articles['team-' + activeUser.id]
if (articles == null) articles = []
articles.sort((a, b) => {
return new Date(b.updatedAt) - new Date(a.updatedAt)
})
+ // Filter articles
+ let filters = status.search.split(' ').map(key => key.trim()).filter(key => key.length > 0).map(key => {
+ if (key.match(/^in:.+$/)) {
+ return {type: FOLDER_FILTER, value: key.match(/^in:(.+)$/)[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 targetFolders = activeUser.Folders.filter(folder => {
+ return findWhere(folderFilters, {value: folder.name})
+ })
+ status.targetFolders = targetFolders
+
+ if (targetFolders.length > 0) {
+ articles = articles.filter(article => {
+ return findWhere(targetFolders, {id: article.FolderId})
+ })
+ }
+ if (textFilters.length > 0) {
+ articles = textFilters.reduce((articles, textFilter) => {
+ return articles.filter(article => {
+ return article.title.match(new RegExp(textFilter.value, 'i')) || article.content.match(new RegExp(textFilter.value, 'i'))
+ })
+ }, articles)
+ }
+
+ // Grab active article
let activeArticle = findWhere(articles, {key: status.articleKey})
if (activeArticle == null) activeArticle = articles[0]
@@ -120,7 +153,7 @@ function remap (state) {
articles,
activeArticle
}
- console.log(props)
+
return props
}
@@ -131,8 +164,7 @@ HomePage.propTypes = {
userId: PropTypes.string
}),
status: PropTypes.shape({
- userId: PropTypes.string,
- folderId: PropTypes.number
+ userId: PropTypes.string
}),
articles: PropTypes.array,
activeArticle: PropTypes.shape(),
diff --git a/browser/main/HomePage/ArticleList.js b/browser/main/HomePage/ArticleList.js
index 84e6753b..a9657a03 100644
--- a/browser/main/HomePage/ArticleList.js
+++ b/browser/main/HomePage/ArticleList.js
@@ -15,7 +15,6 @@ export default class ArticleList extends React.Component {
render () {
let { articles, activeArticle } = this.props
- console.log(articles)
let articlesEl = articles.map(article => {
let tags = Array.isArray(article.Tags) && article.Tags.length > 0
diff --git a/browser/main/HomePage/ArticleNavigator.js b/browser/main/HomePage/ArticleNavigator.js
index 963222fa..197555c6 100644
--- a/browser/main/HomePage/ArticleNavigator.js
+++ b/browser/main/HomePage/ArticleNavigator.js
@@ -1,7 +1,7 @@
import React, { PropTypes } from 'react'
import ProfileImage from 'boost/components/ProfileImage'
import { findWhere } from 'lodash'
-import { switchMode, CREATE_MODE } from 'boost/actions'
+import { setSearchFilter, switchFolder, switchMode, CREATE_MODE } from 'boost/actions'
import { openModal } from 'boost/modal'
import FolderMark from 'boost/components/FolderMark'
import Preferences from 'boost/components/modal/Preferences'
@@ -27,16 +27,30 @@ export default class ArticleNavigator extends React.Component {
openModal(CreateNewFolder, {user: activeUser})
}
+ handleFolderButtonClick (name) {
+ return e => {
+ let { dispatch } = this.props
+ dispatch(switchFolder(name))
+ }
+ }
+
+ handleAllFoldersButtonClick (e) {
+ let { dispatch } = this.props
+ dispatch(setSearchFilter(''))
+ }
+
render () {
let { activeUser, status } = this.props
if (activeUser == null) return ()
-
- let activeFolder = findWhere(activeUser.Folders, {id: status.folderId})
+ let { targetFolders } = status
+ if (targetFolders == null) targetFolders = []
let folders = activeUser.Folders != null
? activeUser.Folders.map((folder, index) => {
+ let isActive = findWhere(targetFolders, {id: folder.id})
+
return (
-