File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Hacktoberfest Projects 🎉
2
2
3
- A Web app that lets you find eligible repositories for Hacktoberfest 2022!
3
+
4
+ A Web app that lets you find eligible repositories for Hacktoberfest!
4
5
5
6
Use it here - https://finder.usmans.me
6
7
Original file line number Diff line number Diff line change 1
- import { FormEventHandler } from 'react' ;
1
+ import { FormEventHandler , useState } from 'react' ;
2
2
import Link from 'next/link' ;
3
3
4
4
import languages from 'assets/languages.json' ;
@@ -10,11 +10,19 @@ import Button from './Button';
10
10
const { main : mainLanguages , others : otherLanguages } = languages ;
11
11
12
12
function Hero ( ) {
13
+ const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
13
14
const router = useRouter ( ) ;
14
15
const handleSubmit : FormEventHandler = e => {
15
16
e . preventDefault ( ) ;
16
17
const formData = new FormData ( e . target as HTMLFormElement ) ;
17
- const search = formData . get ( 'search' ) ;
18
+ const search = ( formData . get ( 'search' ) as string ) . trim ( ) ;
19
+ // Check if the input is empty or contains only spaces
20
+ if ( search === '' ) {
21
+ setErrorMessage ( 'Empty search terms invalid!' ) ;
22
+ return ;
23
+ }
24
+ // Clear any previous error message & proceed to search
25
+ setErrorMessage ( null ) ;
18
26
router . push ( `/repos/${ search } ` ) ;
19
27
} ;
20
28
return (
Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ export default function Search({ searchBarWrapperStyles }: SearchProps) {
19
19
} ) ;
20
20
21
21
const onSubmit : SubmitHandler < FormValues > = ( { searchQuery } ) => {
22
- router . push ( { query : { ...router . query , q : searchQuery } } ) ;
22
+ let trimmedQuery = searchQuery . trim ( ) ;
23
+ //Performs search only with non-empty strings
24
+ if ( trimmedQuery !== '' ) {
25
+ router . push ( { query : { ...router . query , q : trimmedQuery } } ) ;
26
+ }
23
27
} ;
24
28
25
29
return (
@@ -40,7 +44,7 @@ export default function Search({ searchBarWrapperStyles }: SearchProps) {
40
44
type = "button"
41
45
onClick = { ( ) => reset ( ) }
42
46
>
43
- < GoX color = "lightgrey " />
47
+ < GoX color = "white " />
44
48
</ button >
45
49
</ div >
46
50
</ form >
You can’t perform that action at this time.
0 commit comments