From 97e04b31391c2533ff94743d0fa04229aa127e4c Mon Sep 17 00:00:00 2001 From: PIYUSH956 Date: Mon, 3 Oct 2022 23:14:46 +0530 Subject: [PATCH 1/4] Ability to change width and orientation --- src/components/Meme.js | 45 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/components/Meme.js b/src/components/Meme.js index 6b34300..ad35040 100644 --- a/src/components/Meme.js +++ b/src/components/Meme.js @@ -5,7 +5,6 @@ export default function Meme() { const api_url = "https://api.imgflip.com/get_memes"; //this is to store all the meme's url returned by the api const [allMemes, setAllMemes] = useState([]); - //this function run only once on component load //when this component is mounted on page //it makes call to the api @@ -21,6 +20,8 @@ export default function Meme() { topText: "", bottomText: "", url: "", + width:"", + rotate:"", }); function getRandomMeme() { @@ -45,7 +46,8 @@ export default function Meme() { setMeme({ topText: "", bottomText: "", - url: "" + url: "", + width:"", }); } @@ -63,6 +65,22 @@ export default function Meme() { })); } + function widthChange(event) { + setMeme((prevMeme) => ({ + ...prevMeme, + width: event.target.value + })); + console.log(event.target.value); + } + + function rotateChange(event) { + setMeme((prevMeme) => ({ + ...prevMeme, + rotate: event.target.value, + })); + console.log(event.target.value); + } + // this is for uploading the image from the PC function uploadImage(event){ let fileURL = event.target.files[0]; @@ -100,6 +118,25 @@ export default function Meme() { name="bottomText" onChange={handleInput2Change} /> + + + + + @@ -113,8 +150,8 @@ export default function Meme() {
{meme.url && meme} - {meme.url &&

{meme.topText}

} - {meme.url &&

{meme.bottomText}

} + {meme.url &&

{meme.topText}

} + {meme.url &&

{meme.bottomText}

}
); From e310e741041f53749bd7f84dab1afa4cf54e69e2 Mon Sep 17 00:00:00 2001 From: Piyush Jaiswal <55656203+PIYUSH956@users.noreply.github.com> Date: Tue, 4 Oct 2022 01:24:08 +0530 Subject: [PATCH 2/4] Update Meme.js Correct the class name --- src/components/Meme.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Meme.js b/src/components/Meme.js index 767cb9b..df0cfd8 100644 --- a/src/components/Meme.js +++ b/src/components/Meme.js @@ -139,8 +139,8 @@ export default function Meme() {
{meme.url && meme - {meme.url &&

{meme.topText}

} - {meme.url &&

{meme.bottomText}

} + {meme.url &&

{meme.topText}

} + {meme.url &&

{meme.bottomText}

}
); From a77a0da0aa15deaad9b51efe5dbfb7bc36717f8c Mon Sep 17 00:00:00 2001 From: PIYUSH956 Date: Tue, 4 Oct 2022 02:11:54 +0530 Subject: [PATCH 3/4] Rotated In Center --- src/components/Meme.js | 79 ++++++++++++++++++++++++++++++++++-------- src/custom.css | 16 +++++++++ 2 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/custom.css diff --git a/src/components/Meme.js b/src/components/Meme.js index e8bcc98..bad11dc 100644 --- a/src/components/Meme.js +++ b/src/components/Meme.js @@ -1,11 +1,11 @@ import React from "react"; import { useState, useEffect } from "react"; +import '../custom.css'; export default function Meme() { const api_url = "https://api.imgflip.com/get_memes"; //this is to store all the meme's url returned by the api const [allMemes, setAllMemes] = useState([]); - //this function run only once on component load //when this component is mounted on page //it makes call to the api @@ -13,10 +13,7 @@ export default function Meme() { useEffect(function () { fetch(api_url) .then((data) => data.json()) - .then((data) => setAllMemes(data.data.memes)) - .catch((err) => - document.write("

Engine can't understand this code , it's invalid. please check code and reload page

") - ); + .then((data) => setAllMemes(data.data.memes)); }, []); //this state stores information about the current meme @@ -24,6 +21,8 @@ export default function Meme() { topText: "", bottomText: "", url: "", + width:"", + rotate:"", }); function getRandomMeme() { @@ -34,22 +33,53 @@ export default function Meme() { })); } + //this is for handling the input + function handleChange(event) { + const { name, value } = event.target; + setMeme((prevMeme) => ({ + ...prevMeme, + [name]: value, + })); + } + //this is for handling the reset functionality function handleReset() { setMeme({ topText: "", bottomText: "", - url: "" + url: "", + width:"", }); } //this is to handle input change - function handleInputChange(event) { - const {name, value} = event.target; + function handleInput1Change(event) { setMeme( (prevMeme) => ({ ...prevMeme, - [name]: value - }) ); + topText: event.target.value + })); + } + function handleInput2Change(event) { + setMeme( (prevMeme) => ({ + ...prevMeme, + bottomText: event.target.value + })); + } + + function widthChange(event) { + setMeme((prevMeme) => ({ + ...prevMeme, + width: event.target.value + })); + console.log(event.target.value); + } + + function rotateChange(event) { + setMeme((prevMeme) => ({ + ...prevMeme, + rotate: event.target.value, + })); + console.log(event.target.value); } // this is for uploading the image from the PC @@ -79,7 +109,7 @@ export default function Meme() { value={meme.topText} placeholder="text1" name="topText" - onChange={handleInputChange} + onChange={handleInput1Change} /> + + + + + -