11import { useEffect , useState } from "react" ;
2- import axios from "axios" ;
32import "../../styles/pages/activities/RandomQuote.css" ;
43
54export const RandomAnimeQuote = ( ) => {
@@ -9,11 +8,21 @@ export const RandomAnimeQuote = () => {
98 const generateQuote = async ( ) => {
109 try {
1110 setQuote ( null ) ;
12- const res = await axios . get ( "/api/v1/quotes/random" ) ;
13- setQuote ( res . data . data ) ;
14- } catch ( error ) {
15- console . log ( error ) ;
16- setError ( error ) ;
11+ setError ( null ) ;
12+
13+ const response = await fetch ( "https://animotto-api.onrender.com/api/quotes/random" ) ;
14+ if ( ! response . ok ) throw new Error ( "Network response was not ok" ) ;
15+
16+ const data = await response . json ( ) ;
17+
18+ setQuote ( {
19+ quote : data . quote ,
20+ character : data . character ,
21+ anime : data . anime . name || data . anime . altName || "Unknown"
22+ } ) ;
23+ } catch ( err ) {
24+ console . error ( err ) ;
25+ setError ( err ) ;
1726 }
1827 } ;
1928
@@ -27,26 +36,29 @@ export const RandomAnimeQuote = () => {
2736 < div className = "description" >
2837 Generate any random anime quote to get some inspiration!
2938 </ div >
39+
3040 { quote && (
3141 < div className = "rquote-content" >
32- < div className = "rquote-quote" > { quote . content } </ div >
42+ < div className = "rquote-quote" > { quote . quote } </ div >
3343 < div className = "rquote-author" >
34- - { quote . character . name } ({ quote . anime . name } )
44+ - { quote . character } ({ quote . anime } )
3545 </ div >
3646 </ div >
3747 ) }
48+
3849 { error && (
3950 < div className = "rquote-content error" >
40- Too many requests have been sent to the API. Please try again after an
41- hour.
51+ Error fetching quote. Please try again later.
4252 </ div >
4353 ) }
54+
4455 { ! quote && ! error && (
4556 < div className = "spinner-wrapper" >
4657 < div className = "spinner" > </ div >
4758 </ div >
4859 ) }
49- < button className = "rquote-button" onClick = { ( ) => generateQuote ( ) } >
60+
61+ < button className = "rquote-button" onClick = { generateQuote } >
5062 Generate Quote
5163 </ button >
5264 </ div >
0 commit comments