diff --git a/src/App.tsx b/src/App.tsx index c3ba803..609f33c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,12 +3,14 @@ import { Route, HashRouter } from "@solidjs/router"; import { Editor } from "./pages/Editor"; import { Index } from "./pages/Index"; import { Arrow } from "./pages/Arrow"; +import { IndexMobile } from "./pages/IndexMobile"; export default function() { return ( <> + diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 1c3f33c..137cc9a 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -10,6 +10,13 @@ export function Index() { const container =
; onMount(() => { + // Detect screen size and ratio, + // and redirect to mobile page if neccesary + if (window.matchMedia("only screen and (max-width: 760px)").matches) { + window.location.replace("/#/mobile"); + return; + } + global_map = L.map(container as HTMLElement) .setView([-16.40171, -71.53040], 13); diff --git a/src/pages/IndexMobile.tsx b/src/pages/IndexMobile.tsx index 09d755c..1721624 100644 --- a/src/pages/IndexMobile.tsx +++ b/src/pages/IndexMobile.tsx @@ -1,8 +1,154 @@ +import { createEffect, createResource, createSignal, For, onMount } from "solid-js"; +import L from "leaflet"; +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 IndexMobile() { + const container =
; + + onMount(() => { + // Detect screen size and ratio, + // and redirect to pc page if neccesary + if (!window.matchMedia("only screen and (max-width: 760px)").matches) { + window.location.replace("/#/"); + return; + } + + 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 (
- Mobile index :D + {container} +
); } + +function LinesContainer() { + const [selected_line, set_selected_line] = createSignal(-1); + const [linesData] = createResource(async() => { + const res = await fetch("/n/lines.json"); + if (!res.ok) throw new Error("Error fetching data"); + return res.json(); + }); + + return ( +
+
+ + {(line) => } + +
+
+ + {(line) => ( + set_selected_line(line.id)} + deactivate={() => set_selected_line(-1)} + selected={selected_line() === line.id} + /> + )} + +
+
+ ); +} + +function LineChip(props: { + line: Line, + selected: boolean, + activate: () => void, + deactivate: () => void, +}) { + const active_classes = () => (props.selected ? "bg-r-hover-bg text-r-hover-on-bg" : "text-r-hover-bg"); + return ( + + ); +} + +function RouteChipContainer(props: {line: Line, active_line: number}) { + 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(); + }); + + const container_classes = () => (props.active_line === props.line.id ? "inline-block" : "hidden"); + return ( +
+ + {(route) => } + +
+ ); +} + +function RouteChip(props: {route: Route, color: string}) { + const route = props.route; + const [active, set_active] = createSignal(false); + + // Create departure and return polylines + const departure_polyline = L.polyline(route.departure, { color: props.color }); + const return_polyline = L.polyline(route.return, { color: props.color }); + + // Render the lines into the map + // TODO: Change the UI to allow selecting departure and return separately + // and then update this + + createEffect(() => { + if (global_count() === 0 || active() === true) { + departure_polyline.addTo(global_map!); + return_polyline.addTo(global_map!); + } else { + departure_polyline.removeFrom(global_map!); + return_polyline.removeFrom(global_map!); + } + }); + + const toggle_active = () => { + if (active()) { + set_active(false); + set_global_count((c) => c - 1); + } else { + set_active(true); + set_global_count((c) => c + 1); + } + }; + + const active_classes = () => (active() === true ? "bg-r-hover-bg text-r-hover-on-bg" : "bg-white text-r-hover-bg"); + return ( + + ); +} +