static-cms/src/actions/findbar.js

32 lines
991 B
JavaScript
Raw Normal View History

2016-07-15 15:05:04 -03:00
import history from '../routing/history';
2016-07-08 07:20:20 -03:00
import { SEARCH } from '../containers/FindBar';
2016-07-06 18:51:43 -03:00
export const RUN_COMMAND = 'RUN_COMMAND';
export const SHOW_COLLECTION = 'SHOW_COLLECTION';
export const CREATE_COLLECTION = 'CREATE_COLLECTION';
2016-07-08 07:20:20 -03:00
export const HELP = 'HELP';
2016-07-06 18:51:43 -03:00
2016-07-08 07:20:20 -03:00
export function run(commandName, payload) {
2016-07-07 12:04:19 -03:00
return { type: RUN_COMMAND, command: commandName, payload };
2016-07-06 18:51:43 -03:00
}
2016-07-08 07:20:20 -03:00
export function runCommand(commandName, payload) {
return (dispatch, getState) => {
switch (commandName) {
case SHOW_COLLECTION:
history.push(`/collections/${payload.collectionName}`);
2016-07-08 07:20:20 -03:00
break;
case CREATE_COLLECTION:
window.alert(`Create a new ${payload.collectionName} - not supported yet`);
2016-07-08 07:20:20 -03:00
break;
case HELP:
window.alert('Find Bar Help (PLACEHOLDER)\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.');
break;
case SEARCH:
2016-07-15 15:05:04 -03:00
history.push('/search');
2016-07-08 07:20:20 -03:00
break;
}
dispatch(run(commandName, payload));
};
}