mirror of https://github.com/embarklabs/embark.git
Adding file contracts
This commit is contained in:
parent
ea9939c03a
commit
41eb23df82
|
@ -0,0 +1,44 @@
|
||||||
|
import React, {Component} from 'react';
|
||||||
|
import {connect} from 'react-redux';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import {withRouter} from 'react-router-dom';
|
||||||
|
|
||||||
|
import {contract as contractAction} from '../actions';
|
||||||
|
import ContractLayout from '../components/ContractLayout';
|
||||||
|
import {getContractsByFilename} from "../reducers/selectors";
|
||||||
|
|
||||||
|
class FileContractsContainer extends Component {
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.fetchContract(this.props.currentFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.props.contract){
|
||||||
|
return <ContractLayout contractIsFiddle={this.props.contract.isFiddle} />;
|
||||||
|
} else {
|
||||||
|
return <React.Fragment />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapStateToProps(state, props) {
|
||||||
|
return {
|
||||||
|
contracts: getContractsByFilename(state, props.currentFile.name),
|
||||||
|
error: state.errorMessage,
|
||||||
|
loading: state.loading
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
FileContractsContainer.propTypes = {
|
||||||
|
contracts: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
fetchFileContracts: PropTypes.func,
|
||||||
|
error: PropTypes.string,
|
||||||
|
loading: PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
{
|
||||||
|
fetchContract: contractAction.request
|
||||||
|
}
|
||||||
|
)(FileContractsContainer);
|
|
@ -8,6 +8,7 @@ import {
|
||||||
} from '../actions';
|
} from '../actions';
|
||||||
import {getCurrentFile} from '../reducers/selectors';
|
import {getCurrentFile} from '../reducers/selectors';
|
||||||
import Preview from '../components/Preview';
|
import Preview from '../components/Preview';
|
||||||
|
import FileContractsContainer from './FileContractsContainer';
|
||||||
|
|
||||||
class TextEditorAsideContainer extends Component {
|
class TextEditorAsideContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -30,7 +31,7 @@ class TextEditorAsideContainer extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return this.isContract() ? <React.Fragment>hello</React.Fragment> : <Preview />
|
return this.isContract() ? <FileContractsContainer currentFile={this.state.currentFile} /> : <Preview />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +49,8 @@ TextEditorAsideContainer.propTypes = {
|
||||||
currentFile: PropTypes.object,
|
currentFile: PropTypes.object,
|
||||||
fetchCurrentFile: PropTypes.func,
|
fetchCurrentFile: PropTypes.func,
|
||||||
loading: PropTypes.bool,
|
loading: PropTypes.bool,
|
||||||
error: PropTypes.string
|
error: PropTypes.string,
|
||||||
|
defaultFile: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
@ -123,6 +123,7 @@ function mapStateToProps(state, props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorContainer.propTypes = {
|
TextEditorContainer.propTypes = {
|
||||||
|
defaultFile: PropTypes.object,
|
||||||
currentFile: PropTypes.object,
|
currentFile: PropTypes.object,
|
||||||
contractCompile: PropTypes.object,
|
contractCompile: PropTypes.object,
|
||||||
saveCurrentFile: PropTypes.func,
|
saveCurrentFile: PropTypes.func,
|
||||||
|
|
|
@ -68,7 +68,7 @@ export function fetchContracts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchContract(payload) {
|
export function fetchContract(payload) {
|
||||||
return get(`/contract/${payload.contractName}`, ...arguments);
|
return get('/contract', ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postContractFunction(payload) {
|
export function postContractFunction(payload) {
|
||||||
|
|
|
@ -84,9 +84,16 @@ class ContractsManager {
|
||||||
|
|
||||||
embark.registerAPICall(
|
embark.registerAPICall(
|
||||||
'get',
|
'get',
|
||||||
'/embark-api/contract/:contractName',
|
'/embark-api/contract',
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
self.events.request('contracts:contract', req.params.contractName, res.send.bind(res));
|
const result = [];
|
||||||
|
self.events.request('contracts:all', null, (contracts) => {
|
||||||
|
const contractByFilename = contracts.filter((contract) => contract.filename === req.query.filename);
|
||||||
|
contractByFilename.forEach((contract) => {
|
||||||
|
self.events.request('contracts:contract', contract.className, (contract) => result.push(contract));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
res.send(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue