UNPKG

select-previsao-ondas

Version:

Componente que busca a previsão de ondas por praias

52 lines (47 loc) 2.04 kB
import { r as registerInstance, c as createEvent, h } from './index-72ad3407.js'; class PrevisaoOndasService { constructor() { this.url = "https://previsao-ondas.herokuapp.com"; } async getEstados() { const response = await fetch(`${this.url}/litoral/estados`); const data = await response.json(); return data.estados; } async getCidades(estado) { const response = await fetch(`${this.url}/litoral/estado/${estado}`); const data = await response.json(); return data.estado.cidades; } async getPrevisoes(cidade) { const response = await fetch(`${this.url}/onda/cidade/${cidade}`); const data = await response.json(); return data.dias; } } const selectPrevisaoOndasCss = ""; const SelectPrevisaoOndasComponent = class { constructor(hostRef) { registerInstance(this, hostRef); this.estados = []; this.cidades = []; this.previsoes = []; this.previsaoOndasService = new PrevisaoOndasService(); this.change = createEvent(this, "change", 7); } async componentWillLoad() { this.estados = await this.previsaoOndasService.getEstados(); } async handleSelectEstado(event) { this.cidades = await this.previsaoOndasService.getCidades(event.target.value); } async handleSelectCidade(event) { this.previsoes = await this.previsaoOndasService.getPrevisoes(event.target.value); this.change.emit(this.previsoes); } render() { return (h("div", null, h("select", { onInput: event => this.handleSelectEstado(event) }, this.estados.map(item => (h("option", { value: item.abreviatura }, item.abreviatura)))), this.cidades.length ? (h("select", { onInput: event => this.handleSelectCidade(event) }, this.cidades.map(item => (h("option", { value: item.id }, item.cidade))))) : null)); } }; SelectPrevisaoOndasComponent.style = selectPrevisaoOndasCss; export { SelectPrevisaoOndasComponent as select_previsao_ondas };