Compare commits

..

4 Commits

Author SHA1 Message Date
b15207d18d final fix 2024-10-17 20:29:22 +02:00
7468d74b92 hotfix 2024-10-17 20:26:00 +02:00
d6fe70b38e hotfix 2024-10-17 20:23:49 +02:00
5405e93d27 Comentarios 2024-10-17 20:23:10 +02:00
11 changed files with 76 additions and 32 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -1,3 +1,6 @@
/**
* Respuesta de Oracle DB
*/
export default interface ApiResponse<T> {
items: T[];
hasMore: boolean;

View File

@ -1,3 +1,6 @@
/**
* Datos del embalse
*/
export default interface Embalse {
id: number
ambito_nombre: string

View File

@ -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
}

View File

@ -1,3 +1,5 @@
@charset 'utf8';
// TODO: MODULAR
@forward 'bulma/sass';

View File

@ -1,3 +1,5 @@
/** Spinner */
.loader {
width: 48px;
height: 48px;

View File

@ -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 {

View File

@ -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";

View File

@ -17,27 +17,17 @@ 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">
<FaSolidGlassWaterDroplet />
</span>
<span>Malackathon</span>
</span>
</p>
<div class="buttons">
<A class="button is-primary" href="/embalses">Todos los embalses</A>
<A class="button is-primary" href="/embalses/nearby">Buscar</A>
</div>
</div>
<p class="title">
<span class="icon-text">
<span class="icon">
<FaSolidGlassWaterDroplet />
</span>
<span>Malackathon</span>
</span>
</p>
<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>
</div>
</div>

View File

@ -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">
<div id="map" style={{
height: '70vh'
}}></div>
</div>
<>
<Navbar />
<div class="container has-text-centered">
<div id="map" style={{
height: '70vh'
}}></div>
</div>
</>
);
}