wagtail/client/src/components/explorer/index.js
Josh Barr 14f02a0b50 Tooling for modern front-end components: React JS, ES6, and BEM CSS
Thanks to @justinvdm for the help

Merges: #2275
2016-02-25 13:32:48 +00:00

67 lines
1.3 KiB
JavaScript

import React, { Component, PropTypes } from 'react';
import LoadingIndicator from 'components/loading-indicator';
import ExplorerItem from './explorer-item';
import { API } from 'config';
class Explorer extends Component {
constructor(props) {
super(props);
this.state = { cursor: null };
}
componentDidMount() {
fetch(`${API}/pages/?child_of=root`)
.then(res => res.json())
.then(body => {
this.setState({
cursor: body
});
});
}
componentWillUnmount(cursor) {
}
_getPages(cursor) {
if (!cursor) {
return [];
}
return cursor.pages.map(item =>
<ExplorerItem key={item.id} title={item.title} data={item} />
);
}
getPosition() {
const { position } = this.props;
return {
left: position.right + 'px',
top: position.top + 'px'
};
}
render() {
const { cursor } = this.state;
const pages = this._getPages(cursor);
return (
<div style={this.getPosition()} className="c-explorer">
{cursor ? pages : <LoadingIndicator />}
</div>
);
}
}
Explorer.propTypes = {
onPageSelect: PropTypes.func,
initialPath: PropTypes.string,
apiPath: PropTypes.string,
size: PropTypes.number,
position: PropTypes.object
};
export default Explorer;