From e7052dfb5b7f8d80db33b66a540bd92f064e9865 Mon Sep 17 00:00:00 2001 From: ajmaley Date: Mon, 8 Oct 2018 15:41:05 -0400 Subject: [PATCH] Added a better demo displaying how our app communicates with Flamelink Schemas and displays schema details in the right order. --- src/components/Flamelink.js | 31 +++++++++++++++++------ src/components/Layout.js | 49 +++++++++++++++++++++++++++++++++++++ src/pages/Info.js | 5 ++-- 3 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 src/components/Layout.js diff --git a/src/components/Flamelink.js b/src/components/Flamelink.js index 4033d59..d79007e 100644 --- a/src/components/Flamelink.js +++ b/src/components/Flamelink.js @@ -1,14 +1,31 @@ -import { Component } from 'react'; +import React, { Component, Fragment } from 'react'; +import Grid from '@material-ui/core/Grid'; import flamelinkApp from '../flamelink.js'; - +import Layout from './Layout'; class Flamelink extends Component { + constructor() { + super(); + + this.state = { + schemaDetails: '' + } + } + + componentDidMount() { + // fetch the project name, once it retrieves resolve the promsie and update the state. + flamelinkApp.schemas.getFields('martenSchemaDemo', { fields: [ 'title', 'key' ] }) + .then(result => this.setState({ + schemaDetails: result + })) + } + render() { - //Grabs data from text field in entry from the martenSchemaDemo - flamelinkApp.content.get('martenSchemaDemo') - .then(flameData => document.getElementById("flamelinkDemo").innerHTML = flameData.field_1538162314419); - - return(null); + return( + + + + ); } } diff --git a/src/components/Layout.js b/src/components/Layout.js new file mode 100644 index 0000000..760b0dc --- /dev/null +++ b/src/components/Layout.js @@ -0,0 +1,49 @@ +import React, { Component, Fragment } from 'react'; +import flamelinkApp from '../flamelink.js'; + +class Layout extends Component { + constructor() { + super(); + + this.state = { + contentDetails: '' + } + } + + + getData(schemaData){ + for (var val in this.props.schemaDetails){ + this.getMoreData(this.props.schemaDetails[val]); + } + } + + getMoreData(moreData){ + var tArray = document.createElement("H1"); + var kArray = document.createElement("P"); + this.getTitle(moreData.title, tArray); + this.getKey(moreData.key, kArray); + } + + getTitle(title, arr){ + var t = document.createTextNode(title); + arr.appendChild(t); + document.getElementById("demo").appendChild(arr); + } + + + getKey(key, arr){ + var k = document.createTextNode(key); + arr.appendChild(k); + document.getElementById("demo").appendChild(arr); + } + + render() { + return( +
+

{this.getData(this.props)}

+
+ ); + } +} + +export default Layout; \ No newline at end of file diff --git a/src/pages/Info.js b/src/pages/Info.js index 838a1e1..3db9d8f 100644 --- a/src/pages/Info.js +++ b/src/pages/Info.js @@ -2,16 +2,17 @@ import React, { Component } from 'react'; import Typography from '@material-ui/core/Typography'; import Flamelink from '../components/Flamelink'; + class Info extends Component { render() { return (
- + Info -

+
);