1- import { useState , useContext , useRef } from "react" ;
1+ import { useContext } from "react" ;
22import UserContext from "../../Hooks/userContext" ;
33import { useNavigate } from "react-router-dom" ;
44import styled from "styled-components" ;
5- import { IconCircle , IconClose , IconSearch } from "../../assets/SVG" ;
5+ import { IconCircle , IconSearch } from "../../assets/SVG" ;
66import { Flex } from "../Styles/Flexbox" ;
77
88const Hero = ( ) => {
9- const { setUsername } = useContext ( UserContext ) ;
9+ const { username , setUsername } = useContext ( UserContext ) ;
1010
11- const [ isActive , setIsActive ] = useState ( false ) ;
1211 const handleChange = ( e ) => setUsername ( e . target . value ) ;
1312 const navigate = useNavigate ( ) ;
14- const ref = useRef ( null ) ;
1513
16- const handleClick = ( ) => {
17- ref . current . focus ( ) ;
18- setIsActive ( ! isActive ) ;
19- } ;
14+ const handleSubmit = event => {
15+ event . preventDefault ( ) ;
16+ if ( username ) {
17+ return navigate ( "/dashboard" ) ;
18+ }
19+ }
2020
2121 return (
2222 < StyledHero >
2323 < Flex alignCenter justifyEnd flexColumn >
2424 < h1 > Find Your Github Profile</ h1 >
2525 < form
26- className = { isActive ? "active" : "" }
27- onSubmit = { ( e ) => {
28- e . preventDefault ( ) ;
29- navigate ( "/dashboard" ) ;
30- } }
31- >
26+ onSubmit = { handleSubmit } >
3227 < input
33- ref = { ref }
3428 name = "username"
3529 placeholder = ":search username"
3630 type = "text"
@@ -39,9 +33,7 @@ const Hero = () => {
3933 </ form >
4034 </ Flex >
4135 < StyledCircleButton >
42- < button className = { isActive ? "active" : null } onClick = { handleClick } >
43- { ! isActive ? < IconSearch /> : < IconClose /> }
44- </ button >
36+ < button onClick = { handleSubmit } > < IconSearch /> </ button >
4537 < IconCircle />
4638 < h2 > A simple yet creative way to interact with your GitHub profile.</ h2 >
4739 < p > Scroll Down</ p >
@@ -57,22 +49,14 @@ export default Hero;
5749const StyledHero = styled . section `
5850 position: relative;
5951 text-align: center;
60- height: 100%;
61- min-height: 100vh;
52+ padding-top: 30vh;
6253 & > *:first-child {
63- position: relative;
6454 margin-inline: auto;
6555 width: min(600px, 100%);
66- padding-block: 22rem 2rem;
56+ padding-bottom: 2rem;
6757 & form {
6858 width: 100%;
69- margin-block-end: -6rem;
70- opacity: 0;
7159 transition: ${ ( { theme } ) => theme . transPrime } ;
72- &.active {
73- margin-block-end: -1rem;
74- opacity: 1;
75- }
7660 & input {
7761 display: block;
7862 border: 0;
0 commit comments