From 555f549c766941717bd1df82cf2ecfa2cb30fc97 Mon Sep 17 00:00:00 2001 From: TingluoHuang Date: Mon, 15 Jun 2020 16:54:43 -0400 Subject: [PATCH] add joke. --- public/index.html | 81 +++++++++++-------- .../JSONFormatter/JSONFormatter.jsx | 24 +++++- 2 files changed, 68 insertions(+), 37 deletions(-) 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: ""