Commit 12a8d101 by asranov0003

feat: add cmarker and center map in routes page

parent b5b97bf4
...@@ -10,12 +10,17 @@ import { ...@@ -10,12 +10,17 @@ import {
type RootState, type RootState,
} from "../../stores/store"; } from "../../stores/store";
import { getRouteHistory } from "../../stores/slices/dataSlice"; import { getRouteHistory } from "../../stores/slices/dataSlice";
import CMarker from "../../components/CMarker";
const Routes: React.FC = () => { const Routes: React.FC = () => {
const [fromDate, setFromDate] = useState(""); const [fromDate, setFromDate] = useState("");
const [fromTime, setFromTime] = useState(""); const [fromTime, setFromTime] = useState("");
const [toDate, setToDate] = useState(""); const [toDate, setToDate] = useState("");
const [toTime, setToTime] = useState(""); const [toTime, setToTime] = useState("");
const [mapCenter, setMapCenter] = useState({
lat: 37.33,
lng: -122,
});
const { selectedDevice } = useAppSelector((state: RootState) => state.device); const { selectedDevice } = useAppSelector((state: RootState) => state.device);
const { routeHistory, isRouteHistoryLoading } = useAppSelector( const { routeHistory, isRouteHistoryLoading } = useAppSelector(
...@@ -47,6 +52,18 @@ const Routes: React.FC = () => { ...@@ -47,6 +52,18 @@ const Routes: React.FC = () => {
} }
}, [dispatch, selectedDevice]); }, [dispatch, selectedDevice]);
useEffect(() => {
if (routeHistory.length > 0) {
const lat = Number(routeHistory[0]?.location.lat);
const lng = Number(routeHistory[0]?.location.lon);
if (!isNaN(lat) && !isNaN(lng)) {
setMapCenter({ lat, lng });
}
} else {
setMapCenter({ lat: 37.33, lng: -122 });
}
}, [routeHistory]);
const handleSearch = () => { const handleSearch = () => {
if (!selectedDevice) return; if (!selectedDevice) return;
...@@ -64,10 +81,6 @@ const Routes: React.FC = () => { ...@@ -64,10 +81,6 @@ const Routes: React.FC = () => {
); );
}; };
useEffect(() => {
console.log("routeHistory", routeHistory);
}, [routeHistory]);
return ( return (
<div className="routes wrapper"> <div className="routes wrapper">
<SectionHeader to="/home" /> <SectionHeader to="/home" />
...@@ -75,10 +88,17 @@ const Routes: React.FC = () => { ...@@ -75,10 +88,17 @@ const Routes: React.FC = () => {
<div className="routes__content"> <div className="routes__content">
<div style={{ height: "67vh", width: "100%" }}> <div style={{ height: "67vh", width: "100%" }}>
<GoogleMapReact <GoogleMapReact
defaultCenter={{ lat: 40.7128, lng: -74.006 }} center={mapCenter}
defaultZoom={12} defaultZoom={12}
options={{ disableDefaultUI: true }} options={{ disableDefaultUI: true }}
></GoogleMapReact> >
{routeHistory.length > 0 && (
<CMarker
lat={Number(routeHistory[0]?.location.lat)}
lng={Number(routeHistory[0]?.location.lon)}
/>
)}
</GoogleMapReact>
</div> </div>
<div className="routes__filter"> <div className="routes__filter">
......
...@@ -54,8 +54,6 @@ export const checkPassword = createAsyncThunk( ...@@ -54,8 +54,6 @@ export const checkPassword = createAsyncThunk(
password, password,
}); });
console.log("response", response);
if (response?.message === "valid") { if (response?.message === "valid") {
const deleteAccountResponse = await sendRpcRequest<{ const deleteAccountResponse = await sendRpcRequest<{
message: string; message: string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment