@@ -12,6 +12,7 @@ function App() {
12
12
const [ ipData , setIpData ] = useState ( { } ) ;
13
13
const [ searchIP , setSearchIP ] = useState ( "" ) ;
14
14
const [ latlang , setLatlang ] = useState ( [ - 6.1752 , 106.8272 ] ) ;
15
+ const [ errorMsg , seterrorMsg ] = useState ( ) ;
15
16
16
17
useEffect ( ( ) => {
17
18
//this web app is built for learning & experimenting purposes, therefore this kind of API request is strongly NOT recommended due to exposing the API key to the client, please consider using a server-side request for an API request that requires an API KEY.
@@ -26,10 +27,13 @@ function App() {
26
27
? `domain=${ searchIP } `
27
28
: `ipAddress=${ searchIP } `
28
29
} `
29
- ) . then ( ( res ) => {
30
- setIpData ( res . data ) ;
31
- setLatlang ( [ res . data . location ?. lat , res . data . location ?. lng ] ) ;
32
- } ) ;
30
+ )
31
+ . then ( ( res ) => {
32
+ setIpData ( res . data ) ;
33
+ setLatlang ( [ res . data . location ?. lat , res . data . location ?. lng ] ) ;
34
+ seterrorMsg ( "" ) ;
35
+ } )
36
+ . catch ( ( err ) => seterrorMsg ( err ?. message ) ) ;
33
37
} , 500 ) ;
34
38
35
39
return ( ) => clearTimeout ( timer ) ;
@@ -55,78 +59,90 @@ function App() {
55
59
} ) ;
56
60
57
61
return (
58
- < div id = "App" >
59
- < header
60
- className = "h-76 bg-cover bg-center flex container"
61
- style = { { backgroundImage : `url(${ patternBg } )` } }
62
- >
62
+ < div id = "App" className = "min-w-min" >
63
+ < header className = "sm:flex" >
63
64
< div
64
- id = "header-wrapper"
65
- className = "m-auto mt-7 flex flex-col w-full mx-6"
65
+ id = "header-container"
66
+ className = "h-76 bg-cover bg-bottom flex sm:w-full sm:h-64"
67
+ style = { { backgroundImage : `url(${ patternBg } )` } }
66
68
>
67
- < h1 className = "text-white text-2.5xl font-medium tracking-wide mx-auto mb-7" >
68
- IP Adress Tracker
69
- </ h1 >
70
69
< div
71
- id = "search-input-wrapper"
72
- className = "bg-white rounded-2xl w-full flex"
73
- >
74
- < input
75
- type = "search"
76
- className = "grow rounded-2xl px-6 text-lg"
77
- placeholder = "Search for any IP address or domain"
78
- value = { searchIP }
79
- onChange = { ( e ) => setSearchIP ( e . target . value ) }
80
- />
81
- < button className = "font-bold h-full bg-black text-white px-6 py-5.5 rounded-r-2xl text-xl" >
82
- < img src = { searchArrow } alt = "search arrow button" />
83
- </ button >
84
- </ div >
85
- < div
86
- id = "details-wrapper"
87
- className = "rounded-2xl flex bg-white mt-6 shadow-md"
88
- style = { { zIndex : 9999 } }
70
+ id = "header-wrapper"
71
+ className = "m-auto mt-7 flex flex-col w-full mx-6 sm:container sm:mx-auto"
89
72
>
73
+ < h1 className = "text-white text-2.5xl font-medium tracking-wide mx-auto mb-7 sm:text-3xl sm:mt-2.5" >
74
+ IP Adress Tracker
75
+ </ h1 >
76
+ < div
77
+ id = "search-input-wrapper"
78
+ className = "bg-white rounded-2xl w-full flex sm:w-128 sm:mx-auto"
79
+ >
80
+ < input
81
+ type = "search"
82
+ className = "grow rounded-2xl px-6 text-lg"
83
+ placeholder = "Search for any IP address or domain"
84
+ value = { searchIP }
85
+ onChange = { ( e ) => setSearchIP ( e . target . value ) }
86
+ />
87
+ < button className = "font-bold h-full bg-black text-white px-6 py-5.5 rounded-r-2xl text-xl" >
88
+ < img src = { searchArrow } alt = "search arrow button" />
89
+ </ button >
90
+ </ div >
91
+ < p className = "pt-1 text-center font-semibold text-white text-red-300" >
92
+ { errorMsg && `*${ errorMsg } ` }
93
+ </ p >
90
94
< div
91
- id = "details"
92
- className = "rounded-2xl bg-white p-7 flex flex-col mx-auto text-center gap-3.5 font-semibold text-very-dark-gray tracking-wide"
95
+ id = "details-wrapper"
96
+ className = "rounded-2xl flex bg-white mt-6 shadow-md sm:w-11/12 sm:mx-auto"
97
+ style = { { zIndex : 9999 } }
93
98
>
94
- < div id = "ip-address-wrapper" >
95
- < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
96
- IP ADDRESS
97
- </ h3 >
98
- < div className = "text-xl" id = "ip-address" >
99
- { ipData ?. ip || "Unknown" }
99
+ < div
100
+ id = "details"
101
+ className = "rounded-2xl bg-white p-7 flex flex-col mx-auto text-center gap-3.5 font-semibold text-very-dark-gray tracking-wide sm:flex-row sm:text-left sm:justify-between sm:w-full sm:m-1 sm:my-2"
102
+ >
103
+ < div id = "ip-address-wrapper" >
104
+ < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
105
+ IP ADDRESS
106
+ </ h3 >
107
+ < div className = "text-xl" id = "ip-address" >
108
+ { ipData ?. ip || "Unknown" }
109
+ </ div >
100
110
</ div >
101
- </ div >
102
- < div id = "location-wrapper" >
103
- < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
104
- LOCATION
105
- </ h3 >
106
- < div className = "text-xl" id = "location" >
107
- { `${ ipData ?. location ?. city || "" } ${
108
- ipData . location ?. country ? "," : ""
109
- } ${ ipData ?. location ?. country || "Unknown" } ${
110
- ipData ?. location ?. postalCode || ""
111
- } `}
111
+ < div
112
+ id = "location-wrapper"
113
+ className = "sm:border-l-2 sm:pl-6 sm:py-2"
114
+ >
115
+ < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
116
+ LOCATION
117
+ </ h3 >
118
+ < div className = "text-xl" id = "location" >
119
+ { `${ ipData ?. location ?. city || "" } ${
120
+ ipData . location ?. country ? "," : ""
121
+ } ${ ipData ?. location ?. country || "Unknown" } ${
122
+ ipData ?. location ?. postalCode || ""
123
+ } `}
124
+ </ div >
112
125
</ div >
113
- </ div >
114
- < div id = "timezone-wrapper" >
115
- < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
116
- TIMEZONE
117
- </ h3 >
118
- < div className = "text-xl" id = "timezone" >
119
- { ipData . location ?. timezone
120
- ? `UTC${ ipData . location . timezone } `
121
- : "Unknown" }
126
+ < div
127
+ id = "timezone-wrapper"
128
+ className = "sm:border-l-2 sm:pl-6 sm:py-2"
129
+ >
130
+ < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
131
+ TIMEZONE
132
+ </ h3 >
133
+ < div className = "text-xl" id = "timezone" >
134
+ { ipData . location ?. timezone
135
+ ? `UTC${ ipData . location . timezone } `
136
+ : "Unknown" }
137
+ </ div >
122
138
</ div >
123
- </ div >
124
- < div id = "isp-wrapper ">
125
- < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5" >
126
- ISP
127
- </ h3 >
128
- < div className = "text-xl" id = " isp" >
129
- { ipData . isp ? ipData . isp : "Unknown" }
139
+ < div id = "isp-wrapper" className = "sm:border-l-2 sm:pl-6 sm:py-2" >
140
+ < h3 className = "text-2xs text-dark-gray tracking-x-wide pb-1.5 ">
141
+ ISP
142
+ </ h3 >
143
+ < div className = "text-xl" id = "isp" >
144
+ { ipData . isp ? ipData . isp : "Unknown" }
145
+ </ div >
130
146
</ div >
131
147
</ div >
132
148
</ div >
0 commit comments