Skip to content

Commit

Permalink
Add an action to create new translations
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Jun 19, 2017
1 parent 9a56746 commit f15422f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/ProjectContents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProjectContents extends Component {

render() {
const { contents } = this.props;
const project_contents = contents.data.length ? contents.data[0] : {};
const project_contents = contents.original.length ? contents.original[0] : {};
return (
<div>
<h2>Project Contents</h2>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tutorial.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ options.log = (test) => {

function Tutorial(props) {
const { contents } = props;
const tutorial = contents.data.length ? contents.data[0] : { steps: [] };
const tutorial = contents.original.length ? contents.original[0] : { steps: [] };
const steps = [];
tutorial.steps && tutorial.steps.map((step, key) => {
steps.push(<p key={key}><b>{key}</b> {step.content}</p>);
Expand Down
2 changes: 1 addition & 1 deletion src/components/WorkflowContents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WorkflowContents extends Component {

render() {
const { contents } = this.props;
const workflow_contents = contents.data.length ? contents.data[0] : {strings: []};
const workflow_contents = contents.original.length ? contents.original[0] : {strings: []};
console.log(workflow_contents)
const strings = [];
for (const key in workflow_contents.strings) {
Expand Down
34 changes: 20 additions & 14 deletions src/ducks/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import apiClient from 'panoptes-client/lib/api-client';
export const FETCH_RESOURCE = 'FETCH_RESOURCE';
export const FETCH_RESOURCE_SUCCESS = 'FETCH_RESOURCE_SUCCESS';
export const FETCH_RESOURCE_ERROR = 'FETCH_RESOURCE_ERROR';
export const CREATE_TRANSLATION_SUCCESS = 'CREATE_TRANSLATION_SUCCESS';

// Reducer
const initialState = {
data: [],
original: [],
translation: null,
error: false,
loading: false,
};
Expand All @@ -17,9 +19,11 @@ const resourceReducer = (state = initialState, action) => {
case FETCH_RESOURCE:
return Object.assign({}, initialState, { loading: true });
case FETCH_RESOURCE_SUCCESS:
return Object.assign({}, state, { data: action.payload, loading: false });
return Object.assign({}, state, { original: action.payload, loading: false });
case FETCH_RESOURCE_ERROR:
return Object.assign({}, state, { error: action.payload, loading: false });
case CREATE_TRANSLATION_SUCCESS:
return Object.assign({}, state, { translation: action.payload, loading: false });
default:
return state;
}
Expand Down Expand Up @@ -77,25 +81,27 @@ function fetchResourceContents(id, type) {
};
}

const createNewTranslation = (type) =>
const createTranslation = (type, lang) =>
(dispatch, getState) => {
const { contents } = getState();
const translation = apiClient.type(type).create({
title: contents.title,
description: contents.description,
introduction: contents.introduction,
language: 'nz',
'links.project': contents.links.project,
});
translation.save()
.then(res => console.info('Saved! ', res))
const { original } = getState();
const newResource = Object.assign({}, original);
newResource.lang = lang;
apiClient.type(type)
.create(newResource)
.save()
.then((translation) => {
dispatch({
type: CREATE_TRANSLATION_SUCCESS,
payload: translation,
});
})
.catch(error => console.error(error));
};

// Exports
export default resourceReducer;

export {
createNewTranslation,
createTranslation,
fetchResource,
};

0 comments on commit f15422f

Please sign in to comment.