import { useEffect, useState, useCallback } from "react"; import type { YjsState } from "~/lib/use-yjs"; const PROFILES = [ { id: "trekking", label: "Hiking" }, { id: "fastbike", label: "Cycling (fast)" }, { id: "safety", label: "Cycling (safe)" }, { id: "shortest", label: "Shortest" }, { id: "car-eco", label: "Car" }, ]; interface ProfileSelectorProps { yjs: YjsState; } export function ProfileSelector({ yjs }: ProfileSelectorProps) { const [profile, setProfile] = useState("trekking"); useEffect(() => { const update = () => { const p = yjs.routeData.get("profile") as string | undefined; if (p) setProfile(p); }; yjs.routeData.observe(update); update(); return () => yjs.routeData.unobserve(update); }, [yjs.routeData]); const handleChange = useCallback( (e: React.ChangeEvent) => { const value = e.target.value; setProfile(value); yjs.routeData.set("profile", value); }, [yjs.routeData], ); return (
); }