diff --git a/public/index.html b/public/index.html index e6407ba..5070c2f 100644 --- a/public/index.html +++ b/public/index.html @@ -1,21 +1,30 @@ - - - - - - - - + + + + + + + + + + - - - Binary JSON Formatter - - - - - - - - - - - - - - - -
- + + + + + + + + + + + + + + +
+ - - + + + \ No newline at end of file diff --git a/src/components/JSONFormatter/JSONFormatter.jsx b/src/components/JSONFormatter/JSONFormatter.jsx index c416f3c..7676eac 100644 --- a/src/components/JSONFormatter/JSONFormatter.jsx +++ b/src/components/JSONFormatter/JSONFormatter.jsx @@ -82,20 +82,36 @@ export class JSONFormatter extends Component { getJSONData() { // eslint-disable-next-line - var outputText, outputClass; + var outputText; try { outputText = this.formatJSON(this.state.inputText); - outputClass = 'output-good'; + if (outputText === "") { + outputText = this.state.jobText; + } } catch (err) { // JSON.parse threw an exception - outputText = 'It looks like there was an error with your JSON---\n\n' + err.message; - outputClass = 'output-error'; + outputText = 'It looks like there was an error with your input---\n\n' + err.message; } return outputText } + getJoke() { + fetch('https://geek-jokes.sameerkumar.website/api?format=json') + .then((response) => response.json()) + .then((responseJson) => { + this.setState({ jobText: responseJson.joke }) + }) + .catch((error) => { + console.error(error); + }); + } + + componentWillMount() { + this.getJoke(); + } + UNSAFE_componentWillMount() { this.setState({ inputText: ""