🚨 Make ts linter less depressed
This commit is contained in:
@@ -7,11 +7,11 @@ import { Passages, Stops } from './types';
|
|||||||
interface Store {
|
interface Store {
|
||||||
passages: () => Passages;
|
passages: () => Passages;
|
||||||
getLinePassages?: (lineId: string) => Passages;
|
getLinePassages?: (lineId: string) => Passages;
|
||||||
addPassages?: (passages) => void;
|
addPassages?: (passages: Passages) => void;
|
||||||
clearPassages?: () => void;
|
clearPassages?: () => void;
|
||||||
|
|
||||||
stops: () => Stops;
|
stops: () => Stops;
|
||||||
addStops?: (stops) => void;
|
addStops?: (stops: Stops) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BusinessDataContext = createContext<Store>();
|
export const BusinessDataContext = createContext<Store>();
|
||||||
@@ -22,7 +22,7 @@ export function BusinessDataProvider(props: { children: JSX.Element }) {
|
|||||||
|
|
||||||
const [store, setStore] = createStore({ lines: {}, passages: {}, stops: {} });
|
const [store, setStore] = createStore({ lines: {}, passages: {}, stops: {} });
|
||||||
|
|
||||||
async function getLine(lineId: number) {
|
const getLine: Line = async (lineId: string) => {
|
||||||
let line = store.lines[lineId];
|
let line = store.lines[lineId];
|
||||||
if (line === undefined) {
|
if (line === undefined) {
|
||||||
console.log(`${lineId} not found... fetch it from backend.`);
|
console.log(`${lineId} not found... fetch it from backend.`);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, createEffect, createSignal, useContext } from "solid-js";
|
import { Component, createEffect, createResource, createSignal, useContext } from "solid-js";
|
||||||
import { createStore } from "solid-js/store";
|
import { createStore } from "solid-js/store";
|
||||||
import { createDateNow } from "@solid-primitives/date";
|
import { createDateNow } from "@solid-primitives/date";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
import { batch, createContext, createSignal } from 'solid-js';
|
import { batch, createContext } from 'solid-js';
|
||||||
import { createStore } from 'solid-js/store';
|
import { createStore } from 'solid-js/store';
|
||||||
|
|
||||||
import { Stop, Stops } from './types';
|
import { Stop, Stops } from './types';
|
||||||
|
|
||||||
|
|
||||||
interface Store {
|
interface Store {
|
||||||
getMarkers: () => Markers;
|
getMarkers: () => Markers;
|
||||||
addMarkers?: (stopId, markers) => void;
|
addMarkers?: (stopId, markers) => void;
|
||||||
setMarkers?: (markers) => void;
|
setMarkers?: (markers) => void;
|
||||||
|
|
||||||
getStops: () => Stops;
|
getStops: () => Stops;
|
||||||
setStops?: (stops) => void;
|
setStops?: (stops) => void;
|
||||||
removeStops?: (stopIds) => void;
|
removeStops?: (stopIds: Array<number>) => void;
|
||||||
|
|
||||||
getDisplayedStop: () => Stop;
|
getDisplayedStops: () => Array<Stop>;
|
||||||
setDisplayedStop: (stop: Stop) => void;
|
setDisplayedStops: (stops: Array<Stop>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SearchContext = createContext<Store>();
|
export const SearchContext = createContext<Store>();
|
||||||
|
@@ -1,15 +1,13 @@
|
|||||||
import { batch, Component, createEffect, createResource, createSignal, onMount, Show, useContext } from 'solid-js';
|
import { Component, createEffect, createResource, createSignal, onMount, Show, useContext } from 'solid-js';
|
||||||
|
|
||||||
import {
|
import { Box, Button, Input, InputLeftAddon, InputGroup, HStack, List, ListItem, Progress, ProgressIndicator, VStack } from "@hope-ui/solid";
|
||||||
Box, Button, Input, InputLeftAddon, InputGroup, HStack, List, ListItem, Progress,
|
|
||||||
ProgressIndicator, VStack
|
|
||||||
} from "@hope-ui/solid";
|
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import L from 'leaflet';
|
import L from 'leaflet';
|
||||||
|
|
||||||
import { BusinessDataContext } from './businessData';
|
import { BusinessDataContext } from './businessData';
|
||||||
import { SearchContext } from './search';
|
import { SearchContext } from './search';
|
||||||
|
|
||||||
|
import { Stop } from './types';
|
||||||
import { renderLineTransportMode, renderLinePicto, TransportModeWeights } from './utils';
|
import { renderLineTransportMode, renderLinePicto, TransportModeWeights } from './utils';
|
||||||
|
|
||||||
import styles from './stopManager.module.css';
|
import styles from './stopManager.module.css';
|
||||||
@@ -21,7 +19,7 @@ const StopRepr: Component = (props) => {
|
|||||||
|
|
||||||
const [lineReprs] = createResource(props.stop.lines, fetchLinesRepr);
|
const [lineReprs] = createResource(props.stop.lines, fetchLinesRepr);
|
||||||
|
|
||||||
async function fetchLinesRepr(lineIds) {
|
const fetchLinesRepr = async (lineIds: Array<string>) => {
|
||||||
const reprs = [];
|
const reprs = [];
|
||||||
for (const lineId of lineIds) {
|
for (const lineId of lineIds) {
|
||||||
const line = await getLine(lineId);
|
const line = await getLine(lineId);
|
||||||
@@ -100,7 +98,7 @@ const Map: Component = (props) => {
|
|||||||
let map = null;
|
let map = null;
|
||||||
const stopsLayerGroup = L.featureGroup();
|
const stopsLayerGroup = L.featureGroup();
|
||||||
|
|
||||||
function buildMap(div: HTMLDivElement) {
|
const buildMap = (div: HTMLDivElement) => {
|
||||||
map = L.map(div).setView(mapCenter, 11);
|
map = L.map(div).setView(mapCenter, 11);
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
@@ -108,7 +106,7 @@ const Map: Component = (props) => {
|
|||||||
stopsLayerGroup.addTo(map);
|
stopsLayerGroup.addTo(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMarker(stop) {
|
const setMarker = (stop: Stop): Array<L.Marker> => {
|
||||||
const markers = [];
|
const markers = [];
|
||||||
if (stop.lat !== undefined && stop.lon !== undefined) {
|
if (stop.lat !== undefined && stop.lon !== undefined) {
|
||||||
/* TODO: Add stop lines representation to popup. */
|
/* TODO: Add stop lines representation to popup. */
|
||||||
@@ -124,7 +122,7 @@ const Map: Component = (props) => {
|
|||||||
|
|
||||||
onMount(() => buildMap(mapDiv));
|
onMount(() => buildMap(mapDiv));
|
||||||
|
|
||||||
const onStopUpdate = createEffect(() => {
|
createEffect(() => {
|
||||||
/* TODO: Avoid to clear all layers... */
|
/* TODO: Avoid to clear all layers... */
|
||||||
stopsLayerGroup.clearLayers();
|
stopsLayerGroup.clearLayers();
|
||||||
|
|
||||||
|
@@ -6,28 +6,91 @@ export enum TrafficStatus {
|
|||||||
BYPASSED
|
BYPASSED
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Passages { };
|
export class Passages { };
|
||||||
export interface Passage {
|
|
||||||
line: number,
|
export class Passage {
|
||||||
operator: string,
|
line: number;
|
||||||
destinations: Array<string>,
|
operator: string;
|
||||||
atStop: boolean,
|
destinations: Array<string>;
|
||||||
aimedArrivalTs: number,
|
atStop: boolean;
|
||||||
expectedArrivalTs: number,
|
aimedArrivalTs: number;
|
||||||
arrivalPlatformName: string,
|
expectedArrivalTs: number;
|
||||||
aimedDepartTs: number,
|
arrivalPlatformName: string;
|
||||||
expectedDepartTs: number,
|
aimedDepartTs: number;
|
||||||
arrivalStatus: string,
|
expectedDepartTs: number;
|
||||||
departStatus: string,
|
arrivalStatus: string;
|
||||||
|
departStatus: string;
|
||||||
|
|
||||||
|
constructor(line: number, operator: string, destinations: Array<string>, atStop: boolean, aimedArrivalTs: number,
|
||||||
|
expectedArrivalTs: number, arrivalPlatformName: string, aimedDepartTs: number, expectedDepartTs: number,
|
||||||
|
arrivalStatus: string, departStatus: string) {
|
||||||
|
this.line = line;
|
||||||
|
this.operator = operator;
|
||||||
|
this.destinations = destinations;
|
||||||
|
this.atStop = atStop;
|
||||||
|
this.aimedArrivalTs = aimedArrivalTs;
|
||||||
|
this.expectedArrivalTs = expectedArrivalTs;
|
||||||
|
this.arrivalPlatformName = arrivalPlatformName;
|
||||||
|
this.aimedDepartTs = aimedDepartTs;
|
||||||
|
this.expectedDepartTs = expectedDepartTs;
|
||||||
|
this.arrivalStatus = arrivalStatus;
|
||||||
|
this.departStatus = departStatus;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export class Stops { };
|
||||||
|
|
||||||
export interface Stops { };
|
export class Stop {
|
||||||
export interface Stop {
|
id: number;
|
||||||
id: number,
|
name: string;
|
||||||
name: string,
|
town: string;
|
||||||
town: string,
|
lat: number;
|
||||||
lat: number,
|
lon: number;
|
||||||
lon: number,
|
stops: Array<Stop>;
|
||||||
lines: Array<string>
|
lines: Array<string>;
|
||||||
|
|
||||||
|
constructor(id: number, name: string, town: string, lat: number, lon: number, stops: Array<Stop>, lines: Array<string>) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.town = town;
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.stops = stops;
|
||||||
|
this.lines = lines;
|
||||||
|
for (const stop of this.stops) {
|
||||||
|
this.lines.push(...stop.lines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export class Line {
|
||||||
|
id: string;
|
||||||
|
shortName: string;
|
||||||
|
name: string;
|
||||||
|
status: string; // TODO: Use an enum
|
||||||
|
transportMode: string; // TODO: Use an enum
|
||||||
|
backColorHexa: string;
|
||||||
|
foreColorHexa: string;
|
||||||
|
operatorId: number;
|
||||||
|
accessibility: boolean;
|
||||||
|
visualSignsAvailable: string; // TODO: Use an enum
|
||||||
|
audibleSignsAvailable: string; // TODO: Use an enum
|
||||||
|
stopIds: Array<number>;
|
||||||
|
|
||||||
|
constructor(id: string, shortName: string, name: string, status: string, transportMode: string, backColorHexa: string,
|
||||||
|
foreColorHexa: string, operatorId: number, accessibility: boolean, visualSignsAvailable: string,
|
||||||
|
audibleSignsAvailable: string, stopIds: Array<number>) {
|
||||||
|
this.id = id;
|
||||||
|
this.shortName = shortName;
|
||||||
|
this.name = name;
|
||||||
|
this.status = status;
|
||||||
|
this.transportMode = transportMode;
|
||||||
|
this.backColorHexa = backColorHexa;
|
||||||
|
this.foreColorHexa = foreColorHexa;
|
||||||
|
this.operatorId = operatorId;
|
||||||
|
this.accessibility = accessibility;
|
||||||
|
this.visualSignsAvailable = visualSignsAvailable;
|
||||||
|
this.audibleSignsAvailable = audibleSignsAvailable;
|
||||||
|
this.stopIds = stopIds;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { Line } from './types';
|
||||||
|
|
||||||
const validTransportModes = ["bus", "tram", "metro", "rer", "transilien", "funicular", "ter", "unknown"];
|
const validTransportModes = ["bus", "tram", "metro", "rer", "transilien", "funicular", "ter", "unknown"];
|
||||||
|
|
||||||
export const TransportModeWeights = {
|
export const TransportModeWeights = {
|
||||||
@@ -11,11 +13,11 @@ export const TransportModeWeights = {
|
|||||||
ter: 8,
|
ter: 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function renderLineTransportMode(line): JSX.Element {
|
export function renderLineTransportMode(line: Line): JSX.Element {
|
||||||
return <img src={getTransportModeSrc(line.transportMode)} />
|
return <img src={getTransportModeSrc(line.transportMode)} />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTransportModeSrc(mode: string, color: bool = true): string {
|
export function getTransportModeSrc(mode: string, color: boolean = true): string | null {
|
||||||
let ret = null;
|
let ret = null;
|
||||||
if (validTransportModes.includes(mode)) {
|
if (validTransportModes.includes(mode)) {
|
||||||
ret = `/public/symbole_${mode}_${color ? "" : "support_fonce_"}RVB.svg`;
|
ret = `/public/symbole_${mode}_${color ? "" : "support_fonce_"}RVB.svg`;
|
||||||
@@ -24,7 +26,7 @@ export function getTransportModeSrc(mode: string, color: bool = true): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function renderBusLinePicto(line, styles): JSX.Element {
|
function renderBusLinePicto(line: Line, styles): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div class={styles.busLinePicto}>
|
<div class={styles.busLinePicto}>
|
||||||
<svg viewBox="0 0 31.5 14">
|
<svg viewBox="0 0 31.5 14">
|
||||||
@@ -42,7 +44,7 @@ function renderBusLinePicto(line, styles): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTramLinePicto(line, styles): JSX.Element {
|
function renderTramLinePicto(line: Line, styles): JSX.Element {
|
||||||
const lineStyle = { fill: `#${line.backColorHexa}` };
|
const lineStyle = { fill: `#${line.backColorHexa}` };
|
||||||
return (
|
return (
|
||||||
<div class={styles.tramLinePicto}>
|
<div class={styles.tramLinePicto}>
|
||||||
@@ -62,7 +64,7 @@ function renderTramLinePicto(line, styles): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMetroLinePicto(line, styles): JSX.Element {
|
function renderMetroLinePicto(line: Line, styles): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div class={styles.metroLinePicto}>
|
<div class={styles.metroLinePicto}>
|
||||||
<svg viewbox="0 0 20 20">
|
<svg viewbox="0 0 20 20">
|
||||||
@@ -79,7 +81,7 @@ function renderMetroLinePicto(line, styles): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTrainLinePicto(line, styles): JSX.Element {
|
function renderTrainLinePicto(line: Line, styles): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div class={styles.trainLinePicto}>
|
<div class={styles.trainLinePicto}>
|
||||||
<svg viewbox="0 0 20 20">
|
<svg viewbox="0 0 20 20">
|
||||||
@@ -97,7 +99,7 @@ function renderTrainLinePicto(line, styles): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderLinePicto(line, styles): JSX.Element {
|
export function renderLinePicto(line: Line, styles): JSX.Element {
|
||||||
switch (line.transportMode) {
|
switch (line.transportMode) {
|
||||||
case "bus":
|
case "bus":
|
||||||
case "funicular":
|
case "funicular":
|
||||||
|
Reference in New Issue
Block a user