select-previsao-ondas
Version:
Componente que busca a previsão de ondas por praias
1 lines • 1.24 kB
JavaScript
import{r as t,c as s,h as a}from"./p-2acdf2a6.js";class i{constructor(){this.url="https://previsao-ondas.herokuapp.com"}async getEstados(){const t=await fetch(`${this.url}/litoral/estados`);return(await t.json()).estados}async getCidades(t){const s=await fetch(`${this.url}/litoral/estado/${t}`);return(await s.json()).estado.cidades}async getPrevisoes(t){const s=await fetch(`${this.url}/onda/cidade/${t}`);return(await s.json()).dias}}const e=class{constructor(a){t(this,a),this.estados=[],this.cidades=[],this.previsoes=[],this.previsaoOndasService=new i,this.change=s(this,"change",7)}async componentWillLoad(){this.estados=await this.previsaoOndasService.getEstados()}async handleSelectEstado(t){this.cidades=await this.previsaoOndasService.getCidades(t.target.value)}async handleSelectCidade(t){this.previsoes=await this.previsaoOndasService.getPrevisoes(t.target.value),this.change.emit(this.previsoes)}render(){return a("div",null,a("select",{onInput:t=>this.handleSelectEstado(t)},this.estados.map(t=>a("option",{value:t.abreviatura},t.abreviatura))),this.cidades.length?a("select",{onInput:t=>this.handleSelectCidade(t)},this.cidades.map(t=>a("option",{value:t.id},t.cidade))):null)}};e.style="";export{e as select_previsao_ondas}