JSFiddle - React, Tailwind, and code Playground
by evgkch
JavaScript
async componentWillMount() {
const pathURI = this.props.location.pathname.split('/')[2];
const [comments, object] = Promise.all([
getComments(pathURI),
getObj(pathURI)
]);
getComments(this.props.location.pathname.split('/')[2])
.then(comments => this.setState({
comments,
commentsDisabled: !(comments.length > 0),
}));
getObj(this.props.location.pathname.split('/')[2])
.then((response) => {
getVersion(this.props.location.pathname.split('/')[2])
.then((rsp) => {
const versions = rsp.fetch.versions_ids.versions_ids;
const buildings = rsp.fetch['versions_ids.buildings_ids'].buildings_ids;
const enrichedVersions = versions.map((version) => {
const enVersion = version;
const buildingIds = version.buildings_ids.split(',');
if (buildingIds[0] !== '') {
buildings.forEach((buildingsArray) => {
if (buildingsArray[0] && buildingIds.includes(buildingsArray[0].id)) {
enVersion.buildingsArray = buildingsArray;
}
});
return enVersion;
} enVersion.buildingsArray = [];
return enVersion;
});
this.setState({
versions: enrichedVersions,
obj: response.fetch.currentVersion_id.currentVersion_id,
buildings: response.fetch['currentVersion_id.buildings_ids'].buildings_ids,
firstSaveOccured: response.fetch.firstSaveOccured.firstSaveOccured,
address: response.obj.address,
status: response.obj.status,
version: response.obj.version,
developerReady: response.obj.developerReady,
designerReady: response.obj.designerReady,
});
})
.then(getMeta('atzVersion')
.then((responseMeta) => {
const structured =...