-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (64 loc) · 1.92 KB
/
index.js
File metadata and controls
73 lines (64 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from "react"
import { useLocation } from "wouter"
import useForm from './hook'
import css from "./SearchForm.module.css"
import Button from 'components/Button'
const RATINGS = ["g", "pg", "pg-13", "r"]
const LANGS = ["es", "en", "it", "pr"]
export default function SearchForm ({
initialKeyword = '',
initialRating = RATINGS[0],
initialLang = LANGS[0],
}) {
const [_, pushLocation] = useLocation()
const { keyword, rating, lang, changeKeyword, changeRating, changeLang } = useForm({ initialKeyword, initialRating, initialLang })
const onSubmit = ({ keyword }) => {
if (keyword !== '') {
// navegar a otra ruta
pushLocation(`/search/${keyword}/${rating}/${lang}`)
}
}
const handleChange = (evt) => {
changeKeyword({ keyword: evt.target.value })
}
const handleSubmit = (evt) => {
evt.preventDefault()
onSubmit({ keyword })
}
const handleChangeRating = (evt) => {
changeRating({ rating: evt.target.value })
}
const handleChangeLang = (evt) => {
changeLang({ lang: evt.target.value })
}
return (
<>
<form onSubmit={handleSubmit} className={css["c-search"]}>
<Button>Buscar</Button>
<input
className={css["c-search-input"]}
placeholder="Search a gif here..."
onChange={handleChange}
type="text"
value={keyword}
/>
<select className={css["c-search-list"]} value={rating} onChange={handleChangeRating}>
<option disabled>
Rating:
</option>
{RATINGS.map((rating) => (
<option key={rating}>{rating}</option>
))}
</select>
<select className={css["c-search-list"]} value={lang} onChange={handleChangeLang}>
<option disabled>
Lang:
</option>
{LANGS.map((lang) => (
<option key={lang}>{lang}</option>
))}
</select>
</form>
</>
)
}