Skip to content

Commit

Permalink
ticket #7
Browse files Browse the repository at this point in the history
  • Loading branch information
LifeofMichal committed Jan 7, 2020
1 parent 5e09c96 commit 18f6cb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ header > p {
background: #6441A5;
}

.meme-form > button:disabled {
background: #ddd;
}

.meme-form > input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
font-family: VT323, monospace;
font-size: 25px;
Expand Down
5 changes: 3 additions & 2 deletions src/MemeGen/Form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react"

function Form(props) {
const { topText, bottomText, handleChange } = props
const { topText, bottomText, handleChange, memesListLength } = props


return (
<form className="meme-form">
Expand All @@ -20,7 +21,7 @@ function Form(props) {
onChange={handleChange}
/>

<button type="button" name="randomImg" onClick={handleChange}>Gen</button>
<button type="button" name="randomImg" onClick={handleChange} disabled={memesListLength ? false : true}>Gen</button>
</form>
)
}
Expand Down
22 changes: 15 additions & 7 deletions src/MemeGen/MemeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MemeGenerator extends Component {
handleChange = (event) => {
const { name, value } = event.target


if (name === "searchQuote") {

const filteredAMIs = this.state.allMemeImgs.filter(function (element) {
Expand All @@ -66,13 +67,16 @@ class MemeGenerator extends Component {
})
}

} else if ( name === "randomImg") {
const randomMeme = this.state.filteredMemes[Math.floor(Math.random() * Math.floor(this.state.filteredMemes.length))]
} else if ( name === "randomImg" && this.state.filteredMemes.length) {

this.setState({
topText: randomMeme.name,
[name]: randomMeme.url
})
const randomMeme = this.state.filteredMemes[Math.floor(Math.random() * Math.floor(this.state.filteredMemes.length))]

this.setState({
topText: randomMeme.name,
[name]: randomMeme.url
})

console.log(this.state.topText)
} else if( name === "selectedImg") {
const pickedImg = this.state.filteredMemes.find(element => element.url === value)

Expand All @@ -89,15 +93,19 @@ class MemeGenerator extends Component {
bottomText: value
})
}



}

render() {
const { loading, topText, bottomText, randomImg, allMemeImgs, filteredMemes, searchQuote } = this.state
const filteredMemesLength = this.state.filteredMemes.length
const pickImage = allMemeImgs.find(element => element.url === randomImg)

return (
<div className="memeGen">
<Form topText={topText} bottomText={bottomText} handleChange={this.handleChange} />
<Form topText={topText} bottomText={bottomText} handleChange={this.handleChange} memesListLength={filteredMemesLength}/>
<Search searchQuote={searchQuote} handleChange={this.handleChange} />
<Select randomImg={randomImg} filteredMemes={filteredMemes} searchQuote={searchQuote} handleChange={this.handleChange} />
{
Expand Down

0 comments on commit 18f6cb6

Please sign in to comment.