-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventListeners.js
32 lines (27 loc) · 1016 Bytes
/
eventListeners.js
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
import {recivesData} from "./Requests.js";
import {formatString} from "./dataTreatment.js"
import { creatingCards } from "./Components/card.js";
import { creatingHeader } from "./Components/header.js";
import { returnsState } from "./Components/allTheCities.js";
const cityStr = (value)=>{
if (value === 'rj' || value ==='RJ') return 'rio-de-janeiro'
else if (value === 'sp'|| value ==='SP') return 'sao-paulo'
else return formatString(value)
}
const eventBlur = () =>{
const input = document.querySelector('#search')
input.addEventListener('blur',async (evt)=>{
evt.preventDefault()
const city = cityStr(evt.target.value)
const state = returnsState(city)
const result = await recivesData(state,city)
const insertDiv = document.querySelector("#insertCards")
const checkIfAlreadyExists = document.querySelectorAll(".card")
if (result) {
insertDiv.innerHTML = ""
}
creatingHeader(result)
creatingCards(result)
} )
}
export {eventBlur};