import React, { useState } from "react"; import searchIcon from "../../assets/search_icon.png"; import routeIcon from "../../assets/route_icon.png"; import closeIcon from "../../assets/close_icon.png"; import styles from "./SearchBar.module.css"; function SearchBar(props) { const [isExpanded, setIsExpanded] = useState(false); const [from, setFrom] = useState(""); const [to, setTo] = useState(""); const toggleExpanded = () => { setIsExpanded(!isExpanded); }; function searchRoom(){ props.map.search(); } const handleDirectionsSubmit = () => { console.log(`From: ${from}, To: ${to}`); const url = new URL('http://localhost:8080/api/public/navigate'); url.searchParams.append('from', from); url.searchParams.append('to', to); fetch(url) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { console.log('Success:', data); const points = data.map(item => item.coordinates); props.map.drawRoute(points); }) .catch(error => { console.error('Error:', error); }); }; return (
{/* Regular search bar */} {!isExpanded ? (
) : ( /* Expanded view for directions */
setFrom(e.target.value)} className={styles.inputField} /> setTo(e.target.value)} className={styles.inputField} />
)}
); } export default SearchBar;