File tree Expand file tree Collapse file tree 4 files changed +109
-0
lines changed Expand file tree Collapse file tree 4 files changed +109
-0
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,13 @@ import { RandomJoke } from "../pages/activities/RandomJoke";
1111import { RandomAnimeQuote } from "../pages/activities/RandomAnimeQuote" ;
1212import meme from "../assets/activities/meme.jpg"
1313import dog from "../assets/activities/dogimage.jpeg"
14+ import cat from "../assets/activities/cat.jpg"
1415import numberblocs from "../assets/numberblocks.png"
1516import wordleicon from "../assets/games/Wordle/wordlejpg.png"
1617import flagger from "../assets/games/flag guess/flagger.png"
1718import Calculator from "../pages/activities/Calculator"
1819import { DogHttpCode } from "../pages/activities/DogHttpCode" ;
20+ import { CatHttpCode } from "../pages/activities/CatHttpCode" ;
1921
2022export const activities = [
2123 {
@@ -74,6 +76,13 @@ export const activities = [
7476 urlTerm : "dog-http-status" ,
7577 element : < DogHttpCode />
7678 } ,
79+ {
80+ title : "Cat Http Status Code" ,
81+ description : "Get random cat images or meme" ,
82+ icon : cat ,
83+ urlTerm : "cat-http-status" ,
84+ element : < CatHttpCode />
85+ } ,
7786] ;
7887
7988export const games = [
Original file line number Diff line number Diff line change 1+ import "../../styles/pages/activities/CatHttpCode.css"
2+ import { useState } from "react" ;
3+
4+ export const CatHttpCode = ( ) => {
5+ const [ httpCode , setHttpCode ] = useState ( "" ) ;
6+ const [ imageUrl , setImageUrl ] = useState ( "" ) ;
7+ const [ error , setError ] = useState ( "" ) ;
8+
9+ const handleSubmit = ( e ) => {
10+ e . preventDefault ( ) ;
11+
12+ if ( httpCode < 100 || httpCode > 599 || isNaN ( httpCode ) ) {
13+ setError ( "Please enter a valid HTTP status code (100-599)." ) ;
14+ setImageUrl ( "" ) ;
15+ } else {
16+ setError ( "" ) ; //Clear any existing error
17+ setImageUrl ( `https://http.cat/${ httpCode } .jpg` ) ; //Construct the image url
18+ }
19+ } ;
20+
21+ return (
22+ < div className = "cat-root" >
23+ < h1 > Cat Http Status Code</ h1 >
24+ < form onSubmit = { handleSubmit } className = "cat-form" >
25+ < input type = "text" className = "cat-input" placeholder = "Enter the Http status code (e.g. 404)"
26+ value = { httpCode } onChange = { ( e ) => setHttpCode ( e . target . value ) } />
27+ < button type = "submit" className = "cat-submit" > Fetch Cat Image</ button >
28+ </ form >
29+
30+ { error && < p style = { { color : "red" } } > { error } </ p > }
31+ { imageUrl && (
32+ < div >
33+ < img
34+ src = { imageUrl }
35+ alt = { `Cat image for HTTP status code ${ httpCode } ` }
36+ style = { { marginTop : "20px" , width : "300px" , height : "300px" } }
37+ className = "cat-image" />
38+ </ div >
39+ ) }
40+ </ div >
41+ )
42+ }
Original file line number Diff line number Diff line change 1+ .cat-root {
2+ display : flex;
3+ flex-direction : column;
4+ align-items : center;
5+ margin-top : 20px ;
6+ }
7+
8+ .cat-form {
9+ display : flex;
10+ flex-direction : row;
11+ margin : 20px 0 ;
12+ }
13+
14+ .cat-input {
15+ width : 25rem ;
16+ height : 5rem ;
17+ padding : 0.5rem ;
18+ font-size : 16px ;
19+ border : 1px solid # ccc ;
20+ border-radius : 8px ;
21+ margin-right : 10px ;
22+ transition : border-color 300ms ;
23+ }
24+
25+ .cat-input : focus {
26+ outline : none;
27+ border-color : blue;
28+ }
29+
30+ .cat-submit {
31+ font-size : 18px ;
32+ background-color : white;
33+ border : 1px solid blue;
34+ color : blue;
35+ padding : 10px 15px ;
36+ border-radius : 10px ;
37+ transition : background-color 0.3s , transform 0.3s ;
38+ }
39+
40+ .cat-submit : hover {
41+ cursor : pointer;
42+ background-color : rgb (10 , 80 , 193 );
43+ color : white;
44+ transform : scale (1.1 );
45+ }
46+
47+ .cat-error {
48+ color : red;
49+ font-size : 16px ;
50+ margin-top : 10px ;
51+ }
52+
53+ .cat-image {
54+ margin-top : 20px ;
55+ max-width : 30rem ;
56+ max-height : 30rem ;
57+ object-fit : contain;
58+ }
You can’t perform that action at this time.
0 commit comments