diff --git a/dashboard-client/app/app/src/App.js b/dashboard-client/app/app/src/App.js index 04ed341f2b..9f1388029f 100644 --- a/dashboard-client/app/app/src/App.js +++ b/dashboard-client/app/app/src/App.js @@ -16,33 +16,54 @@ const Container = styled.div` class App extends Component { state = { - number: null, + number: '', foundPRs: [] }; + inputRef = React.createRef(); + handleInputChange = (event) => { const { value } = event.target; - - this.setState((prevState) => ({ number: value })); + console.log(Number(value)) + if (Number(value) || value === '') { + this.setState((prevState) => ({ number: value, foundPRs: [] })); + } } handleButtonClick = () => { const { number } = this.state; - fetch(`https://pr-relations.glitch.me/test/${number}`) + fetch(`https://pr-relations.glitch.me/pr/${number}`) .then((response) => response.json()) - .then(({ foundPRs }) => { - console.log(foundPRs); - this.setState((prevState) => ({ foundPRs })) + .then(({ ok, foundPRs }) => { + if (ok) { + if (!foundPRs.length) { + foundPRs.push({number: 'No PRs with matching files', filenames: []}); + } + this.setState((prevState) => ({ foundPRs })); + } + else { + this.inputRef.current.focus(); + } + }) + .catch((err) => { + //console.log(err) + this.setState((prevState) => ({ number: '', foundPRs: [] })); }); } render() { - const { foundPRs } = this.state; + const { number, foundPRs } = this.state; return ( - + diff --git a/dashboard-client/app/app/src/components/Input.js b/dashboard-client/app/app/src/components/Input.js index 029f9905f6..8b81a78954 100644 --- a/dashboard-client/app/app/src/components/Input.js +++ b/dashboard-client/app/app/src/components/Input.js @@ -1,10 +1,12 @@ import React from 'react'; -const Input = ({ onInputChange }) => ( +const Input = ({ onInputChange, value, test }) => ( ); diff --git a/dashboard-client/app/app/src/components/Results.js b/dashboard-client/app/app/src/components/Results.js index a0acc8b4a7..c78871008c 100644 --- a/dashboard-client/app/app/src/components/Results.js +++ b/dashboard-client/app/app/src/components/Results.js @@ -6,10 +6,15 @@ const Results = ({ foundPRs }) => { const files = filenames.map((filename, index) => { return
  • {filename}
  • ; }); - + const prUrl = `https://github.com/freeCodeCamp/freeCodeCamp/pull/${number}` return (
    -

    {number}

    +
    + {!Number(number) + ? number + : {number} + } +