Skip to content

Commit

Permalink
Can view map with directions; need to implement routes for more locat…
Browse files Browse the repository at this point in the history
…ions and make it property manager specific
  • Loading branch information
devireddyprasanth22 committed Aug 8, 2024
1 parent fe1da69 commit 6dd24d5
Show file tree
Hide file tree
Showing 8 changed files with 1,472 additions and 25 deletions.
542 changes: 542 additions & 0 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mapbox/mapbox-gl-directions": "^4.3.1",
"@mui/icons-material": "^5.15.16",
"@mui/material": "^5.15.15",
"@mui/x-charts": "^7.3.2",
Expand Down
77 changes: 56 additions & 21 deletions frontend/src/components/inspection_run/InspectionRun.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import NavigationMenu from "../navigation_menu/NavigationMenus";
import React, { useEffect, useState } from "react";
import { Typography, Button, Grid, Box } from "@mui/material";
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Stack, Card, tableCellClasses } from "@mui/material"
import { Typography, Grid } from "@mui/material";
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, tableCellClasses } from "@mui/material";
import { supabase } from "../../supabase";
import { styled } from '@mui/material/styles';
import MyMap from "./MyMap";

const ACCESS_TOKEN = "pk.eyJ1IjoicGRldjAwMTAiLCJhIjoiY2x6ajVxNG1nMG4xOTJucTE1MHY4bDF2bCJ9.HfHy4wIk1KMg658ISOLoRQ"
import MapComponent from "./MapNav";

const ACCESS_TOKEN = "pk.eyJ1IjoicGRldjAwMTAiLCJhIjoiY2x6ajVxNG1nMG4xOTJucTE1MHY4bDF2bCJ9.HfHy4wIk1KMg658ISOLoRQ";

const InspectionRun = () => {
const [activeSection, setActiveSection] = useState("inspection");
const [inspectionsData, setInspectionsData] = useState([]);
const [mapData, setMapData] = useState({ origin: '', destination: '' });

useEffect(() => {
const fetchInspectionsData = async () => {
Expand Down Expand Up @@ -78,6 +78,7 @@ const InspectionRun = () => {

fetchInspectionsData();
}, []);

const StyledTableCell = styled(TableCell)(({ theme }) => ({
[`&.${tableCellClasses.head}`]: {
backgroundColor: "white",
Expand All @@ -86,9 +87,37 @@ const InspectionRun = () => {
fontSize: 12,
},
}));

const fullAddress = (number, name, type, suburb, state) => {
return `${number} ${name} ${type}, ${suburb}, ${state}`
}
return `${number} ${name} ${type}, ${suburb}, ${state}`;
};

const handleShowRoute = (propertyManagerId) => {
const filteredInspections = inspectionsData.filter(
inspection => inspection.propertyManagerData.property_manager_id === propertyManagerId
);

if (filteredInspections.length >= 2) {
const origin = fullAddress(
filteredInspections[0].propertyData.property_street_number,
filteredInspections[0].propertyData.property_street_name,
filteredInspections[0].propertyData.property_type,
filteredInspections[0].propertyData.property_suburb,
filteredInspections[0].propertyData.property_state
);

const destination = fullAddress(
filteredInspections[1].propertyData.property_street_number,
filteredInspections[1].propertyData.property_street_name,
filteredInspections[1].propertyData.property_type,
filteredInspections[1].propertyData.property_suburb,
filteredInspections[1].propertyData.property_state
);

setMapData({ origin, destination });
}
};

return (
<div>
<NavigationMenu>
Expand All @@ -97,21 +126,21 @@ const InspectionRun = () => {
spacing={2}
style={{ padding: "30px", paddingTop: "110px" }}
justifyContent="flex-start"
>
</Grid>
/>
<div style={{ padding: "20px" }}>
{activeSection === "inspection" && (
<Typography variant="h5">
Inspections Runs: ({inspectionsData.length})
</Typography>)}
<Table stickyHeader sx={{ minWidth: 650 }} aria-label="Table of properties" >
Inspections Runs
</Typography>
)}
<Table stickyHeader sx={{ minWidth: 650 }} aria-label="Table of properties">
<TableHead>
<TableRow>
<StyledTableCell><Typography fontSize={"12px"} fontWeight={700}>Property Manager</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"} >Property Address</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"} >Inspection Time and Date</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"}>Property Address</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"}>Inspection Time and Date</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"}>Duration</Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"}></Typography></StyledTableCell>
<StyledTableCell align="right"><Typography fontWeight={700} fontSize={"12px"}>Show Route</Typography></StyledTableCell>
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -122,14 +151,15 @@ const InspectionRun = () => {
>
<TableCell>
<Typography variant='body' fontWeight={700}>
{inspection.propertyManagerData.property_manager_first_name} {inspection.propertyManagerData.property_manager_last_name}
{inspection.propertyManagerData.property_manager_first_name} {inspection.propertyManagerData.property_manager_last_name}
</Typography>
</TableCell>
<TableCell align="right">
<Typography variant='body' fontWeight={700}>
{fullAddress(
inspection.propertyData.property_street_number,
inspection.propertyData.property_street_name,
inspection.propertyData.property_type,
inspection.propertyData.property_suburb,
inspection.propertyData.property_state
)}
Expand All @@ -141,21 +171,26 @@ const InspectionRun = () => {
</Typography>
</TableCell>
<TableCell align="right">
<Typography variant='body' fontWeight={700}>
{inspection.inspection_duration}
<Typography variant='body' fontWeight={700}>
{inspection.inspection_duration}
</Typography>
</TableCell>
<TableCell align="right">
<button onClick={() => handleShowRoute(inspection.propertyManagerData.property_manager_id)}>
Show Route
</button>
</TableCell>
</TableRow>
))} </TableBody>
))}
</TableBody>
</Table>
</div>
<div style={{ display: "flex", justifyContent: "center", height: "100vh" }}>
<MyMap></MyMap>
<MapComponent origin={mapData.origin} destination={mapData.destination} />
</div>
</NavigationMenu>
</div>
);
};

export default InspectionRun;

40 changes: 40 additions & 0 deletions frontend/src/components/inspection_run/MapNav.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect } from 'react';
import mapboxgl from 'mapbox-gl';
import MapboxDirections from '@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions';
import '@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions.css';
import 'mapbox-gl/dist/mapbox-gl.css';

const ACCESS_TOKEN = "pk.eyJ1IjoicGRldjAwMTAiLCJhIjoiY2x6ajVxNG1nMG4xOTJucTE1MHY4bDF2bCJ9.HfHy4wIk1KMg658ISOLoRQ"

const MapComponent = ({ origin, destination }) => {
useEffect(() => {
const map = new mapboxgl.Map({
accessToken: ACCESS_TOKEN,
container: 'map',
style: "mapbox://styles/mapbox/streets-v12",
center: [-79.4512, 43.6568],
zoom: 13,
});

const directions = new MapboxDirections({
accessToken: ACCESS_TOKEN
});

map.addControl(directions, 'top-left');

if (origin) {
directions.setOrigin(origin);
}

if (destination) {
directions.setDestination(destination);
}

// Cleanup on unmount
return () => map.remove();
}, [origin, destination]);

return <div id="map" style={{ width: 600, height: 400 }} />;
};

export default MapComponent;
4 changes: 2 additions & 2 deletions frontend/src/components/inspection_run/MyMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const MyMap = () => {
<Map
mapboxAccessToken= {ACCESS_TOKEN}
initialViewState={{
longitude: -122.4,
latitude: 37.8,
longitude: 145.1275,
latitude: -37.9145,
zoom: 14
}}
style={{width: 600, height: 400}}
Expand Down
Loading

0 comments on commit 6dd24d5

Please sign in to comment.