💄 Redesign stop search menu to follow the passage display style

This commit is contained in:
2023-03-05 13:46:25 +01:00
parent f09ba4cc58
commit 4a2fadb5b3
5 changed files with 390 additions and 118 deletions

View File

@@ -1,13 +1,16 @@
import { createContext, JSX } from 'solid-js';
import { batch, createContext, JSX } from 'solid-js';
import { createStore } from 'solid-js/store';
import { Marker as LeafletMarker } from 'leaflet';
import { Stop } from './types';
import { Stop, Stops } from './types';
export type ByStopIdMarkers = Record<number, LeafletMarker[] | undefined>;
export interface SearchStore {
getFoundStops: () => Stop[];
setFoundStops: (stops: Stop[]) => void;
getDisplayedStops: () => Stop[];
setDisplayedStops: (stops: Stop[]) => void;
@@ -19,12 +22,20 @@ export const SearchContext = createContext<SearchStore>();
export function SearchProvider(props: { children: JSX.Element }) {
type Store = {
stops: Record<number, Stop | undefined>;
foundStops: Stop[];
markers: ByStopIdMarkers;
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[] => {
return store.displayedStops;
@@ -42,7 +53,7 @@ export function SearchProvider(props: { children: JSX.Element }) {
}
return (
<SearchContext.Provider value={{ getDisplayedStops, setDisplayedStops, addMarkers }}>
<SearchContext.Provider value={{ getFoundStops, setFoundStops, getDisplayedStops, setDisplayedStops, addMarkers }}>
{props.children}
</SearchContext.Provider>
);