UNPKG

select-previsao-ondas

Version:

Componente que busca a previsão de ondas por praias

56 lines (49 loc) 2.12 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-ecb13329.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) { index.registerInstance(this, hostRef); this.estados = []; this.cidades = []; this.previsoes = []; this.previsaoOndasService = new PrevisaoOndasService(); this.change = index.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 (index.h("div", null, index.h("select", { onInput: event => this.handleSelectEstado(event) }, this.estados.map(item => (index.h("option", { value: item.abreviatura }, item.abreviatura)))), this.cidades.length ? (index.h("select", { onInput: event => this.handleSelectCidade(event) }, this.cidades.map(item => (index.h("option", { value: item.id }, item.cidade))))) : null)); } }; SelectPrevisaoOndasComponent.style = selectPrevisaoOndasCss; exports.select_previsao_ondas = SelectPrevisaoOndasComponent;