diff --git a/.eslintcache b/.eslintcache index f008e49..48aa45b 100644 --- a/.eslintcache +++ b/.eslintcache @@ -1 +1 @@ -[{"/home/yusuf/Programming/React/quote-machine/src/index.js":"1","/home/yusuf/Programming/React/quote-machine/src/App.js":"2","/home/yusuf/Programming/React/quote-machine/src/reportWebVitals.js":"3","/home/yusuf/Programming/React/quote-machine/src/components/quote-box/quote-box.jsx":"4"},{"size":500,"mtime":1611491491707,"results":"5","hashOfConfig":"6"},{"size":201,"mtime":1611492929577,"results":"7","hashOfConfig":"6"},{"size":362,"mtime":1611491491707,"results":"8","hashOfConfig":"6"},{"size":287,"mtime":1611492997507,"results":"9","hashOfConfig":"6"},{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1h1r0ga",{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/home/yusuf/Programming/React/quote-machine/src/index.js",[],"/home/yusuf/Programming/React/quote-machine/src/App.js",[],"/home/yusuf/Programming/React/quote-machine/src/reportWebVitals.js",[],"/home/yusuf/Programming/React/quote-machine/src/components/quote-box/quote-box.jsx",[]] \ No newline at end of file +[{"/home/yusuf/Programming/React/quote-machine/src/index.js":"1","/home/yusuf/Programming/React/quote-machine/src/App.js":"2","/home/yusuf/Programming/React/quote-machine/src/reportWebVitals.js":"3","/home/yusuf/Programming/React/quote-machine/src/components/quote-box/quote-box.jsx":"4"},{"size":500,"mtime":1611491491707,"results":"5","hashOfConfig":"6"},{"size":201,"mtime":1611492929577,"results":"7","hashOfConfig":"6"},{"size":362,"mtime":1611491491707,"results":"8","hashOfConfig":"6"},{"size":1061,"mtime":1611496041983,"results":"9","hashOfConfig":"6"},{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1h1r0ga",{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/home/yusuf/Programming/React/quote-machine/src/index.js",[],"/home/yusuf/Programming/React/quote-machine/src/App.js",[],"/home/yusuf/Programming/React/quote-machine/src/reportWebVitals.js",[],"/home/yusuf/Programming/React/quote-machine/src/components/quote-box/quote-box.jsx",[]] \ No newline at end of file diff --git a/src/components/quote-box/quote-box.jsx b/src/components/quote-box/quote-box.jsx index d90ebe2..edfb94d 100644 --- a/src/components/quote-box/quote-box.jsx +++ b/src/components/quote-box/quote-box.jsx @@ -1,15 +1,45 @@ +import React from "react"; import "./quote-box-styles.scss"; -const QuoteBox = () => { - return ( -
-
-

Deneme

-

Deneme

- {/* new quote button */} +class QuoteBox extends React.Component { + constructor(props) { + super(props); + this.state = { + quotes: null, + displayQuote: "null", + displayAuthor: null, + }; + } + + random = () => { + return Math.floor(Math.random() * 1600); + }; + + async componentDidMount() { + const response = await fetch("https://type.fit/api/quotes"); + const json = await response.json(); + await this.setState({ quotes: json }); + const randomNum = this.random(); + await this.setState({ + displayQuote: this.state.quotes[randomNum].text, + displayAuthor: this.state.quotes[randomNum].author, + }); + } + render() { + if (!this.state.quotes) { + return
Loading...
; + } + + return ( +
+
+

{this.state.displayQuote}

+

{this.state.displayAuthor}

+ {/* new quote button */} +
-
- ); -}; + ); + } +} export default QuoteBox;