-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Rahulagg13/feat/add-random-anime-quote
Feat: Add Random Anime Quote
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useEffect, useState } from "react"; | ||
import axios from "axios"; | ||
import "../../styles/pages/activities/RandomQuote.css"; | ||
|
||
export const RandomAnimeQuote = () => { | ||
const [quote, setQuote] = useState(null); | ||
const [error, setError] = useState(null); | ||
|
||
const generateQuote = async () => { | ||
try { | ||
setQuote(null); | ||
const res = await axios.get("/api/v1/quotes/random"); | ||
setQuote(res.data.data); | ||
} catch (error) { | ||
console.log(error); | ||
setError(error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
generateQuote(); | ||
}, []); | ||
|
||
return ( | ||
<div className="rquote-root"> | ||
<h1 className="header">Random Anime Quote Generator</h1> | ||
<div className="description"> | ||
Generate any random anime quote to get some inspiration! | ||
</div> | ||
{quote && ( | ||
<div className="rquote-content"> | ||
<div className="rquote-quote">{quote.content}</div> | ||
<div className="rquote-author"> | ||
- {quote.character.name} ({quote.anime.name}) | ||
</div> | ||
</div> | ||
)} | ||
{error && ( | ||
<div className="rquote-content error"> | ||
Too many requests have been sent to the API. Please try again after an | ||
hour. | ||
</div> | ||
)} | ||
{!quote && !error && ( | ||
<div className="spinner-wrapper"> | ||
<div className="spinner"></div> | ||
</div> | ||
)} | ||
<button className="rquote-button" onClick={() => generateQuote()}> | ||
Generate Quote | ||
</button> | ||
</div> | ||
); | ||
}; |