🚨 Try to make TS linter happy
This commit is contained in:
@@ -1,35 +1,39 @@
|
||||
import { batch, createContext } from 'solid-js';
|
||||
import { createContext, JSX } from 'solid-js';
|
||||
import { createStore } from 'solid-js/store';
|
||||
import { Marker as LeafletMarker } from 'leaflet';
|
||||
|
||||
import { Stop, Stops } from './types';
|
||||
import { Stop } from './types';
|
||||
|
||||
|
||||
interface Store {
|
||||
getMarkers: () => Markers;
|
||||
addMarkers?: (stopId, markers) => void;
|
||||
setMarkers?: (markers) => void;
|
||||
export type ByStopIdMarkers = Record<number, LeafletMarker[] | undefined>;
|
||||
|
||||
getStops: () => Stops;
|
||||
setStops?: (stops) => void;
|
||||
removeStops?: (stopIds: Array<number>) => void;
|
||||
export interface SearchStore {
|
||||
getDisplayedStops: () => Stop[];
|
||||
setDisplayedStops: (stops: Stop[]) => void;
|
||||
|
||||
getDisplayedStops: () => Array<Stop>;
|
||||
setDisplayedStops: (stops: Array<Stop>) => void;
|
||||
addMarkers: (stopId: number, markers: LeafletMarker[]) => void;
|
||||
};
|
||||
|
||||
export const SearchContext = createContext<Store>();
|
||||
export const SearchContext = createContext<SearchStore>();
|
||||
|
||||
export function SearchProvider(props: { children: JSX.Element }) {
|
||||
|
||||
const [store, setStore] = createStore({ stops: {}, markers: {}, displayedStops: [] });
|
||||
type Store = {
|
||||
stops: Record<number, Stop | undefined>;
|
||||
markers: ByStopIdMarkers;
|
||||
displayedStops: Stop[];
|
||||
};
|
||||
|
||||
const getDisplayedStops = () => {
|
||||
const [store, setStore] = createStore<Store>({ stops: {}, markers: {}, displayedStops: [] });
|
||||
|
||||
const getDisplayedStops = (): Stop[] => {
|
||||
return store.displayedStops;
|
||||
}
|
||||
|
||||
const setDisplayedStops = (stops: Array<Stop>) => {
|
||||
setStore((s) => {
|
||||
const setDisplayedStops = (stops: Stop[]): void => {
|
||||
setStore((s: Store) => {
|
||||
setStore('displayedStops', stops);
|
||||
return s;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,7 +50,7 @@ export function SearchProvider(props: { children: JSX.Element }) {
|
||||
return store.markers;
|
||||
}
|
||||
|
||||
const addMarkers = (stopId: number, markers) => {
|
||||
const addMarkers = (stopId: number, markers: L.Marker[]): void => {
|
||||
setStore('markers', stopId, markers);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user