💄 Redesign stop search menu to follow the passage display style
This commit is contained in:
43
frontend/src/appContext.tsx
Normal file
43
frontend/src/appContext.tsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { createContext, JSX } from 'solid-js';
|
||||||
|
import { createStore } from "solid-js/store";
|
||||||
|
|
||||||
|
import { Stop } from './types';
|
||||||
|
|
||||||
|
export interface AppContextStore {
|
||||||
|
getDisplayedStops: () => Stop[];
|
||||||
|
setDisplayedStops: (stops: Stop[]) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AppContextContext = createContext<AppContextStore>();
|
||||||
|
|
||||||
|
export function AppContextProvider(props: { children: JSX.Element }) {
|
||||||
|
|
||||||
|
type Store = {
|
||||||
|
displayedStops: Stop[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const [store, setStore] = createStore<Store>({
|
||||||
|
displayedStops: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDisplayedStops = (): Stop[] => {
|
||||||
|
return store.displayedStops;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setDisplayedStops = (stops: Stop[]): void => {
|
||||||
|
console.log("setDisplayedStops=", stops);
|
||||||
|
// setStore((s: Store) => {
|
||||||
|
setStore('displayedStops', stops);
|
||||||
|
// return s;
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppContextContext.Provider value={{
|
||||||
|
getDisplayedStops, setDisplayedStops,
|
||||||
|
}}>
|
||||||
|
{props.children}
|
||||||
|
</AppContextContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
@@ -5,19 +5,12 @@ import { IconButton, Menu, MenuTrigger, MenuContent, MenuItem } from "@hope-ui/s
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
|
||||||
import { BusinessDataContext, BusinessDataStore } from "./businessData";
|
import { BusinessDataContext, BusinessDataStore } from "./businessData";
|
||||||
import { SearchContext, SearchStore } from "./search";
|
import { AppContextContext, AppContextStore } from "./appContext";
|
||||||
|
|
||||||
import { getTransportModeSrc } from "./utils";
|
import { getTransportModeSrc, PositionedPanel } from "./utils";
|
||||||
import { PassagesPanel } from "./passagesPanel";
|
import { PassagesPanel } from "./passagesPanel";
|
||||||
import { IconHamburgerMenu } from './extra/iconHamburgerMenu';
|
import { IconHamburgerMenu } from './extra/iconHamburgerMenu';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type PositionnedPanel = {
|
|
||||||
position: number;
|
|
||||||
// TODO: Should be PassagesPanelComponent ?
|
|
||||||
panel: JSX.Element;
|
|
||||||
};
|
|
||||||
import "./passagesDisplay.scss";
|
import "./passagesDisplay.scss";
|
||||||
|
|
||||||
|
|
||||||
@@ -27,8 +20,8 @@ interface PassagesDisplayStore {
|
|||||||
disablePassagesRefresh: () => void;
|
disablePassagesRefresh: () => void;
|
||||||
togglePassagesRefresh: () => void;
|
togglePassagesRefresh: () => void;
|
||||||
|
|
||||||
getPanels: () => Array<PositionnedPanel>;
|
getPanels: () => PositionedPanel[];
|
||||||
setPanels: (panels: Array<PositionnedPanel>) => void;
|
setPanels: (panels: PositionedPanel[]) => void;
|
||||||
|
|
||||||
getDisplayedPanelId: () => number;
|
getDisplayedPanelId: () => number;
|
||||||
setDisplayedPanelId: (panelId: number) => void;
|
setDisplayedPanelId: (panelId: number) => void;
|
||||||
@@ -40,7 +33,7 @@ function PassagesDisplayProvider(props: { children: JSX.Element }) {
|
|||||||
|
|
||||||
type Store = {
|
type Store = {
|
||||||
refreshEnabled: boolean;
|
refreshEnabled: boolean;
|
||||||
panels: Array<PositionnedPanel>;
|
panels: PositionedPanel[];
|
||||||
displayedPanelId: number;
|
displayedPanelId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,10 +55,10 @@ function PassagesDisplayProvider(props: { children: JSX.Element }) {
|
|||||||
setStore('refreshEnabled', !store.refreshEnabled);
|
setStore('refreshEnabled', !store.refreshEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPanels = (): Array<PositionnedPanel> => {
|
const getPanels = (): PositionedPanel[] => {
|
||||||
return store.panels;
|
return store.panels;
|
||||||
}
|
}
|
||||||
const setPanels = (panels: Array<PositionnedPanel>): void => {
|
const setPanels = (panels: PositionedPanel[]): void => {
|
||||||
setStore('panels', panels);
|
setStore('panels', panels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +81,6 @@ function PassagesDisplayProvider(props: { children: JSX.Element }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Sort transport modes by weight
|
// TODO: Sort transport modes by weight
|
||||||
const Header: VoidComponent<{ title: string }> = (props) => {
|
const Header: VoidComponent<{ title: string }> = (props) => {
|
||||||
|
|
||||||
@@ -193,17 +185,16 @@ const Footer: VoidComponent<{}> = () => {
|
|||||||
const Body: ParentComponent<{ maxPassagesPerPanel: number, syncPeriodMsec: number, panelSwitchPeriodMsec: number }> = (props) => {
|
const Body: ParentComponent<{ maxPassagesPerPanel: number, syncPeriodMsec: number, panelSwitchPeriodMsec: number }> = (props) => {
|
||||||
|
|
||||||
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
||||||
|
const appContextStore: AppContextStore | undefined = useContext(AppContextContext);
|
||||||
const passagesDisplayStore: PassagesDisplayStore | undefined = useContext(PassagesDisplayContext);
|
const passagesDisplayStore: PassagesDisplayStore | undefined = useContext(PassagesDisplayContext);
|
||||||
// TODO: Use props instead
|
|
||||||
const searchStore: SearchStore | undefined = useContext(SearchContext);
|
|
||||||
|
|
||||||
if (businessDataStore === undefined || passagesDisplayStore === undefined || searchStore === undefined) {
|
if (businessDataStore === undefined || appContextStore === undefined || passagesDisplayStore === undefined) {
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { getLineDestinations, passages, getPassagesLineIds, clearPassages, refreshPassages } = businessDataStore;
|
const { getLineDestinations, passages, getPassagesLineIds, clearPassages, refreshPassages } = businessDataStore;
|
||||||
const { isPassagesRefreshEnabled, getDisplayedPanelId, setDisplayedPanelId, getPanels, setPanels } = passagesDisplayStore;
|
const { isPassagesRefreshEnabled, getDisplayedPanelId, setDisplayedPanelId, getPanels, setPanels } = passagesDisplayStore;
|
||||||
const { getDisplayedStops } = searchStore;
|
const { getDisplayedStops } = appContextStore;
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
let nextPanelId = getDisplayedPanelId() + 1;
|
let nextPanelId = getDisplayedPanelId() + 1;
|
||||||
@@ -249,7 +240,7 @@ const Body: ParentComponent<{ maxPassagesPerPanel: number, syncPeriodMsec: numbe
|
|||||||
setPanels([]);
|
setPanels([]);
|
||||||
|
|
||||||
let newPanels = [];
|
let newPanels = [];
|
||||||
let positioneds: PositionnedPanel[] = [];
|
let positioneds: PositionedPanel[] = [];
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
let lineIds: string[] = [];
|
let lineIds: string[] = [];
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
import { createContext, JSX } from 'solid-js';
|
import { batch, createContext, JSX } from 'solid-js';
|
||||||
import { createStore } from 'solid-js/store';
|
import { createStore } from 'solid-js/store';
|
||||||
import { Marker as LeafletMarker } from 'leaflet';
|
import { Marker as LeafletMarker } from 'leaflet';
|
||||||
|
|
||||||
import { Stop } from './types';
|
import { Stop, Stops } from './types';
|
||||||
|
|
||||||
|
|
||||||
export type ByStopIdMarkers = Record<number, LeafletMarker[] | undefined>;
|
export type ByStopIdMarkers = Record<number, LeafletMarker[] | undefined>;
|
||||||
|
|
||||||
export interface SearchStore {
|
export interface SearchStore {
|
||||||
|
getFoundStops: () => Stop[];
|
||||||
|
setFoundStops: (stops: Stop[]) => void;
|
||||||
|
|
||||||
getDisplayedStops: () => Stop[];
|
getDisplayedStops: () => Stop[];
|
||||||
setDisplayedStops: (stops: Stop[]) => void;
|
setDisplayedStops: (stops: Stop[]) => void;
|
||||||
|
|
||||||
@@ -19,12 +22,20 @@ export const SearchContext = createContext<SearchStore>();
|
|||||||
export function SearchProvider(props: { children: JSX.Element }) {
|
export function SearchProvider(props: { children: JSX.Element }) {
|
||||||
|
|
||||||
type Store = {
|
type Store = {
|
||||||
stops: Record<number, Stop | undefined>;
|
foundStops: Stop[];
|
||||||
markers: ByStopIdMarkers;
|
markers: ByStopIdMarkers;
|
||||||
displayedStops: Stop[];
|
displayedStops: Stop[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const [store, setStore] = createStore<Store>({ stops: {}, markers: {}, displayedStops: [] });
|
const [store, setStore] = createStore<Store>({ foundStops: [], markers: {}, displayedStops: [] });
|
||||||
|
|
||||||
|
const getFoundStops = (): Stop[] => {
|
||||||
|
return store.foundStops;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setFoundStops = (stops: Stop[]): void => {
|
||||||
|
setStore('foundStops', stops);
|
||||||
|
}
|
||||||
|
|
||||||
const getDisplayedStops = (): Stop[] => {
|
const getDisplayedStops = (): Stop[] => {
|
||||||
return store.displayedStops;
|
return store.displayedStops;
|
||||||
@@ -42,7 +53,7 @@ export function SearchProvider(props: { children: JSX.Element }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SearchContext.Provider value={{ getDisplayedStops, setDisplayedStops, addMarkers }}>
|
<SearchContext.Provider value={{ getFoundStops, setFoundStops, getDisplayedStops, setDisplayedStops, addMarkers }}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</SearchContext.Provider>
|
</SearchContext.Provider>
|
||||||
);
|
);
|
||||||
|
@@ -1,20 +1,160 @@
|
|||||||
import { createEffect, createResource, createSignal, For, JSX, onMount, Show, useContext, VoidComponent } from 'solid-js';
|
import { createContext, createEffect, createResource, For, JSX, onMount, ParentComponent, Show, useContext, VoidComponent } from 'solid-js';
|
||||||
|
import { createStore } from "solid-js/store";
|
||||||
import { Box, Button, Input, InputLeftAddon, InputGroup, HStack, List, ListItem, Progress, ProgressIndicator, VStack } from "@hope-ui/solid";
|
import { createScrollPosition } from "@solid-primitives/scroll";
|
||||||
import 'leaflet/dist/leaflet.css';
|
|
||||||
|
|
||||||
|
import { Input, InputLeftAddon, InputGroup } from "@hope-ui/solid";
|
||||||
import {
|
import {
|
||||||
featureGroup as leafletFeatureGroup, LatLngLiteral as LeafletLatLngLiteral, Map as LeafletMap,
|
featureGroup as leafletFeatureGroup, LatLngLiteral as LeafletLatLngLiteral, Map as LeafletMap,
|
||||||
Marker as LeafletMarker, tileLayer as leafletTileLayer
|
Marker as LeafletMarker, tileLayer as leafletTileLayer
|
||||||
} from 'leaflet';
|
} from 'leaflet';
|
||||||
|
|
||||||
import { BusinessDataContext, BusinessDataStore } from "./businessData";
|
|
||||||
import { SearchContext, SearchStore } from './search';
|
|
||||||
|
|
||||||
import { Stop } from './types';
|
import { Stop } from './types';
|
||||||
import { renderLineTransportMode, renderLinePicto, TransportModeWeights } from './utils';
|
import { PositionedPanel, renderLineTransportMode, renderLinePicto, TransportModeWeights } from './utils';
|
||||||
|
|
||||||
import styles from './stopManager.module.css';
|
import { AppContextContext, AppContextStore } from "./appContext";
|
||||||
|
import { BusinessDataContext, BusinessDataStore } from "./businessData";
|
||||||
|
|
||||||
|
import "leaflet/dist/leaflet.css";
|
||||||
|
import "./stopsSearchMenu.scss";
|
||||||
|
|
||||||
|
|
||||||
|
type ByStopIdMarkers = Record<number, LeafletMarker[] | undefined>;
|
||||||
|
|
||||||
|
interface SearchStore {
|
||||||
|
|
||||||
|
getSearchText: () => string;
|
||||||
|
setSearchText: (text: string, businessDataStore: BusinessDataStore) => Promise<void>;
|
||||||
|
isSearchInProgress: () => boolean;
|
||||||
|
|
||||||
|
getFoundStops: () => Stop[];
|
||||||
|
setFoundStops: (stops: Stop[]) => void;
|
||||||
|
|
||||||
|
getDisplayedPanelId: () => number;
|
||||||
|
setDisplayedPanelId: (panelId: number) => void;
|
||||||
|
|
||||||
|
addMarkers: (stopId: number, markers: LeafletMarker[]) => void;
|
||||||
|
|
||||||
|
getPanels: () => PositionedPanel[];
|
||||||
|
setPanels: (panels: PositionedPanel[]) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SearchContext = createContext<SearchStore>();
|
||||||
|
|
||||||
|
function SearchProvider(props: { children: JSX.Element }) {
|
||||||
|
|
||||||
|
type Store = {
|
||||||
|
searchText: string;
|
||||||
|
searchInProgress: boolean;
|
||||||
|
foundStops: Stop[];
|
||||||
|
markers: ByStopIdMarkers;
|
||||||
|
displayedPanelId: number;
|
||||||
|
panels: PositionedPanel[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const [store, setStore] = createStore<Store>({
|
||||||
|
searchText: "", searchInProgress: false, foundStops: [], markers: {}, displayedPanelId: 0, panels: []
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSearchText = (): string => {
|
||||||
|
return store.searchText;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setSearchText = async (text: string, businessDataStore: BusinessDataStore): Promise<void> => {
|
||||||
|
setStore('searchInProgress', true);
|
||||||
|
|
||||||
|
setStore('searchText', text);
|
||||||
|
|
||||||
|
const { searchStopByName } = businessDataStore;
|
||||||
|
console.log("store.searchText=", store.searchText);
|
||||||
|
const stopsById = await searchStopByName(store.searchText);
|
||||||
|
console.log("stopsById=", stopsById);
|
||||||
|
setFoundStops(Object.values(stopsById));
|
||||||
|
|
||||||
|
setStore('searchInProgress', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSearchInProgress = (): boolean => {
|
||||||
|
return store.searchInProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getFoundStops = (): Stop[] => {
|
||||||
|
return store.foundStops;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setFoundStops = (stops: Stop[]): void => {
|
||||||
|
setStore('foundStops', stops);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getDisplayedPanelId = (): number => {
|
||||||
|
return store.displayedPanelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setDisplayedPanelId = (panelId: number): void => {
|
||||||
|
setStore('displayedPanelId', panelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const addMarkers = (stopId: number, markers: L.Marker[]): void => {
|
||||||
|
setStore('markers', stopId, markers);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPanels = (): PositionedPanel[] => {
|
||||||
|
return store.panels;
|
||||||
|
}
|
||||||
|
const setPanels = (panels: PositionedPanel[]): void => {
|
||||||
|
setStore('panels', panels);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SearchContext.Provider value={{
|
||||||
|
getSearchText, setSearchText, isSearchInProgress,
|
||||||
|
getFoundStops, setFoundStops,
|
||||||
|
getDisplayedPanelId, setDisplayedPanelId,
|
||||||
|
addMarkers,
|
||||||
|
getPanels, setPanels
|
||||||
|
}}>
|
||||||
|
{props.children}
|
||||||
|
</SearchContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Header: VoidComponent<{ title: string, minCharsNb: number }> = (props) => {
|
||||||
|
|
||||||
|
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
||||||
|
const searchStore: SearchStore | undefined = useContext(SearchContext);
|
||||||
|
|
||||||
|
if (businessDataStore === undefined || searchStore === undefined)
|
||||||
|
return <div />;
|
||||||
|
|
||||||
|
const { isSearchInProgress, setSearchText } = searchStore;
|
||||||
|
|
||||||
|
const onStopNameInput: JSX.EventHandler<HTMLInputElement, InputEvent> = async (event): Promise<void> => {
|
||||||
|
/* TODO: Add a tempo before fetching stop for giving time to user to finish his request */
|
||||||
|
const stopName = event.currentTarget.value;
|
||||||
|
if (stopName.length >= props.minCharsNb) {
|
||||||
|
console.log(`Fetching data for "${stopName}" stop name`);
|
||||||
|
await setSearchText(stopName, businessDataStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="header">
|
||||||
|
<div class="title">
|
||||||
|
<svg viewBox="0 0 1260 50">
|
||||||
|
<text x="0" y="50%" dominant-baseline="middle" font-size="50" style="fill: #ffffff">
|
||||||
|
{props.title}
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="inputGroup">
|
||||||
|
<InputGroup >
|
||||||
|
<InputLeftAddon>🚉 🚏</InputLeftAddon>
|
||||||
|
<Input onInput={onStopNameInput} readOnly={isSearchInProgress()} placeholder="Stop name..." />
|
||||||
|
</InputGroup>
|
||||||
|
</div>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const StopRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
const StopRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
||||||
@@ -40,27 +180,31 @@ const StopRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
|||||||
const [lineReprs] = createResource<JSX.Element[], string[]>(props.stop.lines, fetchLinesRepr);
|
const [lineReprs] = createResource<JSX.Element[], string[]>(props.stop.lines, fetchLinesRepr);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HStack height="100%">
|
<div class="stop">
|
||||||
{props.stop.name}
|
<div class="name">{props.stop.name}</div>
|
||||||
<For each={lineReprs()}>{(line: JSX.Element) => line}</For>
|
<For each={lineReprs()}>{(line: JSX.Element) => line}</For>
|
||||||
</HStack>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type ByTransportModeReprs = {
|
||||||
|
mode: JSX.Element | undefined;
|
||||||
|
lines: Record<string, JSX.Element | JSX.Element[] | undefined>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const StopAreaRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
const StopAreaRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
||||||
|
|
||||||
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
||||||
if (businessDataStore === undefined)
|
const appContextStore: AppContextStore | undefined = useContext(AppContextContext);
|
||||||
|
if (businessDataStore === undefined || appContextStore === undefined)
|
||||||
return <div />;
|
return <div />;
|
||||||
|
|
||||||
const { getLine } = businessDataStore;
|
const { getLine } = businessDataStore;
|
||||||
|
const { setDisplayedStops } = appContextStore;
|
||||||
|
|
||||||
type ByTransportModeReprs = {
|
const fetchLinesRepr = async (stop: Stop): Promise<JSX.Element> => {
|
||||||
mode: JSX.Element | undefined;
|
|
||||||
[key: string]: JSX.Element | JSX.Element[] | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchLinesRepr = async (stop: Stop): Promise<JSX.Element[]> => {
|
|
||||||
const lineIds = new Set(stop.lines);
|
const lineIds = new Set(stop.lines);
|
||||||
const stops = stop.stops;
|
const stops = stop.stops;
|
||||||
for (const stop of stops) {
|
for (const stop of stops) {
|
||||||
@@ -74,38 +218,122 @@ const StopAreaRepr: VoidComponent<{ stop: Stop }> = (props) => {
|
|||||||
if (!(line.transportMode in byModeReprs)) {
|
if (!(line.transportMode in byModeReprs)) {
|
||||||
byModeReprs[line.transportMode] = {
|
byModeReprs[line.transportMode] = {
|
||||||
mode: <div class="transportMode">{renderLineTransportMode(line)}</div>,
|
mode: <div class="transportMode">{renderLineTransportMode(line)}</div>,
|
||||||
|
lines: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
byModeReprs[line.transportMode][line.shortName] = renderLinePicto(line, styles);
|
byModeReprs[line.transportMode].lines[line.shortName] = renderLinePicto(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reprs = [];
|
const sortedTransportModes = Object.keys(byModeReprs).sort((x, y) => TransportModeWeights[x] <
|
||||||
const sortedTransportModes = Object.keys(byModeReprs).sort((x, y) => TransportModeWeights[x] < TransportModeWeights[y] ? 1 : -1);
|
TransportModeWeights[y] ? 1 : -1);
|
||||||
for (const transportMode of sortedTransportModes) {
|
|
||||||
const lines = byModeReprs[transportMode];
|
return (
|
||||||
const repr = [lines.mode];
|
<div class="lineRepr">
|
||||||
delete lines.mode;
|
<For each={sortedTransportModes}>{(transportMode) => {
|
||||||
for (const lineId of Object.keys(lines).sort((x, y) => x.localeCompare(y))) {
|
const reprs = byModeReprs[transportMode];
|
||||||
repr.push(lines[lineId]);
|
const lineNames = Object.keys(reprs.lines).sort((x, y) => x.localeCompare(y));
|
||||||
}
|
return <>
|
||||||
reprs.push(repr);
|
{reprs.mode}
|
||||||
}
|
<div class="linesRepresentationMatrix">
|
||||||
return reprs;
|
<For each={lineNames}>{(lineName) => reprs.lines[lineName]}</For>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
}}
|
||||||
|
</For>
|
||||||
|
</div >
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [lineReprs] = createResource(props.stop, fetchLinesRepr);
|
const [lineReprs] = createResource(props.stop, fetchLinesRepr);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HStack height="100%">
|
<div class="stop" onClick={() => setDisplayedStops([props.stop])}>
|
||||||
{props.stop.name}
|
<div class="name">{props.stop.name}</div>
|
||||||
<For each={lineReprs()}>{(line) => line}</For>
|
{lineReprs()}
|
||||||
</HStack>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StopsPanel: ParentComponent<{ stops: Stop[], show: boolean }> = (props) => {
|
||||||
|
return (
|
||||||
|
<div classList={{ ["stopPanel"]: true, ["displayed"]: props.show }}>
|
||||||
|
<For each={props.stops.sort((x, y) => x.name.localeCompare(y.name))}>
|
||||||
|
{(stop) => {
|
||||||
|
return <Show when={stop.stops !== undefined} fallback={<StopRepr stop={stop} />}>
|
||||||
|
<StopAreaRepr stop={stop} />
|
||||||
|
</Show>;
|
||||||
|
}}
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const Map: VoidComponent<{ stops: Stop[] }> = (props) => {
|
const StopsPanels: ParentComponent<{ maxStopsPerPanel: number }> = (props) => {
|
||||||
|
const searchStore: SearchStore | undefined = useContext(SearchContext);
|
||||||
|
|
||||||
|
if (searchStore === undefined) {
|
||||||
|
return <div />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { getDisplayedPanelId, getFoundStops, getPanels, setDisplayedPanelId, setPanels } = searchStore;
|
||||||
|
|
||||||
|
let stopsPanelsRef: HTMLDivElement | undefined = undefined
|
||||||
|
const stopsPanelsScroll = createScrollPosition(() => stopsPanelsRef);
|
||||||
|
const yStopsPanelsScroll = () => stopsPanelsScroll.y;
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
yStopsPanelsScroll();
|
||||||
|
|
||||||
|
for (const panel of Object.values(getPanels())) {
|
||||||
|
if (panel.panel) {
|
||||||
|
const panelDiv = panel.panel();
|
||||||
|
const panelDivClientRect = panelDiv.getBoundingClientRect();
|
||||||
|
if (panelDivClientRect.y > 0) {
|
||||||
|
setDisplayedPanelId(panel.position);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={stopsPanelsRef} class="stopsPanels">
|
||||||
|
{() => {
|
||||||
|
setPanels([]);
|
||||||
|
|
||||||
|
let newPanels = [];
|
||||||
|
let positioneds: PositionedPanel[] = [];
|
||||||
|
|
||||||
|
let stops: Stop[] = [];
|
||||||
|
|
||||||
|
for (const stop of getFoundStops()) {
|
||||||
|
if (stops.length < props.maxStopsPerPanel) {
|
||||||
|
stops.push(stop);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const panelId = newPanels.length;
|
||||||
|
const panel = <StopsPanel stops={stops} show={panelId == getDisplayedPanelId()} />;
|
||||||
|
newPanels.push(panel);
|
||||||
|
positioneds.push({ position: panelId, panel: panel });
|
||||||
|
stops = [stop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stops.length) {
|
||||||
|
const panelId = newPanels.length;
|
||||||
|
const panel = <StopsPanel stops={stops} show={panelId == getDisplayedPanelId()} />;
|
||||||
|
newPanels.push(panel);
|
||||||
|
positioneds.push({ position: panelId, panel: panel });
|
||||||
|
}
|
||||||
|
|
||||||
|
setPanels(positioneds);
|
||||||
|
|
||||||
|
return newPanels;
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Map: VoidComponent<{}> = () => {
|
||||||
|
|
||||||
const mapCenter: LeafletLatLngLiteral = { lat: 48.853, lng: 2.35 };
|
const mapCenter: LeafletLatLngLiteral = { lat: 48.853, lng: 2.35 };
|
||||||
|
|
||||||
@@ -113,7 +341,7 @@ const Map: VoidComponent<{ stops: Stop[] }> = (props) => {
|
|||||||
if (searchStore === undefined)
|
if (searchStore === undefined)
|
||||||
return <div />;
|
return <div />;
|
||||||
|
|
||||||
const { addMarkers } = searchStore;
|
const { addMarkers, getFoundStops } = searchStore;
|
||||||
|
|
||||||
|
|
||||||
let mapDiv: any;
|
let mapDiv: any;
|
||||||
@@ -148,7 +376,7 @@ const Map: VoidComponent<{ stops: Stop[] }> = (props) => {
|
|||||||
/* TODO: Avoid to clear all layers... */
|
/* TODO: Avoid to clear all layers... */
|
||||||
stopsLayerGroup.clearLayers();
|
stopsLayerGroup.clearLayers();
|
||||||
|
|
||||||
for (const stop of props.stops) {
|
for (const stop of getFoundStops()) {
|
||||||
const markers = setMarker(stop);
|
const markers = setMarker(stop);
|
||||||
addMarkers(stop.id, markers);
|
addMarkers(stop.id, markers);
|
||||||
for (const marker of markers) {
|
for (const marker of markers) {
|
||||||
@@ -162,67 +390,53 @@ const Map: VoidComponent<{ stops: Stop[] }> = (props) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return <div ref={mapDiv} id='main-map' style={{ width: "100%", height: "100%" }} />;
|
return <div ref={mapDiv} class="map" id="main-map" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StopsManager: VoidComponent = () => {
|
const Footer: VoidComponent<{}> = () => {
|
||||||
|
|
||||||
const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext);
|
|
||||||
const searchStore: SearchStore | undefined = useContext(SearchContext);
|
const searchStore: SearchStore | undefined = useContext(SearchContext);
|
||||||
|
|
||||||
if (businessDataStore === undefined || searchStore === undefined)
|
if (searchStore === undefined) {
|
||||||
return <div />;
|
return <div />;
|
||||||
|
|
||||||
const { searchStopByName } = businessDataStore;
|
|
||||||
const { setDisplayedStops } = searchStore;
|
|
||||||
|
|
||||||
// TODO: Use props instead
|
|
||||||
const [minCharactersNb] = createSignal<number>(4);
|
|
||||||
|
|
||||||
const [inProgress, setInProgress] = createSignal<boolean>(false);
|
|
||||||
const [foundStops, setFoundStops] = createSignal<Stop[]>([]);
|
|
||||||
|
|
||||||
const onStopNameInput: JSX.EventHandler<HTMLInputElement, InputEvent> = async (event): Promise<void> => {
|
|
||||||
/* TODO: Add a tempo before fetching stop for giving time to user to finish his request */
|
|
||||||
const stopName = event.currentTarget.value;
|
|
||||||
if (stopName.length >= minCharactersNb()) {
|
|
||||||
console.log(`Fetching data for ${stopName}`);
|
|
||||||
setInProgress(true);
|
|
||||||
const stopsById = await searchStopByName(stopName);
|
|
||||||
setFoundStops(Object.values(stopsById));
|
|
||||||
setInProgress(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { getDisplayedPanelId, getPanels } = searchStore;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack h="100%">
|
<div class="footer">
|
||||||
<InputGroup w="50%" h="5%">
|
<For each={getPanels()}>
|
||||||
<InputLeftAddon>🚉 🚏</InputLeftAddon>
|
{(panel) => {
|
||||||
<Input onInput={onStopNameInput} readOnly={inProgress()} placeholder="Stop name..." />
|
const position = panel.position;
|
||||||
</InputGroup>
|
return (
|
||||||
<Progress size="xs" w="50%" indeterminate={inProgress()}>
|
<div>
|
||||||
<ProgressIndicator striped animated />
|
<svg viewBox="0 0 29 29">
|
||||||
</Progress>
|
<circle cx="50%" cy="50%" r="13" stroke="#ffffff" stroke-width="3"
|
||||||
<Box w="100%" h="40%" borderWidth="1px" borderColor="var(--idfm-black)" borderRadius="$lg" overflow="scroll" marginBottom="2px">
|
style={{ fill: `var(--idfm-${position == getDisplayedPanelId() ? "white" : "black"})` }}
|
||||||
<List width="100%" height="100%">
|
/>
|
||||||
<For each={foundStops().sort((x, y) => x.name.localeCompare(y.name))}>
|
</svg>
|
||||||
{(stop) =>
|
</div>
|
||||||
<ListItem borderWidth="1px" mb="0px" color="var(--idfm-black)" borderRadius="$lg">
|
);
|
||||||
<Button fullWidth="true" color="var(--idfm-black)" bg="white" onClick={() => setDisplayedStops([stop])}>
|
}}
|
||||||
<Box w="100%" h="100%">
|
</For>
|
||||||
<Show when={stop.stops !== undefined} fallback={<StopRepr stop={stop} />}>
|
</div>
|
||||||
<StopAreaRepr stop={stop} />
|
);
|
||||||
</Show>
|
}
|
||||||
</Box>
|
|
||||||
</Button>
|
export const StopsSearchMenu: VoidComponent = () => {
|
||||||
</ListItem>
|
|
||||||
}
|
const MAX_STOPS_PER_PANEL = 5;
|
||||||
</For>
|
|
||||||
</List>
|
return (
|
||||||
</Box>
|
<div class="stopSearchMenu">
|
||||||
<Box borderWidth="1px" borderColor="var(--idfm-black)" borderRadius="$lg" h="55%" w="100%" overflow="scroll">
|
<SearchProvider>
|
||||||
<Map stops={foundStops()} />
|
<Header title="Recherche de l'arrêt..." minCharsNb={4} />
|
||||||
</Box>
|
<div class="body">
|
||||||
</VStack>
|
<StopsPanels maxStopsPerPanel={MAX_STOPS_PER_PANEL} />
|
||||||
|
<Map />
|
||||||
|
</div>
|
||||||
|
<Footer />
|
||||||
|
</SearchProvider>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -2,6 +2,13 @@ import { JSX } from 'solid-js';
|
|||||||
|
|
||||||
import { Line } from './types';
|
import { Line } from './types';
|
||||||
|
|
||||||
|
// Thanks to https://dev.to/ycmjason/how-to-create-range-in-javascript-539i
|
||||||
|
export function* range(start: number, end: number): Generator<number> {
|
||||||
|
for (let i = start; i <= end; i++) {
|
||||||
|
yield i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const validTransportModes = ["bus", "tram", "metro", "rer", "transilien", "funicular", "ter", "unknown"];
|
const validTransportModes = ["bus", "tram", "metro", "rer", "transilien", "funicular", "ter", "unknown"];
|
||||||
|
|
||||||
export const TransportModeWeights: Record<string, number> = {
|
export const TransportModeWeights: Record<string, number> = {
|
||||||
@@ -116,3 +123,9 @@ export function renderLinePicto(line: Line): JSX.Element {
|
|||||||
return renderTrainLinePicto(line);
|
return renderTrainLinePicto(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PositionedPanel = {
|
||||||
|
position: number;
|
||||||
|
// TODO: Should be PassagesPanelComponent ?
|
||||||
|
panel: JSX.Element;
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user