Compare commits
4 Commits
b24b59f619
...
master
Author | SHA1 | Date | |
---|---|---|---|
b15207d18d | |||
7468d74b92 | |||
d6fe70b38e | |||
5405e93d27 |
@ -2,20 +2,42 @@ import ApiResponse from "../interfaces/ApiResponse";
|
||||
import Embalse from "../interfaces/Embalse";
|
||||
import Env from "./Env";
|
||||
|
||||
/**
|
||||
* Wrapper API de la REST de Oracle DB
|
||||
*/
|
||||
export default class Api {
|
||||
/**
|
||||
* Conseguir todos los embalses
|
||||
*/
|
||||
static async embalses(): Promise<Embalse[]> {
|
||||
return Api._makeReq('/embalses');
|
||||
}
|
||||
|
||||
/**
|
||||
* Conseguir embalse a partir de su id
|
||||
* @param id ID del embalse
|
||||
* @returns Lista de embalses que coinciden con la búsqueda
|
||||
*/
|
||||
static async embalseById(id: string): Promise<Embalse[]> {
|
||||
return Api._makeReq(`/embalses/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conseguir todos los embalses cercanos
|
||||
* @param lat Latitud
|
||||
* @param lon Longitud
|
||||
* @returns Lista de embalses cercanos
|
||||
*/
|
||||
static async embalsesNearby(lat: string, lon: string): Promise<Embalse[]> {
|
||||
return Api._makeReq(`/embalsesCercanos/${lat}/${lon}`);
|
||||
}
|
||||
|
||||
static async _makeReq<T>(endpoint: string): Promise<T[]> {
|
||||
/**
|
||||
* Método privado para enviar solicitudes
|
||||
* @param endpoint Endpoint requerido
|
||||
* @returns Lista de elementos
|
||||
*/
|
||||
private static async _makeReq<T>(endpoint: string): Promise<T[]> {
|
||||
let hasMore = true;
|
||||
|
||||
let url = Env.api_base() + endpoint;
|
||||
|
@ -1,5 +1,18 @@
|
||||
/**
|
||||
* Helper para conseguir las variables del entorno
|
||||
*/
|
||||
export default class Env {
|
||||
/**
|
||||
* Base de API
|
||||
*/
|
||||
static api_base(): string {
|
||||
return import.meta.env.VITE_API_BASE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clave API de OpenWeatherMap
|
||||
*/
|
||||
static owm_key(): string {
|
||||
return import.meta.env.VITE_OWM_KEY;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Respuesta de Oracle DB
|
||||
*/
|
||||
export default interface ApiResponse<T> {
|
||||
items: T[];
|
||||
hasMore: boolean;
|
||||
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Datos del embalse
|
||||
*/
|
||||
export default interface Embalse {
|
||||
id: number
|
||||
ambito_nombre: string
|
||||
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Respuesta de la API OpenWeatherMap
|
||||
*/
|
||||
export default interface OWMResponse {
|
||||
cod: string
|
||||
message: number
|
||||
@ -32,7 +35,7 @@ export interface Main {
|
||||
|
||||
export interface Weather {
|
||||
id: number
|
||||
main: string
|
||||
main: Main
|
||||
description: string
|
||||
icon: string
|
||||
}
|
||||
|
2
src/styles/bulma.scss
vendored
2
src/styles/bulma.scss
vendored
@ -1,3 +1,5 @@
|
||||
@charset 'utf8';
|
||||
|
||||
// TODO: MODULAR
|
||||
|
||||
@forward 'bulma/sass';
|
||||
|
@ -1,3 +1,5 @@
|
||||
/** Spinner */
|
||||
|
||||
.loader {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
|
@ -5,7 +5,7 @@ import Navbar from "../partials/Navbar";
|
||||
import Loader from "../partials/Loader";
|
||||
import Api from "../helpers/Api";
|
||||
import Card from "../partials/Card";
|
||||
import { FaSolidLocationDot, FaSolidMapLocationDot, FaSolidWater } from "solid-icons/fa";
|
||||
import { FaSolidCircleInfo, FaSolidLocationDot, FaSolidMapLocationDot, FaSolidWater } from "solid-icons/fa";
|
||||
import OpenWeather from "../helpers/OpenWeather";
|
||||
|
||||
interface CustomParams extends Params {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createSignal, onCleanup, onMount } from "solid-js";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
import L, { Icon } from 'leaflet';
|
||||
import L from 'leaflet';
|
||||
import { FaSolidLocationPin } from "solid-icons/fa";
|
||||
import Navbar from "../partials/Navbar";
|
||||
import Api from "../helpers/Api";
|
||||
|
@ -17,14 +17,6 @@ function Home() {
|
||||
<div class="columns is-centered">
|
||||
<div class="column is-half">
|
||||
<div class="box">
|
||||
<div class="columns is-centered is-vcentered is-mobile">
|
||||
<div class="column is-4">
|
||||
<figure class="image is-128x128">
|
||||
{/* TODO: Agregar icono */}
|
||||
<img src="https://bulma.io/assets/images/placeholders/128x128.png" />
|
||||
</figure>
|
||||
</div>
|
||||
<div class="column is-8">
|
||||
<p class="title">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
@ -33,7 +25,7 @@ function Home() {
|
||||
<span>Malackathon</span>
|
||||
</span>
|
||||
</p>
|
||||
<div class="buttons">
|
||||
<div class="buttons is-centered">
|
||||
<A class="button is-primary" href="/embalses">Todos los embalses</A>
|
||||
<A class="button is-primary" href="/embalses/nearby">Buscar</A>
|
||||
</div>
|
||||
@ -42,8 +34,6 @@ function Home() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="section">
|
||||
<p>TODO: Agregar tarjetitas guapas</p>
|
||||
|
@ -2,8 +2,11 @@ import { onMount } from "solid-js";
|
||||
import L from 'leaflet';
|
||||
import Embalse from "../interfaces/Embalse";
|
||||
import Api from "../helpers/Api";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
import Navbar from "../partials/Navbar";
|
||||
|
||||
function Viewer() {
|
||||
const navigate = useNavigate();
|
||||
let map: L.Map;
|
||||
|
||||
let embalses: Embalse[] = [];
|
||||
@ -21,17 +24,20 @@ function Viewer() {
|
||||
const getEmbalses = async () => {
|
||||
embalses = await Api.embalses();
|
||||
|
||||
embalses.forEach(embalse => {
|
||||
L.marker([parseFloat(embalse.x), parseFloat(embalse.y)]).addTo(map);
|
||||
embalses.forEach(c => {
|
||||
L.marker([parseFloat(c.x), parseFloat(c.y)]).on('click', () => navigate('/embalses/' + c.id)).addTo(map);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="container">
|
||||
<>
|
||||
<Navbar />
|
||||
<div class="container has-text-centered">
|
||||
<div id="map" style={{
|
||||
height: '70vh'
|
||||
}}></div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user