CEC-6016: remove singleton usage (#525)
* CEC-6016: add trim to fleet * update snapshot * CEC-6016: remove singleton in vehicle fetch
This commit is contained in:
@@ -214,7 +214,6 @@ const MainForm = ({ name }) => {
|
|||||||
selectCount={selected.length}
|
selectCount={selected.length}
|
||||||
rowCount={fleetVehicles.length}
|
rowCount={fleetVehicles.length}
|
||||||
/>
|
/>
|
||||||
<VehicleProvider>
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{fleetVehicles && fleetVehicles.map((car) => {
|
{fleetVehicles && fleetVehicles.map((car) => {
|
||||||
const isSelected = selected.includes(car.vin);
|
const isSelected = selected.includes(car.vin);
|
||||||
@@ -260,7 +259,6 @@ const MainForm = ({ name }) => {
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</VehicleProvider>
|
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TablePagination
|
<TablePagination
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { Link } from "react-router-dom";
|
|||||||
import Chip from '@mui/material/Chip';
|
import Chip from '@mui/material/Chip';
|
||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import ConnectedIcon from "../Controls/ConnectedIcon";
|
import ConnectedIcon from "../Controls/ConnectedIcon";
|
||||||
import { useVehicleContext } from "../Contexts/VehicleContext";
|
|
||||||
import useStyles from "../useStyles";
|
import useStyles from "../useStyles";
|
||||||
import { useIntersectObserver } from "../../hooks";
|
import { useIntersectObserver } from "../../hooks";
|
||||||
|
import api from "../../services/vehiclesAPI";
|
||||||
|
|
||||||
// Prevent fetching missing data by not including `token` prop
|
// Prevent fetching missing data by not including `token` prop
|
||||||
|
|
||||||
@@ -13,8 +13,7 @@ export function VehicleTeaserController(props) {
|
|||||||
const el = useRef(null);
|
const el = useRef(null);
|
||||||
const isVisible = useIntersectObserver(el, "0px", true);
|
const isVisible = useIntersectObserver(el, "0px", true);
|
||||||
const [isMissingData, setIsMissingData] = useState(false);
|
const [isMissingData, setIsMissingData] = useState(false);
|
||||||
|
const [vehicle, setVehicle] = useState({});
|
||||||
const { getVehicle, vehicle } = useVehicleContext();
|
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
@@ -26,7 +25,9 @@ export function VehicleTeaserController(props) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isVisible && props.token) {
|
if (isVisible && props.token) {
|
||||||
getVehicle(props.vin, props.token)
|
api.getVehicle(props.vin, props.token)
|
||||||
|
.then(setVehicle)
|
||||||
|
.catch(() => setVehicle({}));
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isMissingData, isVisible, props.vin, props.token]);
|
}, [isMissingData, isVisible, props.vin, props.token]);
|
||||||
|
|||||||
Reference in New Issue
Block a user