import { createEffect, For, JSX, ParentComponent, useContext, Show, VoidComponent } from 'solid-js'; import { lazily } from 'solidjs-lazily'; import { createScrollPosition } from "@solid-primitives/scroll"; import { Stop } from '../types'; import { PositionedPanel } from '../utils'; import { BusinessDataContext, BusinessDataStore } from "../businessData"; import { SearchContext, SearchProvider, SearchStore } from "./searchStore"; import { StopsPanel } from "./stopPanel"; const { Map } = lazily(() => import("./map")); import "./stopsSearchMenu.scss"; const StopNameInput: VoidComponent<{ onInput: JSX.EventHandler, leftAddon: string, placeholder: string }> = (props) => { return
{props.leftAddon}
; }; 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
; const { setSearchText } = searchStore; const onStopNameInput: JSX.EventHandler = async (event): Promise => { const stopName = event.currentTarget.value; if (stopName.length >= props.minCharsNb) { await setSearchText(stopName, businessDataStore); } } return
{props.title}
; }; const StopsPanels: ParentComponent<{ maxStopsPerPanel: number }> = (props) => { const searchStore: SearchStore | undefined = useContext(SearchContext); if (searchStore === undefined) { return
; } 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 getPanels()) { const panelDiv = panel.panel; if (panelDiv != null) { const panelDivClientRect = panelDiv.getBoundingClientRect(); if (panelDivClientRect.y > 0) { setDisplayedPanelId(panel.position); break; } } } }); return (
{() => { 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 = ; newPanels.push(panel); positioneds.push({ position: panelId, panel: panel }); stops = [stop]; } } if (stops.length) { const panelId = newPanels.length; const panel = ; newPanels.push(panel); positioneds.push({ position: panelId, panel: panel }); } setPanels(positioneds); return newPanels; }}
); }; const MapPlaceholder: VoidComponent<{}> = () => { const searchStore: SearchStore | undefined = useContext(SearchContext); if (searchStore === undefined) { return
; } const { enableMap } = searchStore; const onDoubleClick = (): void => { console.log('!!! ON DOUBLE CLICK'); enableMap(true); } return
onDoubleClick()}> Double-clic pour activer la carte
; }; const Body: VoidComponent<{}> = () => { const searchStore: SearchStore | undefined = useContext(SearchContext); if (searchStore === undefined) { return
; } const { isMapEnabled } = searchStore; const maxStopsPerPanel = 5; return
}>
; }; const Footer: VoidComponent<{}> = () => { const searchStore: SearchStore | undefined = useContext(SearchContext); if (searchStore === undefined) { return
; } const { getDisplayedPanelId, getPanels } = searchStore; return ; }; export const StopsSearchMenu: VoidComponent = () => { return
; };