diff --git a/package.json b/package.json index 8520cb82..b6f2bec3 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "js-base64": "^2.1.9", "json-loader": "^0.5.4", "localforage": "^1.4.2", - "lodash": "^4.13.1" + "lodash": "^4.13.1", + "pluralize": "^3.0.0" } } diff --git a/src/actions/findbar.js b/src/actions/findbar.js index 77053ada..68db0399 100644 --- a/src/actions/findbar.js +++ b/src/actions/findbar.js @@ -2,8 +2,8 @@ import history from '../routing/history'; import { SEARCH } from '../containers/FindBar'; export const RUN_COMMAND = 'RUN_COMMAND'; -export const LIST_POSTS = 'LIST_POSTS'; -export const LIST_FAQ = 'LIST_FAQ'; +export const SHOW_COLLECTION = 'SHOW_COLLECTION'; +export const CREATE_COLLECTION = 'CREATE_COLLECTION'; export const HELP = 'HELP'; export function run(commandName, payload) { @@ -13,11 +13,11 @@ export function run(commandName, payload) { export function runCommand(commandName, payload) { return (dispatch, getState) => { switch (commandName) { - case LIST_POSTS: - history.push('/collections/posts'); + case SHOW_COLLECTION: + history.push(`/collections/${payload.collectionName}`); break; - case LIST_FAQ: - history.push('/collections/faq'); + case CREATE_COLLECTION: + window.alert(`Create a new ${payload.collectionName} - not supported yet`); break; case HELP: window.alert('Find Bar Help (PLACEHOLDER)\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.'); diff --git a/src/containers/App.js b/src/containers/App.js index 2e0a00ef..052af2c1 100644 --- a/src/containers/App.js +++ b/src/containers/App.js @@ -3,9 +3,10 @@ import { connect } from 'react-redux'; import { loadConfig } from '../actions/config'; import { loginUser } from '../actions/auth'; import { currentBackend } from '../backends/backend'; -import { LIST_POSTS, LIST_FAQ, HELP, MORE_COMMANDS } from '../actions/findbar'; +import { SHOW_COLLECTION, CREATE_COLLECTION, HELP } from '../actions/findbar'; import FindBar from './FindBar'; import styles from './App.css'; +import pluralize from 'pluralize'; class App extends React.Component { componentDidMount() { @@ -50,6 +51,37 @@ class App extends React.Component { ; } + generateFindBarCommands() { + // Generate command list + const commands = []; + const defaultCommands = []; + + this.props.collections.forEach(collection => { + commands.push({ + id: `show_${collection.get('name')}`, + pattern: `Show ${pluralize(collection.get('label'))}`, + type: SHOW_COLLECTION, + payload: { collectionName:collection.get('name') } + }); + + if (defaultCommands.length < 5) defaultCommands.push(`show_${collection.get('name')}`); + + if (collection.get('create') === true) { + commands.push({ + id: `create_${collection.get('name')}`, + pattern: `Create new ${pluralize(collection.get('label'), 1)}(:itemName as ${pluralize(collection.get('label'), 1)} Name)`, + type: CREATE_COLLECTION, + payload: { collectionName:collection.get('name') } + }); + } + }); + + commands.push({ id: HELP, type: HELP, pattern: 'Help' }); + defaultCommands.push(HELP); + + return { commands, defaultCommands }; + } + render() { const { user, config, children } = this.props; @@ -69,15 +101,16 @@ class App extends React.Component { return this.authenticating(); } + const { commands, defaultCommands } = this.generateFindBarCommands(); + return (