From b836e5e8eb4d5951e33465bc1ea674699a96fce0 Mon Sep 17 00:00:00 2001 From: Araozu Date: Mon, 9 Sep 2024 15:15:52 -0500 Subject: [PATCH] Remove previous index. Create a new page for mobile users --- src/App.tsx | 4 +- src/pages/Index.tsx | 210 +++++++++++++++++++++++--------- src/pages/Index2.tsx | 245 -------------------------------------- src/pages/IndexMobile.tsx | 8 ++ 4 files changed, 163 insertions(+), 304 deletions(-) delete mode 100644 src/pages/Index2.tsx create mode 100644 src/pages/IndexMobile.tsx diff --git a/src/App.tsx b/src/App.tsx index 3d63f4c..c3ba803 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,7 @@ import "leaflet/dist/leaflet.css"; -import { Index } from "./pages/Index"; import { Route, HashRouter } from "@solidjs/router"; import { Editor } from "./pages/Editor"; -import { Index2 } from "./pages/Index2"; +import { Index } from "./pages/Index"; import { Arrow } from "./pages/Arrow"; export default function() { @@ -10,7 +9,6 @@ export default function() { <> - diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 9c5d18b..1c3f33c 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -1,39 +1,38 @@ -import { Map, map, polyline, tileLayer } from "leaflet"; -import { createEffect, createResource, For, onMount, Suspense } from "solid-js"; -import { Line, RouteWrapper, Route, LineWrapper, PointsWrapper } from "../types"; +import L from "leaflet"; +import { createEffect, createResource, createSignal, For, onMount, Suspense } from "solid-js"; import { LineSegmentsIcon } from "../icons/LineSegmentsIcon"; +import { Line, Lines, Route, Routes } from "../new_types"; -let g_map: Map | null = null; +let global_map: L.Map | null = null; +const [global_count, set_global_count] = createSignal(0); export function Index() { - const container =
; + const container =
; onMount(() => { - const l_map = map(container as HTMLElement) + global_map = L.map(container as HTMLElement) .setView([-16.40171, -71.53040], 13); - g_map = l_map; - tileLayer("/tiles/{z}/{x}/{y}.jpg", { + L.tileLayer("/tiles/{z}/{x}/{y}.jpg", { maxZoom: 17, minZoom: 12, - attribution: "© Map data OpenStreetMap", - }).addTo(l_map); + attribution: "Map data © OpenStreetMap", + }).addTo(global_map); }); return ( -
-
+
+

AQP combi

Lineas

- - +
-
-
+
{container} @@ -43,18 +42,17 @@ export function Index() { ); } -function Lines() { - const [lineData] = createResource(async() => { - const res = await fetch("/data/root.json"); +function LinesEl() { + const [linesData] = createResource(async() => { + const res = await fetch("/n/lines.json"); if (!res.ok) throw new Error("Error fetching data"); return res.json(); }); - return ( <> Cargando...
}> - + {(l) => } @@ -63,61 +61,161 @@ function Lines() { } function LineEl(props: { line: Line }) { - const [lineRoute] = createResource(async() => { - const res = await fetch(`/data/cuenca_${props.line.id_cuenca}.json`); + const [routesData] = createResource(async() => { + const res = await fetch(`/n/routes_${props.line.id}.json`); if (!res.ok) throw new Error("Error fetching data"); return res.json(); }); return ( -
+
- - Linea {props.line.name ?? "A"} + + Linea {props.line.name} - - {(r) => } + + {(r) => ( + + )}
); } -function RouteEl(props: { route: Route, parent_id: number, color: string }) { - const [points] = createResource(async() => { - const res = await fetch(`/data/cuenca_${props.parent_id}_ruta_${props.route.id_ruta}_ida.json`); - if (!res.ok) throw new Error("Error fetching data"); - return res.json(); - }); - const [return_points] = createResource(async() => { - const res = await fetch(`/data/cuenca_${props.parent_id}_ruta_${props.route.id_ruta}_vuelta.json`); - if (!res.ok) throw new Error("Error fetching data"); - return res.json(); - }); +function RouteEl(props: { + line_name: string, + route: Route, + color: string, +}) { + const [departure_active, set_departure_active] = createSignal(false); + const [return_active, set_return_active] = createSignal(false); + const [departure_count, set_departure_count] = createSignal(0); + const [return_count, set_return_count] = createSignal(0); + // Create departure and return polylines + const departure_polyline = L.polyline(props.route.departure, { color: props.color }); + const return_polyline = L.polyline(props.route.return, { color: props.color }); + + // Rended the lines into the map createEffect(() => { - // Render the dots into the map - if (!points()) return; - const coords = points()!.data[0]!.ruta_json; - - const line = polyline(coords, { color: props.color}); - line.addTo(g_map!); + if (global_count() === 0 || departure_count() > 0) { + departure_polyline.addTo(global_map!); + } else { + departure_polyline.removeFrom(global_map!); + } }); - createEffect(() => { - // Render the dots into the map - const coords = return_points()!.data[0]!.ruta_json; - - const line = polyline(coords, { color: props.color}); - line.addTo(g_map!); + // if global count === 0, then no route is focused. + // in that case, all routes should be rendered + if (global_count() === 0 || return_count() > 0) { + return_polyline.addTo(global_map!); + } else { + return_polyline.removeFrom(global_map!); + } }); + const toggle_departure = () => { + const currently_active = departure_active(); + if (currently_active) { + set_global_count((c) => c - 1); + set_departure_count((c) => c - 1); + set_departure_active(false); + } else { + set_global_count((c) => c + 1); + set_departure_count((c) => c + 1); + set_departure_active(true); + } + }; + const toggle_return = () => { + const currently_active = return_active(); + if (currently_active) { + set_global_count((c) => c - 1); + set_return_count((c) => c - 1); + set_return_active(false); + } else { + set_global_count((c) => c + 1); + set_return_count((c) => c + 1); + set_return_active(true); + } + }; + + const departure_classes = () => { + if (departure_count() > 0) { + return "bg-r-hover-bg text-r-hover-on-bg"; + } else { + return ""; + } + }; + const return_classes = () => { + if (return_count() > 0) { + return "bg-r-hover-bg text-r-hover-on-bg"; + } else { + return ""; + } + }; return ( -
- Ruta {props.route.cod_ruta} -
+ ); } - - diff --git a/src/pages/Index2.tsx b/src/pages/Index2.tsx deleted file mode 100644 index ebd2aa9..0000000 --- a/src/pages/Index2.tsx +++ /dev/null @@ -1,245 +0,0 @@ -import L from "leaflet"; -import { createEffect, createResource, createSignal, For, onMount, Suspense } from "solid-js"; -import { LineSegmentsIcon } from "../icons/LineSegmentsIcon"; -import { Line, Lines, Route, Routes } from "../new_types"; - -let global_map: L.Map | null = null; -const [global_count, set_global_count] = createSignal(0); - -export function Index2() { - const container =
; - - onMount(() => { - global_map = L.map(container as HTMLElement) - .setView([-16.40171, -71.53040], 13); - - L.tileLayer("/tiles/{z}/{x}/{y}.jpg", { - maxZoom: 17, - minZoom: 12, - attribution: "Map data © OpenStreetMap", - }).addTo(global_map); - }); - - return ( -
-
-

AQP combi

- - - - -
-
-
- {container} -
-
-
- ); -} - -function LinesEl() { - const [linesData] = createResource(async() => { - const res = await fetch("/n/lines.json"); - if (!res.ok) throw new Error("Error fetching data"); - return res.json(); - }); - - return ( - <> - Cargando...
}> - - {(l) => } - - - - ); -} - -function LineEl(props: { line: Line }) { - const [routesData] = createResource(async() => { - const res = await fetch(`/n/routes_${props.line.id}.json`); - if (!res.ok) throw new Error("Error fetching data"); - return res.json(); - }); - - return ( -
-
-
-
- - - {(r) => ( - - )} - - -
-
- ); -} - -function RouteEl(props: { - line_name: string, - route: Route, - color: string, -}) { - const [departure_active, set_departure_active] = createSignal(false); - const [return_active, set_return_active] = createSignal(false); - const [departure_count, set_departure_count] = createSignal(0); - const [return_count, set_return_count] = createSignal(0); - - // Create departure and return polylines - const departure_polyline = L.polyline(props.route.departure, { color: props.color }); - const return_polyline = L.polyline(props.route.return, { color: props.color }); - - // Rended the lines into the map - createEffect(() => { - if (global_count() === 0 || departure_count() > 0) { - departure_polyline.addTo(global_map!); - } else { - departure_polyline.removeFrom(global_map!); - } - }); - createEffect(() => { - // if global count === 0, then no route is focused. - // in that case, all routes should be rendered - if (global_count() === 0 || return_count() > 0) { - return_polyline.addTo(global_map!); - } else { - return_polyline.removeFrom(global_map!); - } - }); - - const toggle_departure = () => { - const currently_active = departure_active(); - if (currently_active) { - set_global_count((c) => c - 1); - set_departure_count((c) => c - 1); - set_departure_active(false); - } else { - set_global_count((c) => c + 1); - set_departure_count((c) => c + 1); - set_departure_active(true); - } - }; - const toggle_return = () => { - const currently_active = return_active(); - if (currently_active) { - set_global_count((c) => c - 1); - set_return_count((c) => c - 1); - set_return_active(false); - } else { - set_global_count((c) => c + 1); - set_return_count((c) => c + 1); - set_return_active(true); - } - }; - - const both_classes = () => { - if (departure_active() && return_active()) { - return "bg-r-hover-bg text-r-hover-on-bg"; - } else { - return ""; - } - }; - const departure_classes = () => { - if (departure_count() > 0) { - return "bg-r-hover-bg text-r-hover-on-bg"; - } else { - return ""; - } - }; - const return_classes = () => { - if (return_count() > 0) { - return "bg-r-hover-bg text-r-hover-on-bg"; - } else { - return ""; - } - }; - return ( - - ); -} diff --git a/src/pages/IndexMobile.tsx b/src/pages/IndexMobile.tsx new file mode 100644 index 0000000..09d755c --- /dev/null +++ b/src/pages/IndexMobile.tsx @@ -0,0 +1,8 @@ + +export function IndexMobile() { + return ( +
+ Mobile index :D +
+ ); +}