Added "Create new" buttons to the header. Closes #49
Note that this is temp solution UI-wise since it won't scale.
This commit is contained in:
@ -10,14 +10,18 @@ export function run(commandName, payload) {
|
|||||||
return { type: RUN_COMMAND, command: commandName, payload };
|
return { type: RUN_COMMAND, command: commandName, payload };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createNewEntryInCollection(collectionName) {
|
||||||
|
return runCommand(CREATE_COLLECTION, { collectionName });
|
||||||
|
}
|
||||||
|
|
||||||
export function runCommand(commandName, payload) {
|
export function runCommand(commandName, payload) {
|
||||||
return (dispatch, getState) => {
|
return dispatch => {
|
||||||
switch (commandName) {
|
switch (commandName) {
|
||||||
case SHOW_COLLECTION:
|
case SHOW_COLLECTION:
|
||||||
history.push(`/collections/${payload.collectionName}`);
|
history.push(`/collections/${payload.collectionName}`);
|
||||||
break;
|
break;
|
||||||
case CREATE_COLLECTION:
|
case CREATE_COLLECTION:
|
||||||
window.alert(`Create a new ${payload.collectionName} - not supported yet`);
|
history.push(`/collections/${payload.collectionName}/entries/new`);
|
||||||
break;
|
break;
|
||||||
case HELP:
|
case HELP:
|
||||||
window.alert('Find Bar Help (PLACEHOLDER)\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
window.alert('Find Bar Help (PLACEHOLDER)\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.actions {}
|
||||||
|
|
||||||
.findBar {
|
.findBar {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { IndexLink } from 'react-router';
|
import { IndexLink } from 'react-router';
|
||||||
|
import pluralize from 'pluralize';
|
||||||
import { loadConfig } from '../actions/config';
|
import { loadConfig } from '../actions/config';
|
||||||
import { loginUser } from '../actions/auth';
|
import { loginUser } from '../actions/auth';
|
||||||
import { currentBackend } from '../backends/backend';
|
import { currentBackend } from '../backends/backend';
|
||||||
import { Loader } from '../components/UI';
|
import { Loader } from '../components/UI';
|
||||||
import { SHOW_COLLECTION, CREATE_COLLECTION, HELP } from '../actions/findbar';
|
import {
|
||||||
|
SHOW_COLLECTION,
|
||||||
|
CREATE_COLLECTION,
|
||||||
|
HELP,
|
||||||
|
createNewEntryInCollection
|
||||||
|
} from '../actions/findbar';
|
||||||
import FindBar from './FindBar';
|
import FindBar from './FindBar';
|
||||||
import styles from './App.css';
|
import styles from './App.css';
|
||||||
import pluralize from 'pluralize';
|
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -84,8 +89,14 @@ class App extends React.Component {
|
|||||||
return { commands, defaultCommands };
|
return { commands, defaultCommands };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleCreatePostClick = collectionName => {
|
||||||
|
this.props.dispatch(
|
||||||
|
createNewEntryInCollection(collectionName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user, config, children } = this.props;
|
const { user, config, children, collections } = this.props;
|
||||||
|
|
||||||
if (config === null) {
|
if (config === null) {
|
||||||
return null;
|
return null;
|
||||||
@ -117,6 +128,16 @@ class App extends React.Component {
|
|||||||
defaultCommands={defaultCommands}
|
defaultCommands={defaultCommands}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className={styles.actions}>
|
||||||
|
{
|
||||||
|
collections.map(collection =>
|
||||||
|
<button
|
||||||
|
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))}
|
||||||
|
>
|
||||||
|
+ {pluralize(collection.get('label'), 1)}
|
||||||
|
</button>)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div className={styles.main}>
|
<div className={styles.main}>
|
||||||
{children}
|
{children}
|
||||||
|
Reference in New Issue
Block a user